|
@@ -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,12 +25,16 @@ 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;
|
|
@@ -48,7 +52,6 @@ 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;
|
|
@@ -192,16 +195,11 @@ public class RolePrivilegeController extends ControllerSupport {
|
|
|
@ApiOperation(value = "查询权限组")
|
|
|
@GetMapping("getPrivilegeGroupList")
|
|
|
public List<PrivilegeGroupDomain> getPrivilegeGroupList() {
|
|
|
-
|
|
|
- List<PrivilegeGroupEntity> list = privilegeGroupRepo.findAllByRootOrgIdIsNullOrderById();
|
|
|
+ Sort sort = new Sort(Sort.Direction.ASC, "id");
|
|
|
+ List<PrivilegeGroupEntity> list = privilegeGroupRepo.findAll(sort);
|
|
|
|
|
|
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());
|
|
@@ -255,210 +253,6 @@ public class RolePrivilegeController extends ControllerSupport {
|
|
|
return pList;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 2020年2月19日
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param rootOrgId
|
|
|
- * @param includeDisabledCodes
|
|
|
- * @return
|
|
|
- */
|
|
|
- @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日
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @param rootOrgId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @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) {
|
|
@@ -520,9 +314,7 @@ public class RolePrivilegeController extends ControllerSupport {
|
|
|
Long privilegeGroupId = req.getPrivilegeGroupId();
|
|
|
Set<Long> privilegeIdSet = req.getPrivilegeIdSet();
|
|
|
|
|
|
- User accessUser = getAccessUser();
|
|
|
- Long userRootOrgId = accessUser.getRootOrgId();
|
|
|
- if ((!rootOrgId.equals(userRootOrgId)) && !isSuperAdmin()) {
|
|
|
+ if (!isSuperAdmin()) {
|
|
|
throw new StatusException("012601", "非法请求");
|
|
|
}
|
|
|
|
|
@@ -593,36 +385,9 @@ public class RolePrivilegeController extends ControllerSupport {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ PrivilegeEntity ret = privilegeRepo.save(privilege);
|
|
|
|
|
|
- return privilege;
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "删除权限")
|
|
@@ -642,32 +407,6 @@ public class RolePrivilegeController extends ControllerSupport {
|
|
|
|
|
|
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 = "查询权限")
|