Search in sources :

Example 1 with TestOrgRole

use of com.ngtesting.platform.entity.TestOrgRole 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 TestOrgRole

use of com.ngtesting.platform.entity.TestOrgRole 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 TestOrgRole

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

the class OrgRoleServiceImpl method genVos.

@Override
public List<OrgRoleVo> genVos(List<TestOrgRole> pos) {
    List<OrgRoleVo> vos = new LinkedList<OrgRoleVo>();
    for (TestOrgRole po : pos) {
        OrgRoleVo vo = genVo(po);
        vos.add(vo);
    }
    return vos;
}
Also used : OrgRoleVo(com.ngtesting.platform.vo.OrgRoleVo) TestOrgRole(com.ngtesting.platform.entity.TestOrgRole) LinkedList(java.util.LinkedList)

Example 4 with TestOrgRole

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

the class OrgRoleServiceImpl method save.

@Override
public TestOrgRole save(OrgRoleVo vo, Long orgId) {
    if (vo == null) {
        return null;
    }
    TestOrgRole po = new TestOrgRole();
    if (vo.getId() != null) {
        po = (TestOrgRole) get(TestOrgRole.class, vo.getId());
    }
    po.setName(vo.getName());
    po.setDescr(vo.getDescr());
    po.setOrgId(orgId);
    po.setDisabled(vo.getDisabled());
    saveOrUpdate(po);
    return po;
}
Also used : TestOrgRole(com.ngtesting.platform.entity.TestOrgRole)

Example 5 with TestOrgRole

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

the class OrgRoleAction method save.

@AuthPassport(validate = true)
@RequestMapping(value = "save", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> save(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    Long orgId = userVo.getDefaultOrgId();
    OrgRoleVo orgRoleVo = JSON.parseObject(JSON.toJSONString(json.get("orgRole")), OrgRoleVo.class);
    TestOrgRole po = orgRoleService.save(orgRoleVo, orgId);
    List<OrgPrivilegeVo> orgPrivileges = (List<OrgPrivilegeVo>) json.get("orgPrivileges");
    boolean success = orgRolePrivilegeService.saveOrgRolePrivileges(po.getId(), orgPrivileges);
    List<UserVo> orgRoleUsers = (List<UserVo>) json.get("orgRoleUsers");
    success = orgRoleUserService.saveOrgRoleUsers(po.getId(), orgRoleUsers);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : HashMap(java.util.HashMap) TestOrgRole(com.ngtesting.platform.entity.TestOrgRole) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

TestOrgRole (com.ngtesting.platform.entity.TestOrgRole)8 JSONObject (com.alibaba.fastjson.JSONObject)2 TestOrgPrivilegeDefine (com.ngtesting.platform.entity.TestOrgPrivilegeDefine)2 AuthPassport (com.ngtesting.platform.util.AuthPassport)2 HashMap (java.util.HashMap)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 TestUser (com.ngtesting.platform.entity.TestUser)1 OrgPrivilegeVo (com.ngtesting.platform.vo.OrgPrivilegeVo)1 OrgRoleVo (com.ngtesting.platform.vo.OrgRoleVo)1 UserVo (com.ngtesting.platform.vo.UserVo)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1