|
@@ -7,9 +7,9 @@ import java.util.Optional;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.*;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
@@ -25,16 +25,12 @@ import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.api.commons.enums.PrivilegeGroupType;
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.api.commons.security.enums.RoleMeta;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.util.RegExpUtil;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.RoleBean;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.controller.bean.PrivilegeDomain;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.controller.bean.PrivilegeGroupDomain;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.controller.bean.RoleDomain;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.controller.bean.UpdateRolePrivilegeRelationsDomain;
|
|
|
-import cn.com.qmth.examcloud.core.basic.api.controller.bean.UpdateRootOrgPrivilegeRelationsDomain;
|
|
|
import cn.com.qmth.examcloud.core.basic.base.constants.BasicConsts;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.PrivilegeGroupRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.PrivilegeRepo;
|
|
@@ -52,6 +48,7 @@ import cn.com.qmth.examcloud.core.basic.service.bean.RoleInfo;
|
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
import cn.com.qmth.examcloud.web.helpers.tree.EleTreeNode;
|
|
|
import cn.com.qmth.examcloud.web.helpers.tree.TreeUtil;
|
|
|
+import cn.com.qmth.examcloud.web.interceptor.GlobalSequenceLock;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -68,476 +65,740 @@ import io.swagger.annotations.ApiOperation;
|
|
|
@RequestMapping("${$rmp.ctr.basic}/rolePrivilege")
|
|
|
public class RolePrivilegeController extends ControllerSupport {
|
|
|
|
|
|
- private static List<String> disabledPrivilegeCodeList = Arrays
|
|
|
- .asList(new String[]{"index_privilege_group_list", "index_app_list", "index_school",
|
|
|
- "school_config", "index_school_privilege_settings", "system"});
|
|
|
+ private static List<String> disabledPrivilegeCodeList = Arrays
|
|
|
+ .asList(new String[]{"index_privilege_group_list", "index_app_list", "index_school",
|
|
|
+ "school_config", "index_school_privilege_settings", "system"});
|
|
|
|
|
|
- @Autowired
|
|
|
- PrivilegeGroupRepo privilegeGroupRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PrivilegeRepo privilegeRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- RoleRepo roleRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- RolePrivilegeRelationRepo rolePrivilegeRelationRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- RootOrgPrivilegeRelationRepo rootOrgPrivilegeRelationRepo;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- RolePrivilegeService rolePrivilegeService;
|
|
|
-
|
|
|
- @ApiOperation(value = "查询角色", notes = "")
|
|
|
- @PostMapping("getRoles")
|
|
|
- public List<RoleBean> getRoles(@RequestParam Boolean includeSuperAdmin,
|
|
|
- @RequestParam(required = false) Long rootOrgId) {
|
|
|
- User accessUser = getAccessUser();
|
|
|
-
|
|
|
- List<RoleEntity> roleList = roleRepo.findByRootOrgIdIsNull();
|
|
|
-
|
|
|
- if (null != rootOrgId) {
|
|
|
- validateRootOrgIsolation(rootOrgId);
|
|
|
- List<RoleEntity> rootOrgRoleList = roleRepo.findByRootOrgId(rootOrgId);
|
|
|
- roleList.addAll(rootOrgRoleList);
|
|
|
- } else {
|
|
|
- List<RoleEntity> rootOrgRoleList = roleRepo.findByRootOrgId(accessUser.getRootOrgId());
|
|
|
- roleList.addAll(rootOrgRoleList);
|
|
|
- }
|
|
|
- List<RoleBean> roleBeanList = Lists.newArrayList();
|
|
|
-
|
|
|
- for (RoleEntity cur : roleList) {
|
|
|
-
|
|
|
- if ((!includeSuperAdmin) && cur.getCode().equals(RoleMeta.SUPER_ADMIN.name())) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- RoleBean bean = new RoleBean();
|
|
|
- bean.setRoleId(cur.getId());
|
|
|
- bean.setRoleName(cur.getName());
|
|
|
- bean.setRoleCode(cur.getCode());
|
|
|
- bean.setRootOrgId(cur.getRootOrgId());
|
|
|
-
|
|
|
- roleBeanList.add(bean);
|
|
|
- }
|
|
|
-
|
|
|
- return roleBeanList;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询用户的权限树", notes = "")
|
|
|
- @PostMapping("getUserPrivileges")
|
|
|
- public List<PrivilegeDomain> getPrivileges(@RequestParam String groupCode,
|
|
|
- @RequestParam boolean full) {
|
|
|
-
|
|
|
- User accessUser = getAccessUser();
|
|
|
- Long rootOrgId = accessUser.getRootOrgId();
|
|
|
-
|
|
|
- PrivilegeGroupEntity privilegeGroup = privilegeGroupRepo.findByCode(groupCode);
|
|
|
-
|
|
|
- if (null == privilegeGroup) {
|
|
|
- throw new StatusException("002001", "groupCode is not existing");
|
|
|
- }
|
|
|
-
|
|
|
- List<Long> roleIdList = getAccessUserRoleIdList();
|
|
|
-
|
|
|
- List<RolePrivilegeRelationEntity> rolePrivRelationList = rolePrivilegeRelationRepo
|
|
|
- .findAllByRoleIdInAndRootOrgId(roleIdList, rootOrgId);
|
|
|
-
|
|
|
- Set<String> pIdSet = Sets.newHashSet();
|
|
|
- for (RolePrivilegeRelationEntity cur : rolePrivRelationList) {
|
|
|
- pIdSet.add(String.valueOf(cur.getPrivilegeId()));
|
|
|
- }
|
|
|
-
|
|
|
- List<PrivilegeEntity> privilegeList = privilegeRepo
|
|
|
- .findAllByGroupIdOrderByWeightDesc(privilegeGroup.getId());
|
|
|
-
|
|
|
- List<PrivilegeDomain> privilegeInfoList = Lists.newArrayList();
|
|
|
-
|
|
|
- for (PrivilegeEntity cur : privilegeList) {
|
|
|
- boolean hasPrivilege = pIdSet.contains(String.valueOf(cur.getId()));
|
|
|
- // 超级管理员拥有所有权限
|
|
|
- if (isSuperAdmin()) {
|
|
|
- hasPrivilege = true;
|
|
|
- } else if (disabledPrivilegeCodeList.contains(cur.getCode())) {
|
|
|
- hasPrivilege = false;
|
|
|
- }
|
|
|
- if ((!full) && (!hasPrivilege)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- PrivilegeDomain privilegeInfo = new PrivilegeDomain();
|
|
|
- privilegeInfo.setHasPrivilege(hasPrivilege);
|
|
|
- privilegeInfo.setCode(cur.getCode());
|
|
|
- privilegeInfo.setCreationTime(cur.getCreationTime());
|
|
|
- privilegeInfo.setGroupId(cur.getGroupId());
|
|
|
- privilegeInfo.setGroupCode(privilegeGroup.getCode());
|
|
|
- privilegeInfo.setId(cur.getId());
|
|
|
- privilegeInfo.setName(cur.getName());
|
|
|
- privilegeInfo.setParentId(cur.getParentId());
|
|
|
- privilegeInfo.setUpdateTime(cur.getUpdateTime());
|
|
|
- privilegeInfo.setDescription(cur.getDescription());
|
|
|
- privilegeInfo.setWeight(cur.getWeight());
|
|
|
- privilegeInfo.setExt1(cur.getExt1());
|
|
|
- privilegeInfo.setExt2(cur.getExt2());
|
|
|
- privilegeInfo.setExt3(cur.getExt3());
|
|
|
- privilegeInfo.setExt4(cur.getExt4());
|
|
|
- privilegeInfo.setExt5(cur.getExt5());
|
|
|
-
|
|
|
- privilegeInfoList.add(privilegeInfo);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- return privilegeInfoList;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询权限组")
|
|
|
- @GetMapping("getPrivilegeGroupList")
|
|
|
- public List<PrivilegeGroupDomain> getPrivilegeGroupList() {
|
|
|
- Sort sort = new Sort(Sort.Direction.ASC, "id");
|
|
|
- List<PrivilegeGroupEntity> list = privilegeGroupRepo.findAll(sort);
|
|
|
-
|
|
|
- List<PrivilegeGroupDomain> ret = Lists.newArrayList();
|
|
|
-
|
|
|
- for (PrivilegeGroupEntity cur : list) {
|
|
|
- PrivilegeGroupDomain bean = new PrivilegeGroupDomain();
|
|
|
- bean.setId(cur.getId());
|
|
|
- bean.setCode(cur.getCode());
|
|
|
- bean.setName(cur.getName());
|
|
|
- bean.setExt1(cur.getExt1());
|
|
|
- bean.setExt2(cur.getExt2());
|
|
|
- bean.setExt3(cur.getExt3());
|
|
|
- bean.setExt4(cur.getExt4());
|
|
|
- bean.setExt5(cur.getExt5());
|
|
|
-
|
|
|
- ret.add(bean);
|
|
|
- }
|
|
|
-
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询权限树")
|
|
|
- @GetMapping("getPrivilegeTree/{groupId}")
|
|
|
- public EleTreeNode getPrivilegeTree(@PathVariable Long groupId,
|
|
|
- @RequestParam(required = false) Boolean includeDisabledCodes) {
|
|
|
- PrivilegeGroupEntity group = GlobalHelper.getEntity(privilegeGroupRepo, groupId,
|
|
|
- PrivilegeGroupEntity.class);
|
|
|
- List<PrivilegeEntity> privilegeList = privilegeRepo
|
|
|
- .findAllByGroupIdOrderByWeightDesc(groupId);
|
|
|
- EleTreeNode rootNode = new EleTreeNode(BasicConsts.ROOT_PRIVILEGE_ID, group.getName());
|
|
|
-
|
|
|
- if (null != includeDisabledCodes && includeDisabledCodes) {
|
|
|
- if (!isSuperAdmin()) {
|
|
|
- throw new StatusException("012001", "非法请求");
|
|
|
- }
|
|
|
- TreeUtil.convert2OneEleTreeNode(rootNode, privilegeList, Lists.newArrayList());
|
|
|
- } else {
|
|
|
- TreeUtil.convert2OneEleTreeNode(rootNode, privilegeList, disabledPrivilegeCodeList);
|
|
|
- }
|
|
|
-
|
|
|
- return rootNode;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询顶级机构的权限ID集合")
|
|
|
- @GetMapping("getRootOrgPrivilegeIdList/{rootOrgId}/{privilegeGroupId}")
|
|
|
- public List<Long> getRootOrgPrivilegeIdList(@PathVariable Long rootOrgId,
|
|
|
- @PathVariable Long privilegeGroupId) {
|
|
|
-
|
|
|
- List<RootOrgPrivilegeRelationEntity> list = rootOrgPrivilegeRelationRepo
|
|
|
- .findAllByRootOrgIdAndGroupId(rootOrgId, privilegeGroupId);
|
|
|
-
|
|
|
- List<Long> pList = list.stream().map(RootOrgPrivilegeRelationEntity::getPrivilegeId)
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- return pList;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询角色的权限ID集合")
|
|
|
- @GetMapping("getPrivilegeIdList/{rootOrgId}/{roleId}")
|
|
|
- public Set<Long> getPrivilegeIdList(@PathVariable Long rootOrgId, @PathVariable Long roleId) {
|
|
|
- List<RolePrivilegeRelationEntity> rolePrivRelationList = rolePrivilegeRelationRepo
|
|
|
- .findAllByRoleIdAndRootOrgId(roleId, rootOrgId);
|
|
|
-
|
|
|
- Set<Long> pIdSet = Sets.newHashSet();
|
|
|
- for (RolePrivilegeRelationEntity cur : rolePrivRelationList) {
|
|
|
- pIdSet.add(cur.getPrivilegeId());
|
|
|
- }
|
|
|
-
|
|
|
- return pIdSet;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询角色的权限ID集合(限制权限组)")
|
|
|
- @GetMapping("getPrivilegeIdList/{rootOrgId}/{roleId}/{privilegeGroupId}")
|
|
|
- public Set<Long> getPrivilegeIdList(@PathVariable Long rootOrgId, @PathVariable Long roleId,
|
|
|
- @PathVariable Long privilegeGroupId) {
|
|
|
- List<RolePrivilegeRelationEntity> rolePrivRelationList = rolePrivilegeRelationRepo
|
|
|
- .findAllByRoleIdAndRootOrgId(roleId, rootOrgId);
|
|
|
-
|
|
|
- Set<Long> pIdSet = Sets.newHashSet();
|
|
|
- for (RolePrivilegeRelationEntity cur : rolePrivRelationList) {
|
|
|
- PrivilegeEntity privilegeEntity = GlobalHelper.getPresentEntity(privilegeRepo,
|
|
|
- cur.getPrivilegeId(), PrivilegeEntity.class);
|
|
|
- if (privilegeEntity.getGroupId().equals(privilegeGroupId)) {
|
|
|
- pIdSet.add(cur.getPrivilegeId());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return pIdSet;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "更新角色权限关联")
|
|
|
- @PostMapping("updateRolePrivilegeRelations")
|
|
|
- @Transactional
|
|
|
- public void updateRolePrivilegeRelations(@RequestBody UpdateRolePrivilegeRelationsDomain req) {
|
|
|
- Long rootOrgId = Long.parseLong(req.getRootOrgId());
|
|
|
- Long roleId = Long.parseLong(req.getRoleId());
|
|
|
- Long privilegeGroupId = Long.parseLong(req.getPrivilegeGroupId());
|
|
|
- Set<Long> privilegeIdSet = req.getPrivilegeIdSet();
|
|
|
-
|
|
|
- User accessUser = getAccessUser();
|
|
|
- Long userRootOrgId = accessUser.getRootOrgId();
|
|
|
- if ((!rootOrgId.equals(userRootOrgId)) && (!isSuperAdmin())) {
|
|
|
- throw new StatusException("012001", "非法请求");
|
|
|
- }
|
|
|
-
|
|
|
- rolePrivilegeService.updateRolePrivilegeRelations(rootOrgId, roleId, privilegeGroupId,
|
|
|
- privilegeIdSet);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "更新顶级机构权限关联")
|
|
|
- @PostMapping("updateRootOrgPrivilegeRelations")
|
|
|
- @Transactional
|
|
|
- public void updateRootOrgPrivilegeRelations(
|
|
|
- @RequestBody UpdateRootOrgPrivilegeRelationsDomain req) {
|
|
|
- Long rootOrgId = Long.parseLong(req.getRootOrgId());
|
|
|
- Long privilegeGroupId = req.getPrivilegeGroupId();
|
|
|
- Set<Long> privilegeIdSet = req.getPrivilegeIdSet();
|
|
|
-
|
|
|
- if (!isSuperAdmin()) {
|
|
|
- throw new StatusException("012601", "非法请求");
|
|
|
- }
|
|
|
-
|
|
|
- rolePrivilegeService.updateRootOrgPrivilegeRelations(rootOrgId, privilegeGroupId,
|
|
|
- privilegeIdSet);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "增加权限")
|
|
|
- @PostMapping("addPrivilege")
|
|
|
- @Transactional
|
|
|
- public PrivilegeEntity addPrivilege(@RequestBody PrivilegeEntity privilege) {
|
|
|
-
|
|
|
- privilege.setName(privilege.getName().trim());
|
|
|
- privilege.setCode(privilege.getCode().trim());
|
|
|
- privilege.setDescription(privilege.getDescription());
|
|
|
-
|
|
|
- if (!privilege.getCode().matches("[0-9a-zA-Z_]+")) {
|
|
|
- throw new StatusException("020101", "权限编码必须由字母,数字和下划线组成");
|
|
|
- }
|
|
|
-
|
|
|
- PrivilegeGroupEntity group = GlobalHelper.getEntity(privilegeGroupRepo,
|
|
|
- privilege.getGroupId(), PrivilegeGroupEntity.class);
|
|
|
- if (null == group) {
|
|
|
- throw new StatusException("020001", "权限组不存在");
|
|
|
- }
|
|
|
-
|
|
|
- if (null == privilege.getParentId()
|
|
|
- || BasicConsts.ROOT_PRIVILEGE_ID == privilege.getParentId()) {
|
|
|
- privilege.setParentId(null);
|
|
|
- } else {
|
|
|
- PrivilegeEntity parentPrivilege = GlobalHelper.getEntity(privilegeRepo,
|
|
|
- privilege.getParentId(), PrivilegeEntity.class);
|
|
|
- if (null == parentPrivilege) {
|
|
|
- throw new StatusException("020002", "父权限不存在");
|
|
|
- }
|
|
|
- if (!parentPrivilege.getGroupId().equals(privilege.getGroupId())) {
|
|
|
- throw new StatusException("020003", "权限组错误");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- PrivilegeEntity ret = privilegeRepo.save(privilege);
|
|
|
-
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "更新权限")
|
|
|
- @PutMapping("updatePrivilege")
|
|
|
- @Transactional
|
|
|
- public PrivilegeEntity updatePrivilege(@RequestBody PrivilegeEntity privilege) {
|
|
|
-
|
|
|
- privilege.setName(privilege.getName().trim());
|
|
|
- privilege.setCode(privilege.getCode().trim());
|
|
|
- privilege.setDescription(privilege.getDescription());
|
|
|
- PrivilegeGroupEntity group = GlobalHelper.getEntity(privilegeGroupRepo,
|
|
|
- privilege.getGroupId(), PrivilegeGroupEntity.class);
|
|
|
- if (null == group) {
|
|
|
- throw new StatusException("020001", "权限组不存在");
|
|
|
- }
|
|
|
-
|
|
|
- if (null != privilege.getParentId()) {
|
|
|
- PrivilegeEntity parentPrivilege = GlobalHelper.getEntity(privilegeRepo,
|
|
|
- privilege.getParentId(), PrivilegeEntity.class);
|
|
|
- if (null == parentPrivilege) {
|
|
|
- throw new StatusException("020002", "父权限不存在");
|
|
|
- }
|
|
|
- if (!parentPrivilege.getGroupId().equals(privilege.getGroupId())) {
|
|
|
- throw new StatusException("020003", "权限组错误");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- PrivilegeEntity ret = privilegeRepo.save(privilege);
|
|
|
-
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "删除权限")
|
|
|
- @DeleteMapping("deletePrivilege/{id}")
|
|
|
- @Transactional
|
|
|
- public void deletePrivilege(@PathVariable Long id) {
|
|
|
- PrivilegeEntity privilege = GlobalHelper.getEntity(privilegeRepo, id,
|
|
|
- PrivilegeEntity.class);
|
|
|
- if (null == privilege) {
|
|
|
- throw new StatusException("020004", "权限不存在");
|
|
|
- }
|
|
|
-
|
|
|
- List<PrivilegeEntity> children = privilegeRepo.findAllByParentId(privilege.getId());
|
|
|
- if (CollectionUtils.isNotEmpty(children)) {
|
|
|
- throw new StatusException("020005", "存在子权限");
|
|
|
- }
|
|
|
-
|
|
|
- privilegeRepo.deleteById(id);
|
|
|
- rolePrivilegeRelationRepo.deleteByPrivilegeId(id);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "查询权限")
|
|
|
- @GetMapping("getPrivilege/{id}")
|
|
|
- public PrivilegeEntity getPrivilege(@PathVariable Long id) {
|
|
|
- PrivilegeEntity privilege = GlobalHelper.getEntity(privilegeRepo, id,
|
|
|
- PrivilegeEntity.class);
|
|
|
- if (null == privilege) {
|
|
|
- throw new StatusException("020004", "权限不存在");
|
|
|
- }
|
|
|
- return privilege;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "校验权限(角色判断)")
|
|
|
- @PostMapping("checkPrivileges")
|
|
|
- public Map<String, Boolean> checkPrivileges(@RequestParam String privilegeCodes) {
|
|
|
-
|
|
|
- List<String> privilegeCodeList = RegExpUtil.findAll(privilegeCodes, "[0-9A-Za-z_]+");
|
|
|
-
|
|
|
- User accessUser = getAccessUser();
|
|
|
-
|
|
|
- List<Long> roleIdList = getAccessUserRoleIdList();
|
|
|
-
|
|
|
- List<PrivilegeEntity> privilegeEntityList = privilegeRepo
|
|
|
- .findAllByCodeIn(privilegeCodeList);
|
|
|
-
|
|
|
- Map<String, Boolean> ret = Maps.newHashMap();
|
|
|
-
|
|
|
- boolean isSuperAdmin = isSuperAdmin();
|
|
|
-
|
|
|
- for (PrivilegeEntity cur : privilegeEntityList) {
|
|
|
- if (isSuperAdmin) {
|
|
|
- ret.put(cur.getCode(), true);
|
|
|
- } else {
|
|
|
- List<RolePrivilegeRelationEntity> relationEntityList = rolePrivilegeRelationRepo
|
|
|
- .findAllByRoleIdInAndRootOrgIdAndPrivilegeId(roleIdList,
|
|
|
- accessUser.getRootOrgId(), cur.getId());
|
|
|
- ret.put(cur.getCode(), CollectionUtils.isNotEmpty(relationEntityList));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "校验权限(机构判断)")
|
|
|
- @PostMapping("checkRootOrgPrivileges")
|
|
|
- public Map<String, Boolean> checkRootOrgPrivileges(@RequestParam String privilegeCodes) {
|
|
|
-
|
|
|
- List<String> privilegeCodeList = RegExpUtil.findAll(privilegeCodes, "[0-9A-Za-z_]+");
|
|
|
-
|
|
|
- User accessUser = getAccessUser();
|
|
|
-
|
|
|
- List<PrivilegeEntity> privilegeEntityList = privilegeRepo
|
|
|
- .findAllByCodeIn(privilegeCodeList);
|
|
|
-
|
|
|
- Map<String, Boolean> ret = Maps.newHashMap();
|
|
|
-
|
|
|
- for (PrivilegeEntity cur : privilegeEntityList) {
|
|
|
-
|
|
|
- Optional<RootOrgPrivilegeRelationEntity> optional = rootOrgPrivilegeRelationRepo
|
|
|
- .findById(
|
|
|
- new RootOrgPrivilegeRelationPK(cur.getId(), accessUser.getRootOrgId()));
|
|
|
- ret.put(cur.getCode(), optional.isPresent());
|
|
|
- }
|
|
|
-
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "添加角色")
|
|
|
- @PostMapping("addRole")
|
|
|
- @Transactional
|
|
|
- public RoleEntity addRole(@RequestBody RoleDomain req) {
|
|
|
- Long rootOrgId = req.getRootOrgId();
|
|
|
- String code = req.getCode();
|
|
|
- String name = req.getName();
|
|
|
+ @Autowired
|
|
|
+ PrivilegeGroupRepo privilegeGroupRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PrivilegeRepo privilegeRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RoleRepo roleRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RolePrivilegeRelationRepo rolePrivilegeRelationRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RootOrgPrivilegeRelationRepo rootOrgPrivilegeRelationRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RolePrivilegeService rolePrivilegeService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询角色", notes = "")
|
|
|
+ @PostMapping("getRoles")
|
|
|
+ public List<RoleBean> getRoles(@RequestParam Boolean includeSuperAdmin,
|
|
|
+ @RequestParam(required = false) Long rootOrgId) {
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+
|
|
|
+ List<RoleEntity> roleList = roleRepo.findByRootOrgIdIsNull();
|
|
|
|
|
|
- validateRootOrgIsolation(rootOrgId);
|
|
|
+ if (null != rootOrgId) {
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
+ List<RoleEntity> rootOrgRoleList = roleRepo.findByRootOrgId(rootOrgId);
|
|
|
+ roleList.addAll(rootOrgRoleList);
|
|
|
+ } else {
|
|
|
+ List<RoleEntity> rootOrgRoleList = roleRepo.findByRootOrgId(accessUser.getRootOrgId());
|
|
|
+ roleList.addAll(rootOrgRoleList);
|
|
|
+ }
|
|
|
+ List<RoleBean> roleBeanList = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (RoleEntity cur : roleList) {
|
|
|
+
|
|
|
+ if ((!includeSuperAdmin) && cur.getCode().equals(RoleMeta.SUPER_ADMIN.name())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ RoleBean bean = new RoleBean();
|
|
|
+ bean.setRoleId(cur.getId());
|
|
|
+ bean.setRoleName(cur.getName());
|
|
|
+ bean.setRoleCode(cur.getCode());
|
|
|
+ bean.setRootOrgId(cur.getRootOrgId());
|
|
|
+
|
|
|
+ roleBeanList.add(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ return roleBeanList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询用户的权限树", notes = "")
|
|
|
+ @PostMapping("getUserPrivileges")
|
|
|
+ public List<PrivilegeDomain> getPrivileges(@RequestParam String groupCode,
|
|
|
+ @RequestParam boolean full) {
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
+
|
|
|
+ PrivilegeGroupEntity privilegeGroup = privilegeGroupRepo.findByCode(groupCode);
|
|
|
+
|
|
|
+ if (null == privilegeGroup) {
|
|
|
+ throw new StatusException("002001", "groupCode is not existing");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> roleIdList = getAccessUserRoleIdList();
|
|
|
+
|
|
|
+ List<RolePrivilegeRelationEntity> rolePrivRelationList = rolePrivilegeRelationRepo
|
|
|
+ .findAllByRoleIdInAndRootOrgId(roleIdList, rootOrgId);
|
|
|
+
|
|
|
+ Set<String> pIdSet = Sets.newHashSet();
|
|
|
+ for (RolePrivilegeRelationEntity cur : rolePrivRelationList) {
|
|
|
+ pIdSet.add(String.valueOf(cur.getPrivilegeId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PrivilegeEntity> privilegeList = privilegeRepo
|
|
|
+ .findAllByGroupIdOrderByWeightDesc(privilegeGroup.getId());
|
|
|
+
|
|
|
+ List<PrivilegeDomain> privilegeInfoList = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (PrivilegeEntity cur : privilegeList) {
|
|
|
+ boolean hasPrivilege = pIdSet.contains(String.valueOf(cur.getId()));
|
|
|
+ // 超级管理员拥有所有权限
|
|
|
+ if (isSuperAdmin()) {
|
|
|
+ hasPrivilege = true;
|
|
|
+ } else if (disabledPrivilegeCodeList.contains(cur.getCode())) {
|
|
|
+ hasPrivilege = false;
|
|
|
+ }
|
|
|
+ if ((!full) && (!hasPrivilege)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ PrivilegeDomain privilegeInfo = new PrivilegeDomain();
|
|
|
+ privilegeInfo.setHasPrivilege(hasPrivilege);
|
|
|
+ privilegeInfo.setCode(cur.getCode());
|
|
|
+ privilegeInfo.setCreationTime(cur.getCreationTime());
|
|
|
+ privilegeInfo.setGroupId(cur.getGroupId());
|
|
|
+ privilegeInfo.setGroupCode(privilegeGroup.getCode());
|
|
|
+ privilegeInfo.setId(cur.getId());
|
|
|
+ privilegeInfo.setName(cur.getName());
|
|
|
+ privilegeInfo.setParentId(cur.getParentId());
|
|
|
+ privilegeInfo.setUpdateTime(cur.getUpdateTime());
|
|
|
+ privilegeInfo.setDescription(cur.getDescription());
|
|
|
+ privilegeInfo.setWeight(cur.getWeight());
|
|
|
+ privilegeInfo.setExt1(cur.getExt1());
|
|
|
+ privilegeInfo.setExt2(cur.getExt2());
|
|
|
+ privilegeInfo.setExt3(cur.getExt3());
|
|
|
+ privilegeInfo.setExt4(cur.getExt4());
|
|
|
+ privilegeInfo.setExt5(cur.getExt5());
|
|
|
+
|
|
|
+ privilegeInfoList.add(privilegeInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return privilegeInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询权限组")
|
|
|
+ @GetMapping("getPrivilegeGroupList")
|
|
|
+ public List<PrivilegeGroupDomain> getPrivilegeGroupList() {
|
|
|
+
|
|
|
+ List<PrivilegeGroupEntity> list = privilegeGroupRepo.findAllByRootOrgIdIsNullOrderById();
|
|
|
+
|
|
|
+ List<PrivilegeGroupDomain> ret = Lists.newArrayList();
|
|
|
+
|
|
|
+ if (null != list && !list.isEmpty()) {
|
|
|
+ list = list.stream().filter(p -> PrivilegeGroupType.STUDENT_CLIENT_MENU != p.getType())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ for (PrivilegeGroupEntity cur : list) {
|
|
|
+ PrivilegeGroupDomain bean = new PrivilegeGroupDomain();
|
|
|
+ bean.setId(cur.getId());
|
|
|
+ bean.setCode(cur.getCode());
|
|
|
+ bean.setName(cur.getName());
|
|
|
+ bean.setExt1(cur.getExt1());
|
|
|
+ bean.setExt2(cur.getExt2());
|
|
|
+ bean.setExt3(cur.getExt3());
|
|
|
+ bean.setExt4(cur.getExt4());
|
|
|
+ bean.setExt5(cur.getExt5());
|
|
|
+
|
|
|
+ ret.add(bean);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询权限树")
|
|
|
+ @GetMapping("getPrivilegeTree/{groupId}")
|
|
|
+ public EleTreeNode getPrivilegeTree(@PathVariable Long groupId,
|
|
|
+ @RequestParam(required = false) Boolean includeDisabledCodes) {
|
|
|
+ PrivilegeGroupEntity group = GlobalHelper.getEntity(privilegeGroupRepo, groupId,
|
|
|
+ PrivilegeGroupEntity.class);
|
|
|
+ List<PrivilegeEntity> privilegeList = privilegeRepo
|
|
|
+ .findAllByGroupIdOrderByWeightDesc(groupId);
|
|
|
+ EleTreeNode rootNode = new EleTreeNode(BasicConsts.ROOT_PRIVILEGE_ID, group.getName());
|
|
|
+
|
|
|
+ if (null != includeDisabledCodes && includeDisabledCodes) {
|
|
|
+ if (!isSuperAdmin()) {
|
|
|
+ throw new StatusException("012001", "非法请求");
|
|
|
+ }
|
|
|
+ TreeUtil.convert2OneEleTreeNode(rootNode, privilegeList, Lists.newArrayList());
|
|
|
+ } else {
|
|
|
+ TreeUtil.convert2OneEleTreeNode(rootNode, privilegeList, disabledPrivilegeCodeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return rootNode;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询顶级机构的权限ID集合")
|
|
|
+ @GetMapping("getRootOrgPrivilegeIdList/{rootOrgId}/{privilegeGroupId}")
|
|
|
+ public List<Long> getRootOrgPrivilegeIdList(@PathVariable Long rootOrgId,
|
|
|
+ @PathVariable Long privilegeGroupId) {
|
|
|
+
|
|
|
+ List<RootOrgPrivilegeRelationEntity> list = rootOrgPrivilegeRelationRepo
|
|
|
+ .findAllByRootOrgIdAndGroupId(rootOrgId, privilegeGroupId);
|
|
|
+
|
|
|
+ List<Long> pList = list.stream().map(RootOrgPrivilegeRelationEntity::getPrivilegeId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return pList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2020年2月19日
|
|
|
+ *
|
|
|
+ * @param rootOrgId
|
|
|
+ * @param includeDisabledCodes
|
|
|
+ * @return
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询菜单树")
|
|
|
+ @GetMapping("getStudentClientMenuTree/{rootOrgId}")
|
|
|
+ @GlobalSequenceLock
|
|
|
+ @Transactional
|
|
|
+ public OrgPrivilegeTreeDomain getStudentClientMenuTree(@PathVariable Long rootOrgId,
|
|
|
+ @RequestParam(required = false) Boolean includeDisabledCodes) {
|
|
|
+
|
|
|
+ PrivilegeGroupEntity group = privilegeGroupRepo.findByRootOrgIdAndType(rootOrgId,
|
|
|
+ PrivilegeGroupType.STUDENT_CLIENT_MENU);
|
|
|
+
|
|
|
+ //如果考生自定义菜单未初始化,默认初始化一份
|
|
|
+ if (null == group) {
|
|
|
+ PrivilegeGroupEntity globalGroup = privilegeGroupRepo
|
|
|
+ .findByCode(PrivilegeGroupType.STUDENT_CLIENT_MENU.name());
|
|
|
+
|
|
|
+ group = new PrivilegeGroupEntity();
|
|
|
+ group.setCode(PrivilegeGroupType.STUDENT_CLIENT_MENU.name() + "_" + rootOrgId);
|
|
|
+ group.setName(globalGroup.getName());
|
|
|
+ group.setRootOrgId(rootOrgId);
|
|
|
+ group.setType(PrivilegeGroupType.STUDENT_CLIENT_MENU);
|
|
|
+
|
|
|
+ group.setExt1(globalGroup.getExt1());
|
|
|
+ group.setExt2(globalGroup.getExt2());
|
|
|
+ group.setExt3(globalGroup.getExt3());
|
|
|
+ group.setExt4(globalGroup.getExt4());
|
|
|
+ group.setExt5(globalGroup.getExt5());
|
|
|
+
|
|
|
+ group = privilegeGroupRepo.save(group);
|
|
|
+
|
|
|
+ List<PrivilegeEntity> globalPrivilegeList = privilegeRepo
|
|
|
+ .findAllByGroupIdOrderByWeightDesc(globalGroup.getId());
|
|
|
+ Map<Long, Integer> idIndex = Maps.newHashMap();
|
|
|
+ List<PrivilegeEntity> privilegeList = Lists.newArrayList();
|
|
|
+ Set<Long> privilegeIdSet = Sets.newHashSet();
|
|
|
+ int c = 0;
|
|
|
+ for (PrivilegeEntity cur : globalPrivilegeList) {
|
|
|
+ idIndex.put(cur.getId(), c);
|
|
|
+ c++;
|
|
|
+
|
|
|
+ PrivilegeEntity privilegeEntity = new PrivilegeEntity();
|
|
|
+ privilegeEntity.setCode(cur.getCode() + "_" + rootOrgId);
|
|
|
+ privilegeEntity.setDescription(cur.getDescription());
|
|
|
+ privilegeEntity.setGroupId(group.getId());
|
|
|
+ privilegeEntity.setName(cur.getName());
|
|
|
+ privilegeEntity.setWeight(cur.getWeight());
|
|
|
+
|
|
|
+ privilegeEntity.setExt1(cur.getExt1());
|
|
|
+ privilegeEntity.setExt2(cur.getExt2());
|
|
|
+ privilegeEntity.setExt3(cur.getExt3());
|
|
|
+ privilegeEntity.setExt4(cur.getExt4());
|
|
|
+ privilegeEntity.setExt5(cur.getExt5());
|
|
|
+
|
|
|
+ PrivilegeEntity saved = privilegeRepo.save(privilegeEntity);
|
|
|
+ privilegeList.add(saved);
|
|
|
+
|
|
|
+ privilegeIdSet.add(saved.getId());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < globalPrivilegeList.size(); i++) {
|
|
|
+ PrivilegeEntity p = privilegeList.get(i);
|
|
|
+ if (null == p.getParentId()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer j = idIndex.get(globalPrivilegeList.get(i).getId());
|
|
|
+ p.setParentId(privilegeList.get(j).getId());
|
|
|
+ privilegeRepo.save(p);
|
|
|
+ }
|
|
|
+
|
|
|
+ rolePrivilegeService.updateRootOrgPrivilegeRelations(rootOrgId, group.getId(),
|
|
|
+ privilegeIdSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PrivilegeEntity> privilegeList = privilegeRepo
|
|
|
+ .findAllByGroupIdOrderByWeightDesc(group.getId());
|
|
|
+
|
|
|
+ EleTreeNode rootNode = new EleTreeNode(BasicConsts.ROOT_PRIVILEGE_ID, group.getName());
|
|
|
+
|
|
|
+ if (null != includeDisabledCodes && includeDisabledCodes) {
|
|
|
+ if (!isSuperAdmin()) {
|
|
|
+ throw new StatusException("012001", "非法请求");
|
|
|
+ }
|
|
|
+ TreeUtil.convert2OneEleTreeNode(rootNode, privilegeList, Lists.newArrayList());
|
|
|
+ } else {
|
|
|
+ TreeUtil.convert2OneEleTreeNode(rootNode, privilegeList, disabledPrivilegeCodeList);
|
|
|
+ }
|
|
|
+
|
|
|
+ OrgPrivilegeTreeDomain domain = new OrgPrivilegeTreeDomain();
|
|
|
+ domain.setPrivilegeGroupId(group.getId());
|
|
|
+ domain.setPrivilegeGroupType(group.getType().name());
|
|
|
+ domain.setTreeData(rootNode);
|
|
|
+
|
|
|
+ List<RootOrgPrivilegeRelationEntity> roprlist = rootOrgPrivilegeRelationRepo
|
|
|
+ .findAllByRootOrgIdAndGroupId(rootOrgId, group.getId());
|
|
|
+
|
|
|
+ List<Long> pList = roprlist.stream().map(RootOrgPrivilegeRelationEntity::getPrivilegeId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ domain.setOwnedPrivilegeIds(pList);
|
|
|
+
|
|
|
+ return domain;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 2020年2月11日
|
|
|
+ *
|
|
|
+ * @param rootOrgId
|
|
|
+ * @return
|
|
|
+ * @author WANGWEI
|
|
|
+ */
|
|
|
+ @ApiOperation(value = "查询学生端菜单")
|
|
|
+ @GetMapping("getStudentClientMenu")
|
|
|
+ public List<CustomPrivilegeDomain> getStudentClientMenu(
|
|
|
+ @RequestParam(required = false) Long rootOrgId) {
|
|
|
+
|
|
|
+ if (null == rootOrgId) {
|
|
|
+ rootOrgId = getRootOrgId();
|
|
|
+ } else {
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
+ }
|
|
|
+
|
|
|
+ String code = PrivilegeGroupType.STUDENT_CLIENT_MENU.name() + "_" + rootOrgId;
|
|
|
+
|
|
|
+ boolean undefined = false;
|
|
|
+
|
|
|
+ PrivilegeGroupEntity privilegeGroup = privilegeGroupRepo.findByCode(code);
|
|
|
+
|
|
|
+ if (null == privilegeGroup) {
|
|
|
+ privilegeGroup = privilegeGroupRepo
|
|
|
+ .findByCode(PrivilegeGroupType.STUDENT_CLIENT_MENU.name());
|
|
|
+ undefined = true;
|
|
|
+ } else {
|
|
|
+ if (null == privilegeGroup.getRootOrgId()) {
|
|
|
+ throw new StatusException("002101", "data error");
|
|
|
+ }
|
|
|
+ GlobalHelper.uniformRootOrg(rootOrgId, privilegeGroup.getRootOrgId());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Long> pList = null;
|
|
|
+ if (!undefined) {
|
|
|
+ List<RootOrgPrivilegeRelationEntity> list = rootOrgPrivilegeRelationRepo
|
|
|
+ .findAllByRootOrgIdAndGroupId(rootOrgId, privilegeGroup.getId());
|
|
|
+
|
|
|
+ pList = list.stream().map(RootOrgPrivilegeRelationEntity::getPrivilegeId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PrivilegeEntity> privilegeList = privilegeRepo
|
|
|
+ .findAllByGroupId(privilegeGroup.getId());
|
|
|
+
|
|
|
+ List<CustomPrivilegeDomain> privilegeInfoList = Lists.newArrayList();
|
|
|
+
|
|
|
+ for (PrivilegeEntity cur : privilegeList) {
|
|
|
+ boolean hasPrivilege = undefined ? true : (pList != null && pList.contains(cur.getId()));
|
|
|
+
|
|
|
+ if (!hasPrivilege) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ CustomPrivilegeDomain privilegeInfo = new CustomPrivilegeDomain();
|
|
|
+ privilegeInfo.setHasPrivilege(hasPrivilege);
|
|
|
+ privilegeInfo.setCode(cur.getCode());
|
|
|
+ privilegeInfo.setCreationTime(cur.getCreationTime());
|
|
|
+ privilegeInfo.setGroupId(cur.getGroupId());
|
|
|
+ privilegeInfo.setGroupCode(privilegeGroup.getCode());
|
|
|
+ privilegeInfo.setId(cur.getId());
|
|
|
+ privilegeInfo.setName(cur.getName());
|
|
|
+ privilegeInfo.setParentId(cur.getParentId());
|
|
|
+ privilegeInfo.setUpdateTime(cur.getUpdateTime());
|
|
|
+ privilegeInfo.setDescription(cur.getDescription());
|
|
|
+ privilegeInfo.setWeight(cur.getWeight());
|
|
|
+ privilegeInfo.setExt1(cur.getExt1());
|
|
|
+ privilegeInfo.setExt2(cur.getExt2());
|
|
|
+ privilegeInfo.setExt3(cur.getExt3());
|
|
|
+ privilegeInfo.setExt4(cur.getExt4());
|
|
|
+ privilegeInfo.setExt5(cur.getExt5());
|
|
|
+
|
|
|
+ //如果未自定义过菜单,则routeCode和权限编码一致
|
|
|
+ String routeCode;
|
|
|
+ if (undefined) {
|
|
|
+ routeCode = cur.getCode();
|
|
|
+ }
|
|
|
+ //如果自定义过菜单,则特殊处理
|
|
|
+ else {
|
|
|
+ routeCode = cur.getCode().replace("_" + rootOrgId, "");
|
|
|
+ }
|
|
|
+ privilegeInfo.setRouteCode(routeCode);
|
|
|
+
|
|
|
+ privilegeInfoList.add(privilegeInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return privilegeInfoList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询角色的权限ID集合")
|
|
|
+ @GetMapping("getPrivilegeIdList/{rootOrgId}/{roleId}")
|
|
|
+ public Set<Long> getPrivilegeIdList(@PathVariable Long rootOrgId, @PathVariable Long roleId) {
|
|
|
+ List<RolePrivilegeRelationEntity> rolePrivRelationList = rolePrivilegeRelationRepo
|
|
|
+ .findAllByRoleIdAndRootOrgId(roleId, rootOrgId);
|
|
|
+
|
|
|
+ Set<Long> pIdSet = Sets.newHashSet();
|
|
|
+ for (RolePrivilegeRelationEntity cur : rolePrivRelationList) {
|
|
|
+ pIdSet.add(cur.getPrivilegeId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return pIdSet;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询角色的权限ID集合(限制权限组)")
|
|
|
+ @GetMapping("getPrivilegeIdList/{rootOrgId}/{roleId}/{privilegeGroupId}")
|
|
|
+ public Set<Long> getPrivilegeIdList(@PathVariable Long rootOrgId, @PathVariable Long roleId,
|
|
|
+ @PathVariable Long privilegeGroupId) {
|
|
|
+ List<RolePrivilegeRelationEntity> rolePrivRelationList = rolePrivilegeRelationRepo
|
|
|
+ .findAllByRoleIdAndRootOrgId(roleId, rootOrgId);
|
|
|
+
|
|
|
+ Set<Long> pIdSet = Sets.newHashSet();
|
|
|
+ for (RolePrivilegeRelationEntity cur : rolePrivRelationList) {
|
|
|
+ PrivilegeEntity privilegeEntity = GlobalHelper.getPresentEntity(privilegeRepo,
|
|
|
+ cur.getPrivilegeId(), PrivilegeEntity.class);
|
|
|
+ if (privilegeEntity.getGroupId().equals(privilegeGroupId)) {
|
|
|
+ pIdSet.add(cur.getPrivilegeId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return pIdSet;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新角色权限关联")
|
|
|
+ @PostMapping("updateRolePrivilegeRelations")
|
|
|
+ @Transactional
|
|
|
+ public void updateRolePrivilegeRelations(@RequestBody UpdateRolePrivilegeRelationsDomain req) {
|
|
|
+ Long rootOrgId = Long.parseLong(req.getRootOrgId());
|
|
|
+ Long roleId = Long.parseLong(req.getRoleId());
|
|
|
+ Long privilegeGroupId = Long.parseLong(req.getPrivilegeGroupId());
|
|
|
+ Set<Long> privilegeIdSet = req.getPrivilegeIdSet();
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ Long userRootOrgId = accessUser.getRootOrgId();
|
|
|
+ if ((!rootOrgId.equals(userRootOrgId)) && (!isSuperAdmin())) {
|
|
|
+ throw new StatusException("012001", "非法请求");
|
|
|
+ }
|
|
|
+
|
|
|
+ rolePrivilegeService.updateRolePrivilegeRelations(rootOrgId, roleId, privilegeGroupId,
|
|
|
+ privilegeIdSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新顶级机构权限关联")
|
|
|
+ @PostMapping("updateRootOrgPrivilegeRelations")
|
|
|
+ @Transactional
|
|
|
+ public void updateRootOrgPrivilegeRelations(
|
|
|
+ @RequestBody UpdateRootOrgPrivilegeRelationsDomain req) {
|
|
|
+ Long rootOrgId = Long.parseLong(req.getRootOrgId());
|
|
|
+ Long privilegeGroupId = req.getPrivilegeGroupId();
|
|
|
+ Set<Long> privilegeIdSet = req.getPrivilegeIdSet();
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+ Long userRootOrgId = accessUser.getRootOrgId();
|
|
|
+ if ((!rootOrgId.equals(userRootOrgId)) && !isSuperAdmin()) {
|
|
|
+ throw new StatusException("012601", "非法请求");
|
|
|
+ }
|
|
|
+
|
|
|
+ rolePrivilegeService.updateRootOrgPrivilegeRelations(rootOrgId, privilegeGroupId,
|
|
|
+ privilegeIdSet);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "增加权限")
|
|
|
+ @PostMapping("addPrivilege")
|
|
|
+ @Transactional
|
|
|
+ public PrivilegeEntity addPrivilege(@RequestBody PrivilegeEntity privilege) {
|
|
|
+
|
|
|
+ privilege.setName(privilege.getName().trim());
|
|
|
+ privilege.setCode(privilege.getCode().trim());
|
|
|
+ privilege.setDescription(privilege.getDescription());
|
|
|
+
|
|
|
+ if (!privilege.getCode().matches("[0-9a-zA-Z_]+")) {
|
|
|
+ throw new StatusException("020101", "权限编码必须由字母,数字和下划线组成");
|
|
|
+ }
|
|
|
+
|
|
|
+ PrivilegeGroupEntity group = GlobalHelper.getEntity(privilegeGroupRepo,
|
|
|
+ privilege.getGroupId(), PrivilegeGroupEntity.class);
|
|
|
+ if (null == group) {
|
|
|
+ throw new StatusException("020001", "权限组不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == privilege.getParentId()
|
|
|
+ || BasicConsts.ROOT_PRIVILEGE_ID == privilege.getParentId()) {
|
|
|
+ privilege.setParentId(null);
|
|
|
+ } else {
|
|
|
+ PrivilegeEntity parentPrivilege = GlobalHelper.getEntity(privilegeRepo,
|
|
|
+ privilege.getParentId(), PrivilegeEntity.class);
|
|
|
+ if (null == parentPrivilege) {
|
|
|
+ throw new StatusException("020002", "父权限不存在");
|
|
|
+ }
|
|
|
+ if (!parentPrivilege.getGroupId().equals(privilege.getGroupId())) {
|
|
|
+ throw new StatusException("020003", "权限组错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PrivilegeEntity ret = privilegeRepo.save(privilege);
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "更新权限")
|
|
|
+ @PutMapping("updatePrivilege")
|
|
|
+ @Transactional
|
|
|
+ public PrivilegeEntity updatePrivilege(@RequestBody PrivilegeEntity privilege) {
|
|
|
+
|
|
|
+ privilege.setName(privilege.getName().trim());
|
|
|
+ privilege.setCode(privilege.getCode().trim());
|
|
|
+ privilege.setDescription(privilege.getDescription());
|
|
|
+ PrivilegeGroupEntity group = GlobalHelper.getEntity(privilegeGroupRepo,
|
|
|
+ privilege.getGroupId(), PrivilegeGroupEntity.class);
|
|
|
+ if (null == group) {
|
|
|
+ throw new StatusException("020001", "权限组不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != privilege.getParentId()) {
|
|
|
+ PrivilegeEntity parentPrivilege = GlobalHelper.getEntity(privilegeRepo,
|
|
|
+ privilege.getParentId(), PrivilegeEntity.class);
|
|
|
+ if (null == parentPrivilege) {
|
|
|
+ throw new StatusException("020002", "父权限不存在");
|
|
|
+ }
|
|
|
+ if (!parentPrivilege.getGroupId().equals(privilege.getGroupId())) {
|
|
|
+ throw new StatusException("020003", "权限组错误");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ privilege = privilegeRepo.save(privilege);
|
|
|
+
|
|
|
+ if (group.getType().equals(PrivilegeGroupType.STUDENT_CLIENT_MENU)
|
|
|
+ && group.getCode().equals(PrivilegeGroupType.STUDENT_CLIENT_MENU.name())) {
|
|
|
+
|
|
|
+ List<PrivilegeGroupEntity> gList = privilegeGroupRepo
|
|
|
+ .findAllByType(PrivilegeGroupType.STUDENT_CLIENT_MENU);
|
|
|
+
|
|
|
+ for (PrivilegeGroupEntity cur : gList) {
|
|
|
+ if (null == cur.getRootOrgId()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ PrivilegeEntity p = privilegeRepo
|
|
|
+ .findByCode(privilege.getCode() + "_" + cur.getRootOrgId());
|
|
|
+ if (null != p) {
|
|
|
+ p.setDescription(privilege.getDescription());
|
|
|
+
|
|
|
+ p.setExt1(privilege.getExt1());
|
|
|
+ p.setExt2(privilege.getExt2());
|
|
|
+ p.setExt3(privilege.getExt3());
|
|
|
+ p.setExt4(privilege.getExt4());
|
|
|
+ p.setExt5(privilege.getExt5());
|
|
|
+
|
|
|
+ privilegeRepo.save(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return privilege;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除权限")
|
|
|
+ @DeleteMapping("deletePrivilege/{id}")
|
|
|
+ @Transactional
|
|
|
+ public void deletePrivilege(@PathVariable Long id) {
|
|
|
+ PrivilegeEntity privilege = GlobalHelper.getEntity(privilegeRepo, id,
|
|
|
+ PrivilegeEntity.class);
|
|
|
+ if (null == privilege) {
|
|
|
+ throw new StatusException("020004", "权限不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<PrivilegeEntity> children = privilegeRepo.findAllByParentId(privilege.getId());
|
|
|
+ if (CollectionUtils.isNotEmpty(children)) {
|
|
|
+ throw new StatusException("020005", "存在子权限");
|
|
|
+ }
|
|
|
+
|
|
|
+ privilegeRepo.deleteById(id);
|
|
|
+ rolePrivilegeRelationRepo.deleteByPrivilegeId(id);
|
|
|
+ rootOrgPrivilegeRelationRepo.deleteByPrivilegeId(id);
|
|
|
+
|
|
|
+ PrivilegeGroupEntity groupEntity = GlobalHelper.getPresentEntity(privilegeGroupRepo,
|
|
|
+ privilege.getGroupId(), PrivilegeGroupEntity.class);
|
|
|
+
|
|
|
+ if (groupEntity.getType().equals(PrivilegeGroupType.STUDENT_CLIENT_MENU)
|
|
|
+ && groupEntity.getCode().equals(PrivilegeGroupType.STUDENT_CLIENT_MENU.name())) {
|
|
|
+
|
|
|
+ List<PrivilegeGroupEntity> gList = privilegeGroupRepo
|
|
|
+ .findAllByType(PrivilegeGroupType.STUDENT_CLIENT_MENU);
|
|
|
+
|
|
|
+ for (PrivilegeGroupEntity cur : gList) {
|
|
|
+ if (null == cur.getRootOrgId()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ PrivilegeEntity p = privilegeRepo
|
|
|
+ .findByCode(privilege.getCode() + "_" + cur.getRootOrgId());
|
|
|
+ if (null != p) {
|
|
|
+ privilegeRepo.deleteById(p.getId());
|
|
|
+ rolePrivilegeRelationRepo.deleteByPrivilegeId(p.getId());
|
|
|
+ rootOrgPrivilegeRelationRepo.deleteByPrivilegeId(p.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "查询权限")
|
|
|
+ @GetMapping("getPrivilege/{id}")
|
|
|
+ public PrivilegeEntity getPrivilege(@PathVariable Long id) {
|
|
|
+ PrivilegeEntity privilege = GlobalHelper.getEntity(privilegeRepo, id,
|
|
|
+ PrivilegeEntity.class);
|
|
|
+ if (null == privilege) {
|
|
|
+ throw new StatusException("020004", "权限不存在");
|
|
|
+ }
|
|
|
+ return privilege;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "校验权限(角色判断)")
|
|
|
+ @PostMapping("checkPrivileges")
|
|
|
+ public Map<String, Boolean> checkPrivileges(@RequestParam String privilegeCodes) {
|
|
|
+
|
|
|
+ List<String> privilegeCodeList = RegExpUtil.findAll(privilegeCodes, "[0-9A-Za-z_]+");
|
|
|
+
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+
|
|
|
+ List<Long> roleIdList = getAccessUserRoleIdList();
|
|
|
+
|
|
|
+ List<PrivilegeEntity> privilegeEntityList = privilegeRepo
|
|
|
+ .findAllByCodeIn(privilegeCodeList);
|
|
|
+
|
|
|
+ Map<String, Boolean> ret = Maps.newHashMap();
|
|
|
+
|
|
|
+ boolean isSuperAdmin = isSuperAdmin();
|
|
|
+
|
|
|
+ for (PrivilegeEntity cur : privilegeEntityList) {
|
|
|
+ if (isSuperAdmin) {
|
|
|
+ ret.put(cur.getCode(), true);
|
|
|
+ } else {
|
|
|
+ List<RolePrivilegeRelationEntity> relationEntityList = rolePrivilegeRelationRepo
|
|
|
+ .findAllByRoleIdInAndRootOrgIdAndPrivilegeId(roleIdList,
|
|
|
+ accessUser.getRootOrgId(), cur.getId());
|
|
|
+ ret.put(cur.getCode(), CollectionUtils.isNotEmpty(relationEntityList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "校验权限(机构判断)")
|
|
|
+ @PostMapping("checkRootOrgPrivileges")
|
|
|
+ public Map<String, Boolean> checkRootOrgPrivileges(@RequestParam String privilegeCodes) {
|
|
|
|
|
|
- RoleEntity roleByCode = roleRepo.findByCode(code);
|
|
|
- if (null != roleByCode) {
|
|
|
- throw new StatusException("620001", "角色编码已被占用");
|
|
|
- }
|
|
|
+ List<String> privilegeCodeList = RegExpUtil.findAll(privilegeCodes, "[0-9A-Za-z_]+");
|
|
|
|
|
|
- RoleEntity roleByName = roleRepo.findByNameAndRootOrgId(name, rootOrgId);
|
|
|
- if (null != roleByName) {
|
|
|
- throw new StatusException("620002", "角色名称已被占用");
|
|
|
- }
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
|
|
- RoleInfo info = new RoleInfo();
|
|
|
- info.setCode(code);
|
|
|
- info.setName(name);
|
|
|
- info.setRootOrgId(rootOrgId);
|
|
|
+ List<PrivilegeEntity> privilegeEntityList = privilegeRepo
|
|
|
+ .findAllByCodeIn(privilegeCodeList);
|
|
|
+
|
|
|
+ Map<String, Boolean> ret = Maps.newHashMap();
|
|
|
+
|
|
|
+ for (PrivilegeEntity cur : privilegeEntityList) {
|
|
|
+
|
|
|
+ Optional<RootOrgPrivilegeRelationEntity> optional = rootOrgPrivilegeRelationRepo
|
|
|
+ .findById(
|
|
|
+ new RootOrgPrivilegeRelationPK(cur.getId(), accessUser.getRootOrgId()));
|
|
|
+ ret.put(cur.getCode(), optional.isPresent());
|
|
|
+ }
|
|
|
|
|
|
- RoleEntity saved = rolePrivilegeService.saveRole(info);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
|
|
|
- return saved;
|
|
|
- }
|
|
|
+ @ApiOperation(value = "添加角色")
|
|
|
+ @PostMapping("addRole")
|
|
|
+ @Transactional
|
|
|
+ public RoleEntity addRole(@RequestBody RoleDomain req) {
|
|
|
+ Long rootOrgId = req.getRootOrgId();
|
|
|
+ String code = req.getCode();
|
|
|
+ String name = req.getName();
|
|
|
|
|
|
- @ApiOperation(value = "更新角色")
|
|
|
- @PutMapping("updateRole")
|
|
|
- @Transactional
|
|
|
- public RoleEntity updateRole(@RequestBody RoleDomain req) {
|
|
|
- Long rootOrgId = req.getRootOrgId();
|
|
|
- String code = req.getCode();
|
|
|
- String name = req.getName();
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
|
|
|
- validateRootOrgIsolation(rootOrgId);
|
|
|
+ RoleEntity roleByCode = roleRepo.findByCode(code);
|
|
|
+ if (null != roleByCode) {
|
|
|
+ throw new StatusException("620001", "角色编码已被占用");
|
|
|
+ }
|
|
|
|
|
|
- RoleInfo info = new RoleInfo();
|
|
|
- info.setCode(code);
|
|
|
- info.setName(name);
|
|
|
- info.setRootOrgId(rootOrgId);
|
|
|
+ RoleEntity roleByName = roleRepo.findByNameAndRootOrgId(name, rootOrgId);
|
|
|
+ if (null != roleByName) {
|
|
|
+ throw new StatusException("620002", "角色名称已被占用");
|
|
|
+ }
|
|
|
|
|
|
- RoleEntity saved = rolePrivilegeService.saveRole(info);
|
|
|
+ RoleInfo info = new RoleInfo();
|
|
|
+ info.setCode(code);
|
|
|
+ info.setName(name);
|
|
|
+ info.setRootOrgId(rootOrgId);
|
|
|
|
|
|
- return saved;
|
|
|
- }
|
|
|
+ RoleEntity saved = rolePrivilegeService.saveRole(info);
|
|
|
|
|
|
- @ApiOperation(value = "删除角色")
|
|
|
- @DeleteMapping("deleteRole/{roleId}")
|
|
|
- @Transactional
|
|
|
- public RoleEntity deleteRole(@PathVariable Long roleId) {
|
|
|
- User accessUser = getAccessUser();
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
|
|
|
- RoleInfo info = new RoleInfo();
|
|
|
- info.setId(roleId);
|
|
|
- info.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ @ApiOperation(value = "更新角色")
|
|
|
+ @PutMapping("updateRole")
|
|
|
+ @Transactional
|
|
|
+ public RoleEntity updateRole(@RequestBody RoleDomain req) {
|
|
|
+ Long rootOrgId = req.getRootOrgId();
|
|
|
+ String code = req.getCode();
|
|
|
+ String name = req.getName();
|
|
|
|
|
|
- RoleEntity saved = rolePrivilegeService.deleteRole(info, false);
|
|
|
+ validateRootOrgIsolation(rootOrgId);
|
|
|
|
|
|
- return saved;
|
|
|
- }
|
|
|
+ RoleInfo info = new RoleInfo();
|
|
|
+ info.setCode(code);
|
|
|
+ info.setName(name);
|
|
|
+ info.setRootOrgId(rootOrgId);
|
|
|
+
|
|
|
+ RoleEntity saved = rolePrivilegeService.saveRole(info);
|
|
|
+
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "删除角色")
|
|
|
+ @DeleteMapping("deleteRole/{roleId}")
|
|
|
+ @Transactional
|
|
|
+ public RoleEntity deleteRole(@PathVariable Long roleId) {
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+
|
|
|
+ RoleInfo info = new RoleInfo();
|
|
|
+ info.setId(roleId);
|
|
|
+ info.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+
|
|
|
+ RoleEntity saved = rolePrivilegeService.deleteRole(info, false);
|
|
|
+
|
|
|
+ return saved;
|
|
|
+ }
|
|
|
|
|
|
}
|