Ver Fonte

。。。

wangwei há 7 anos atrás
pai
commit
747790542b

+ 2 - 0
examcloud-core-basic-api-client/src/main/java/cn/com/qmth/examcloud/core/basic/api/client/UserCloudServiceClient.java

@@ -17,6 +17,8 @@ import cn.com.qmth.examcloud.core.basic.api.response.LoginResp;
 @Service
 public class UserCloudServiceClient extends BasicCloudClientSupport implements UserCloudService {
 
+	private static final long serialVersionUID = 5426364131505803296L;
+
 	@Autowired
 	RestTemplate restTemplate;
 

+ 74 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/RolePrivilegeController.java

@@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 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.web.helpers.tree.EleTreeNode;
 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.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.dao.AppRepo;
 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.PrivilegeRepo;
 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.Privilege;
 import cn.com.qmth.examcloud.core.basic.dao.entity.PrivilegeGroup;
@@ -59,12 +64,81 @@ public class RolePrivilegeController extends ControllerSupport {
 	@Autowired
 	OrgRepo orgRepo;
 
+	@Autowired
+	RoleRepo roleRepo;
+
 	@Autowired
 	RolePrivilegeRelationRepo rolePrivilegeRelationRepo;
 
 	@Autowired
 	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 = "查询权限组")
 	@GetMapping("getPrivilegeGroupList")
 	public List<PrivilegeGroupBean> getPrivilegeGroupList() {

+ 1 - 1
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/bean/PrivilegeInfo.java → examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/bean/PrivilegeInfo.java

@@ -1,4 +1,4 @@
-package cn.com.qmth.examcloud.core.basic.api.bean;
+package cn.com.qmth.examcloud.core.basic.api.controller.bean;
 
 import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
 import cn.com.qmth.examcloud.commons.web.helpers.tree.TreeNode;

+ 0 - 83
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/RolePrivilegeCloudServiceProvider.java

@@ -1,33 +1,21 @@
 package cn.com.qmth.examcloud.core.basic.api.provider;
 
 import java.util.List;
-import java.util.Set;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 
-import cn.com.qmth.examcloud.commons.base.exception.StatusException;
-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.core.basic.api.RolePrivilegeCloudService;
-import cn.com.qmth.examcloud.core.basic.api.bean.PrivilegeInfo;
 import cn.com.qmth.examcloud.core.basic.api.bean.RoleBean;
-import cn.com.qmth.examcloud.core.basic.api.request.GetPrivilegesReq;
-import cn.com.qmth.examcloud.core.basic.api.response.GetPrivilegesResp;
 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.RolePrivilegeRelationRepo;
 import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
-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.RolePrivilegeRelation;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -57,77 +45,6 @@ public class RolePrivilegeCloudServiceProvider extends ControllerSupport
 	@Autowired
 	PrivilegeGroupRepo privilegeGroupRepo;
 
-	@ApiOperation(value = "查询用户权限", notes = "")
-	@PostMapping("getPrivileges")
-	@Override
-	public GetPrivilegesResp getPrivileges(@RequestBody GetPrivilegesReq req) {
-
-		User accessUser = getAccessUser();
-		String groupCode = req.getGroupCode();
-		Long rootOrgId = Long.parseLong(req.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();
-
-		boolean full = req.isFull();
-
-		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);
-
-		}
-
-		GetPrivilegesResp resp = new GetPrivilegesResp();
-		resp.setPrivilegeInfoList(privilegeInfoList);
-		return resp;
-	}
-
 	@ApiOperation(value = "查询所有角色", notes = "")
 	@PostMapping("getAllRoles")
 	@Override

+ 0 - 11
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/RolePrivilegeCloudService.java

@@ -4,8 +4,6 @@ import java.util.List;
 
 import cn.com.qmth.examcloud.commons.web.cloud.api.CloudService;
 import cn.com.qmth.examcloud.core.basic.api.bean.RoleBean;
-import cn.com.qmth.examcloud.core.basic.api.request.GetPrivilegesReq;
-import cn.com.qmth.examcloud.core.basic.api.response.GetPrivilegesResp;
 
 /**
  * 角色权限云服务
@@ -15,15 +13,6 @@ import cn.com.qmth.examcloud.core.basic.api.response.GetPrivilegesResp;
  */
 public interface RolePrivilegeCloudService extends CloudService {
 
-	/**
-	 * 获取用户权限
-	 *
-	 * @author WANGWEI
-	 * @param req
-	 * @return
-	 */
-	GetPrivilegesResp getPrivileges(GetPrivilegesReq req);
-
 	/**
 	 * 获取所有角色
 	 *

+ 0 - 66
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/request/GetPrivilegesReq.java

@@ -1,66 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.api.request;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.BaseRequest;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年5月29日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class GetPrivilegesReq extends BaseRequest {
-
-	private static final long serialVersionUID = 4560605753913614535L;
-
-	private String userType;
-
-	private String userId;
-
-	private String groupCode;
-
-	private String rootOrgId;
-
-	private boolean full;
-
-	public String getUserType() {
-		return userType;
-	}
-
-	public void setUserType(String userType) {
-		this.userType = userType;
-	}
-
-	public String getUserId() {
-		return userId;
-	}
-
-	public void setUserId(String userId) {
-		this.userId = userId;
-	}
-
-	public String getGroupCode() {
-		return groupCode;
-	}
-
-	public void setGroupCode(String groupCode) {
-		this.groupCode = groupCode;
-	}
-
-	public String getRootOrgId() {
-		return rootOrgId;
-	}
-
-	public void setRootOrgId(String rootOrgId) {
-		this.rootOrgId = rootOrgId;
-	}
-
-	public boolean isFull() {
-		return full;
-	}
-
-	public void setFull(boolean full) {
-		this.full = full;
-	}
-
-}

+ 0 - 29
examcloud-core-basic-api/src/main/java/cn/com/qmth/examcloud/core/basic/api/response/GetPrivilegesResp.java

@@ -1,29 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.api.response;
-
-import java.util.List;
-
-import cn.com.qmth.examcloud.commons.web.cloud.api.BaseResponse;
-import cn.com.qmth.examcloud.core.basic.api.bean.PrivilegeInfo;
-
-/**
- * 类注释
- *
- * @author WANGWEI
- * @date 2018年6月8日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-public class GetPrivilegesResp extends BaseResponse {
-
-	private static final long serialVersionUID = 1212352081797526012L;
-
-	private List<PrivilegeInfo> privilegeInfoList;
-
-	public List<PrivilegeInfo> getPrivilegeInfoList() {
-		return privilegeInfoList;
-	}
-
-	public void setPrivilegeInfoList(List<PrivilegeInfo> privilegeInfoList) {
-		this.privilegeInfoList = privilegeInfoList;
-	}
-
-}