|
@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
@@ -21,14 +22,18 @@ import com.google.common.collect.Sets;
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
import cn.com.qmth.examcloud.commons.web.helpers.tree.EleTreeNode;
|
|
import cn.com.qmth.examcloud.commons.web.helpers.tree.EleTreeNode;
|
|
import cn.com.qmth.examcloud.commons.web.helpers.tree.TreeUtil;
|
|
import cn.com.qmth.examcloud.commons.web.helpers.tree.TreeUtil;
|
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.Role;
|
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.PrivilegeGroupBean;
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.PrivilegeGroupBean;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.PrivilegeInfo;
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.UpdateRolePrivilegeRelationsReq;
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.UpdateRolePrivilegeRelationsReq;
|
|
import cn.com.qmth.examcloud.core.basic.dao.AppRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.AppRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.PrivilegeGroupRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.PrivilegeGroupRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.PrivilegeRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.PrivilegeRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.RolePrivilegeRelationRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.RolePrivilegeRelationRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.App;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.App;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Privilege;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Privilege;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.PrivilegeGroup;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.PrivilegeGroup;
|
|
@@ -59,12 +64,81 @@ public class RolePrivilegeController extends ControllerSupport {
|
|
@Autowired
|
|
@Autowired
|
|
OrgRepo orgRepo;
|
|
OrgRepo orgRepo;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ RoleRepo roleRepo;
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
RolePrivilegeRelationRepo rolePrivilegeRelationRepo;
|
|
RolePrivilegeRelationRepo rolePrivilegeRelationRepo;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
RolePrivilegeService rolePrivilegeService;
|
|
RolePrivilegeService rolePrivilegeService;
|
|
|
|
|
|
|
|
+ @ApiOperation(value = "查询用户的权限树", notes = "")
|
|
|
|
+ @PostMapping("getUserPrivileges")
|
|
|
|
+ public List<PrivilegeInfo> getPrivileges(@RequestParam String groupCode,
|
|
|
|
+ @RequestParam boolean full) {
|
|
|
|
+
|
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
+ Long rootOrgId = accessUser.getRootOrgId();
|
|
|
|
+
|
|
|
|
+ PrivilegeGroup privilegeGroup = privilegeGroupRepo.findByCode(groupCode);
|
|
|
|
+
|
|
|
|
+ if (null == privilegeGroup) {
|
|
|
|
+ throw new StatusException("B-002001", "groupCode is not existing");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Role> roleList = accessUser.getRoleList();
|
|
|
|
+ List<Long> roleIdList = Lists.newArrayList();
|
|
|
|
+ for (Role cur : roleList) {
|
|
|
|
+ String roleCode = cur.getRoleCode();
|
|
|
|
+ cn.com.qmth.examcloud.core.basic.dao.entity.Role role = roleRepo.findByCode(roleCode);
|
|
|
|
+ if (null == role) {
|
|
|
|
+ throw new StatusException("B-002002", "role code is wrong. roleCode=" + roleCode);
|
|
|
|
+ }
|
|
|
|
+ roleIdList.add(role.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<RolePrivilegeRelation> rolePrivRelationList = rolePrivilegeRelationRepo
|
|
|
|
+ .findAllByRoleIdInAndRootOrgId(roleIdList, rootOrgId);
|
|
|
|
+
|
|
|
|
+ Set<String> pIdSet = Sets.newHashSet();
|
|
|
|
+ for (RolePrivilegeRelation cur : rolePrivRelationList) {
|
|
|
|
+ pIdSet.add(String.valueOf(cur.getPrivilegeId()));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Privilege> privilegeList = privilegeRepo.findAllByGroupId(privilegeGroup.getId());
|
|
|
|
+
|
|
|
|
+ List<PrivilegeInfo> privilegeInfoList = Lists.newArrayList();
|
|
|
|
+
|
|
|
|
+ for (Privilege cur : privilegeList) {
|
|
|
|
+ boolean hasPrivilege = pIdSet.contains(String.valueOf(cur.getId()));
|
|
|
|
+ if ((!full) && (!hasPrivilege)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ PrivilegeInfo privilegeInfo = new PrivilegeInfo();
|
|
|
|
+ privilegeInfo.setHasPrivilege(hasPrivilege);
|
|
|
|
+ privilegeInfo.setCode(cur.getCode());
|
|
|
|
+ privilegeInfo.setCreationTime(cur.getCreationTime());
|
|
|
|
+ privilegeInfo.setGroupId(cur.getGroupId());
|
|
|
|
+ privilegeInfo.setId(cur.getId());
|
|
|
|
+ privilegeInfo.setName(cur.getName());
|
|
|
|
+ privilegeInfo.setParentId(cur.getParentId());
|
|
|
|
+ privilegeInfo.setUpdateTime(cur.getUpdateTime());
|
|
|
|
+ privilegeInfo.setDescription(cur.getDescription());
|
|
|
|
+ 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 = "查询权限组")
|
|
@ApiOperation(value = "查询权限组")
|
|
@GetMapping("getPrivilegeGroupList")
|
|
@GetMapping("getPrivilegeGroupList")
|
|
public List<PrivilegeGroupBean> getPrivilegeGroupList() {
|
|
public List<PrivilegeGroupBean> getPrivilegeGroupList() {
|