Search in sources :

Example 1 with TestOrgPrivilegeDefine

use of com.ngtesting.platform.entity.TestOrgPrivilegeDefine in project ngtesting-platform by aaronchen2k.

the class OrgRolePrivilegeServiceImpl method saveOrgRolePrivileges.

@Override
public boolean saveOrgRolePrivileges(Long roleId, List<OrgPrivilegeVo> orgPrivileges) {
    if (orgPrivileges == null) {
        return false;
    }
    TestOrgRole orgRole = (TestOrgRole) get(TestOrgRole.class, roleId);
    Set<TestOrgPrivilegeDefine> privilegeSet = orgRole.getOrgPrivilegeSet();
    for (Object obj : orgPrivileges) {
        OrgPrivilegeVo vo = JSON.parseObject(JSON.toJSONString(obj), OrgPrivilegeVo.class);
        if (vo.getSelecting() != vo.getSelected()) {
            // 变化了
            TestOrgPrivilegeDefine orgPrivilege = (TestOrgPrivilegeDefine) get(TestOrgPrivilegeDefine.class, vo.getId());
            if (vo.getSelecting() && !privilegeSet.contains(orgPrivilege)) {
                // 勾选
                privilegeSet.add(orgPrivilege);
            } else if (orgPrivilege != null) {
                // 取消
                privilegeSet.remove(orgPrivilege);
            }
        }
    }
    saveOrUpdate(orgRole);
    return true;
}
Also used : OrgPrivilegeVo(com.ngtesting.platform.vo.OrgPrivilegeVo) TestOrgRole(com.ngtesting.platform.entity.TestOrgRole) TestOrgPrivilegeDefine(com.ngtesting.platform.entity.TestOrgPrivilegeDefine)

Example 2 with TestOrgPrivilegeDefine

use of com.ngtesting.platform.entity.TestOrgPrivilegeDefine in project ngtesting-platform by aaronchen2k.

the class OrgRolePrivilegeServiceImpl method listByUser.

@Override
public Map<String, Boolean> listByUser(Long userId, Long orgId) {
    String hql = "select role from TestOrgRole role" + " join role.userSet users " + " where users.id = ?" + " and role.orgId = ?" + " and role.deleted != true and role.disabled!= true " + " order by role.id asc";
    List<TestOrgRole> ls = getDao().getListByHQL(hql, userId, orgId);
    Map<String, Boolean> map = new HashMap();
    for (TestOrgRole role : ls) {
        for (TestOrgPrivilegeDefine priv : role.getOrgPrivilegeSet()) {
            map.put(priv.getCode().toString(), true);
        }
    }
    return map;
}
Also used : TestOrgRole(com.ngtesting.platform.entity.TestOrgRole) TestOrgPrivilegeDefine(com.ngtesting.platform.entity.TestOrgPrivilegeDefine)

Example 3 with TestOrgPrivilegeDefine

use of com.ngtesting.platform.entity.TestOrgPrivilegeDefine in project ngtesting-platform by aaronchen2k.

the class OrgRolePrivilegeServiceImpl method listAllOrgPrivileges.

private List<TestOrgPrivilegeDefine> listAllOrgPrivileges() {
    DetachedCriteria dc = DetachedCriteria.forClass(TestOrgPrivilegeDefine.class);
    dc.add(Restrictions.eq("deleted", Boolean.FALSE));
    dc.add(Restrictions.eq("disabled", Boolean.FALSE));
    dc.addOrder(Order.asc("id"));
    List<TestOrgPrivilegeDefine> ls = findAllByCriteria(dc);
    return ls;
}
Also used : DetachedCriteria(org.hibernate.criterion.DetachedCriteria) TestOrgPrivilegeDefine(com.ngtesting.platform.entity.TestOrgPrivilegeDefine)

Example 4 with TestOrgPrivilegeDefine

use of com.ngtesting.platform.entity.TestOrgPrivilegeDefine in project ngtesting-platform by aaronchen2k.

the class OrgRolePrivilegeServiceImpl method listPrivilegesByOrgRole.

@Override
public List<OrgPrivilegeVo> listPrivilegesByOrgRole(Long orgId, Long orgRoleId) {
    List<TestOrgPrivilegeDefine> allPrivileges = listAllOrgPrivileges();
    List<TestOrgPrivilegeDefine> orgRolePrivileges;
    if (orgRoleId == null) {
        orgRolePrivileges = new LinkedList<>();
    } else {
        orgRolePrivileges = listOrgRolePrivileges(orgId, orgRoleId);
    }
    List<OrgPrivilegeVo> vos = new LinkedList<OrgPrivilegeVo>();
    for (TestOrgPrivilegeDefine po1 : allPrivileges) {
        OrgPrivilegeVo vo = genVo(orgId, po1);
        vo.setSelected(false);
        vo.setSelecting(false);
        for (TestOrgPrivilegeDefine po2 : orgRolePrivileges) {
            if (po1.getId().longValue() == po2.getId().longValue()) {
                vo.setSelected(true);
                vo.setSelecting(true);
            }
        }
        vos.add(vo);
    }
    return vos;
}
Also used : OrgPrivilegeVo(com.ngtesting.platform.vo.OrgPrivilegeVo) TestOrgPrivilegeDefine(com.ngtesting.platform.entity.TestOrgPrivilegeDefine)

Example 5 with TestOrgPrivilegeDefine

use of com.ngtesting.platform.entity.TestOrgPrivilegeDefine in project ngtesting-platform by aaronchen2k.

the class OrgRoleServiceImpl method getDefaultPrivByRoleCode.

// @Override
// public void initOrgRoleBasicDataPers(Long orgId) {
// for (TestOrgRole.OrgRoleCode e : TestOrgRole.OrgRoleCode.values()) {
// TestOrgRole po = new TestOrgRole();
// 
// po.setName(e.name);
// po.setCode(e);
// po.setDescr("");
// po.setOrgId(orgId);
// po.getOrgPrivilegeSet().addAll(getDefaultPrivByRoleCode(e));
// 
// saveOrUpdate(po);
// }
// }
@Override
public List<TestOrgPrivilegeDefine> getDefaultPrivByRoleCode(TestOrgRole.OrgRoleCode e) {
    TestOrgPrivilegeDefine.OrgPrivilegeCode code = TestOrgPrivilegeDefine.OrgPrivilegeCode.valueOf(e.code);
    DetachedCriteria dc = DetachedCriteria.forClass(TestOrgPrivilegeDefine.class);
    dc.add(Restrictions.eq("code", code));
    dc.add(Restrictions.ne("deleted", true));
    dc.add(Restrictions.ne("disabled", true));
    dc.addOrder(Order.asc("id"));
    List<TestOrgPrivilegeDefine> ls = findAllByCriteria(dc);
    return ls;
}
Also used : DetachedCriteria(org.hibernate.criterion.DetachedCriteria) TestOrgPrivilegeDefine(com.ngtesting.platform.entity.TestOrgPrivilegeDefine)

Aggregations

TestOrgPrivilegeDefine (com.ngtesting.platform.entity.TestOrgPrivilegeDefine)5 TestOrgRole (com.ngtesting.platform.entity.TestOrgRole)2 OrgPrivilegeVo (com.ngtesting.platform.vo.OrgPrivilegeVo)2 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)2