Search in sources :

Example 6 with TestOrgRole

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

the class OrgRoleAction method get.

@AuthPassport(validate = true)
@RequestMapping(value = "get", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> get(HttpServletRequest request, @RequestBody JSONObject req) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    Long orgId = userVo.getDefaultOrgId();
    Long orgRoleId = req.getLong("id");
    List<OrgPrivilegeVo> orgRolePrivileges = orgRolePrivilegeService.listPrivilegesByOrgRole(orgId, orgRoleId);
    List<UserVo> orgRoleUsers = orgRoleUserService.listUserByOrgRole(orgRoleId);
    if (orgRoleId == null) {
        ret.put("orgRole", new OrgRoleVo());
        ret.put("orgRolePrivileges", orgRolePrivileges);
        ret.put("orgRoleUsers", orgRoleUsers);
        ret.put("code", Constant.RespCode.SUCCESS.getCode());
        return ret;
    }
    TestOrgRole po = (TestOrgRole) orgRoleService.get(TestOrgRole.class, orgRoleId);
    OrgRoleVo vo = orgRoleService.genVo(po);
    ret.put("orgRole", vo);
    ret.put("orgRolePrivileges", orgRolePrivileges);
    ret.put("orgRoleUsers", 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) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with TestOrgRole

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

the class OrgRoleServiceImpl method delete.

@Override
public boolean delete(Long id) {
    TestOrgRole po = (TestOrgRole) get(TestOrgRole.class, id);
    po.setDeleted(true);
    saveOrUpdate(po);
    return true;
}
Also used : TestOrgRole(com.ngtesting.platform.entity.TestOrgRole)

Example 8 with TestOrgRole

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

the class OrgRoleUserServiceImpl method saveOrgRoleUsers.

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

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