wangwei 7 лет назад
Родитель
Сommit
8273848d91

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

@@ -18,13 +18,13 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.util.RegExpUtil;
 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;
@@ -90,17 +90,7 @@ public class RolePrivilegeController extends ControllerSupport {
 			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.RoleEntity role = roleRepo
-					.findByCode(roleCode);
-			if (null == role) {
-				throw new StatusException("B-002002", "role code is wrong. roleCode=" + roleCode);
-			}
-			roleIdList.add(role.getId());
-		}
+		List<Long> roleIdList = getAccessUserRoleIdList();
 
 		List<RolePrivilegeRelationEntity> rolePrivRelationList = rolePrivilegeRelationRepo
 				.findAllByRoleIdInAndRootOrgId(roleIdList, rootOrgId);
@@ -304,13 +294,27 @@ public class RolePrivilegeController extends ControllerSupport {
 	@ApiOperation(value = "校验权限")
 	@PostMapping("checkPrivileges")
 	public Map<String, Boolean> checkPrivileges(@RequestParam String privilegeCodes) {
+
 		List<String> privilegeCodeList = RegExpUtil.findAll(privilegeCodes, "[0-9A-Za-z_]+");
 
-		for (String cur : privilegeCodeList) {
+		User accessUser = getAccessUser();
+
+		List<Long> roleIdList = getAccessUserRoleIdList();
 
+		List<PrivilegeEntity> PrivilegeEntityList = privilegeRepo
+				.findAllByCodeIn(privilegeCodeList);
+
+		Map<String, Boolean> ret = Maps.newHashMap();
+
+		for (PrivilegeEntity cur : PrivilegeEntityList) {
+			List<RolePrivilegeRelationEntity> relationEntityList = rolePrivilegeRelationRepo
+					.findAllByRoleIdInAndRootOrgIdAndPrivilegeId(roleIdList,
+							accessUser.getRootOrgId(), cur.getId());
+
+			ret.put(cur.getCode(), CollectionUtils.isNotEmpty(relationEntityList));
 		}
 
-		return null;
+		return ret;
 	}
 
 }

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

@@ -0,0 +1,5 @@
+package cn.com.qmth.examcloud.core.basic.api.provider;
+
+public class RolePrivilegeCloudServiceProvider {
+
+}

+ 2 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/PrivilegeRepo.java

@@ -27,4 +27,6 @@ public interface PrivilegeRepo
 
 	List<PrivilegeEntity> findAllByIdIn(List<Long> idList);
 
+	List<PrivilegeEntity> findAllByCodeIn(List<String> codeList);
+
 }

+ 5 - 4
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/RolePrivilegeRelationRepo.java

@@ -21,9 +21,10 @@ public interface RolePrivilegeRelationRepo
 
 	List<RolePrivilegeRelationEntity> findAllByRoleIdInAndRootOrgId(List<Long> roleIdList,
 			Long rootOrgId);
-	
-	void deleteByRoleIdAndRootOrgIdAndPrivilegeId(Long roleId,Long rootOrgId,Long privilegeId);
-	
-	
+
+	void deleteByRoleIdAndRootOrgIdAndPrivilegeId(Long roleId, Long rootOrgId, Long privilegeId);
+
+	List<RolePrivilegeRelationEntity> findAllByRoleIdInAndRootOrgIdAndPrivilegeId(
+			List<Long> roleIdList, Long rootOrgId, Long privilegeId);
 
 }