Search in sources :

Example 1 with OrgPrivilegeVo

use of com.ngtesting.platform.vo.OrgPrivilegeVo 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 OrgPrivilegeVo

use of com.ngtesting.platform.vo.OrgPrivilegeVo 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)

Aggregations

TestOrgPrivilegeDefine (com.ngtesting.platform.entity.TestOrgPrivilegeDefine)2 OrgPrivilegeVo (com.ngtesting.platform.vo.OrgPrivilegeVo)2 TestOrgRole (com.ngtesting.platform.entity.TestOrgRole)1