wangwei 6 سال پیش
والد
کامیت
43dbc67250

+ 13 - 42
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/UserController.java

@@ -11,7 +11,6 @@ import java.util.stream.Stream;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.Subquery;
-import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringEscapeUtils;
@@ -85,7 +84,7 @@ public class UserController extends ControllerSupport {
 	UserRoleRelationRepo userRoleRelationRepo;
 
 	/**
-	 * 重新定义
+	 * 方法注释
 	 *
 	 * @author WANGWEI
 	 * @param curPage
@@ -95,12 +94,12 @@ public class UserController extends ControllerSupport {
 	 * @param name
 	 * @param enable
 	 * @param roleId
-	 * @param type
+	 * @param roleCode
 	 * @return
 	 */
 	@ApiOperation(value = "查询所有用户", notes = "")
 	@GetMapping("/all/{curPage}/{pageSize}")
-	public PageInfo<UserDomain> getAllUser(@PathVariable Integer curPage,
+	public PageInfo<UserDomain> getUserPage(@PathVariable Integer curPage,
 			@PathVariable Integer pageSize, @RequestParam Long rootOrgId,
 			@RequestParam String loginName, @RequestParam String name,
 			@RequestParam(required = false) Boolean enable,
@@ -126,7 +125,11 @@ public class UserController extends ControllerSupport {
 				throw new StatusException("B-150002", "角色不存在");
 			}
 		} else if (StringUtils.isNotBlank(roleCode)) {
-			RoleEntity roleEntity = roleRepo.findByCode(roleCode.trim());
+			RoleEntity roleEntity = roleRepo.findByCodeAndRootOrgIdIsNull(roleCode.trim());
+			if (null == roleEntity) {
+				roleEntity = roleRepo.findByCodeAndRootOrgId(roleCode.trim(),
+						accessUser.getRootOrgId());
+			}
 			if (null == roleEntity) {
 				throw new StatusException("B-150002", "角色不存在");
 			}
@@ -190,7 +193,7 @@ public class UserController extends ControllerSupport {
 			List<Long> roleIdList = Lists.newArrayList();
 			List<String> roleCodeList = Lists.newArrayList();
 			for (UserRoleRelationEntity cur : relationList) {
-				RoleEntity curRoleEntity = roleRepo.findByCode(cur.getRoleCode());
+				RoleEntity curRoleEntity = roleRepo.findOne(cur.getRoleId());
 				if (null == curRoleEntity) {
 					throw new StatusException("B-150002", "角色错误");
 				}
@@ -343,7 +346,7 @@ public class UserController extends ControllerSupport {
 				throw new StatusException("B-150007", "不允许新增或修改超级管理员");
 			}
 			UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(),
-					curRoleEntity.getId(), curRoleEntity.getCode());
+					curRoleEntity.getId());
 			userRoles.add(relation);
 		}
 
@@ -368,8 +371,9 @@ public class UserController extends ControllerSupport {
 		List<UserRoleRelationEntity> relationList = userRoleRelationRepo.findAllByUserId(userId);
 		if (CollectionUtils.isNotEmpty(relationList)) {
 			for (UserRoleRelationEntity cur : relationList) {
-				String roleCode = cur.getRoleCode();
-				if (roleCode.equals(RoleMeta.SUPER_ADMIN.name())) {
+				Long roleId = cur.getRoleId();
+				RoleEntity roleEntity = roleRepo.findOne(roleId);
+				if (roleEntity.getCode().equals(RoleMeta.SUPER_ADMIN.name())) {
 					return true;
 				}
 			}
@@ -508,37 +512,4 @@ public class UserController extends ControllerSupport {
 		return ret;
 	}
 
-	/**
-	 * 方法注释
-	 *
-	 * @author WANGWEI
-	 * @param request
-	 * @return
-	 */
-	@ApiOperation(value = "查询所有评卷员(不分页)", notes = "查询")
-	@GetMapping("/getMarkerListNoPageable")
-	public List<UserEntity> getMarkerListNoPageable(HttpServletRequest request) {
-
-		RoleEntity role = roleRepo.findByCode(RoleMeta.MARKER.name());
-
-		Specification<UserEntity> specification = (root, query, cb) -> {
-			List<Predicate> predicates = new ArrayList<>();
-			predicates.add(cb.equal(root.get("rootOrgId"), getRootOrgId()));
-
-			Subquery<UserRoleRelationEntity> subquery = query
-					.subquery(UserRoleRelationEntity.class);
-			Root<UserRoleRelationEntity> subRoot = subquery.from(UserRoleRelationEntity.class);
-			subquery.select(subRoot.get("userId"));
-			Predicate p1 = cb.equal(subRoot.get("roleId"), role.getId());
-			Predicate p2 = cb.equal(subRoot.get("userId"), root.get("id"));
-			subquery.where(cb.and(p1, p2));
-			predicates.add(cb.exists(subquery));
-
-			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-		};
-
-		List<UserEntity> userList = userRepo.findAll(specification);
-		return userList;
-	}
-
 }

+ 8 - 6
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/UserCloudServiceProvider.java

@@ -96,7 +96,10 @@ public class UserCloudServiceProvider extends ControllerSupport implements UserC
 
 		List<UserRoleRelationEntity> userRoles = Lists.newArrayList();
 		for (String roleCode : roleCodeList) {
-			RoleEntity roleEntity = roleRepo.findByCode(roleCode);
+			RoleEntity roleEntity = roleRepo.findByCodeAndRootOrgIdIsNull(roleCode);
+			if (null == roleEntity) {
+				roleEntity = roleRepo.findByCodeAndRootOrgId(roleCode, rootOrgId);
+			}
 			if (null == roleEntity) {
 				throw new StatusException("B-002002", "role code is wrong. roleCode=" + roleCode);
 			}
@@ -104,7 +107,7 @@ public class UserCloudServiceProvider extends ControllerSupport implements UserC
 				throw new StatusException("B-150007", "不允许新增或修改超级管理员");
 			}
 			UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(),
-					roleEntity.getId(), roleEntity.getCode());
+					roleEntity.getId());
 			userRoles.add(relation);
 		}
 
@@ -164,11 +167,10 @@ public class UserCloudServiceProvider extends ControllerSupport implements UserC
 		List<RoleBean> roleList = Lists.newArrayList();
 		if (CollectionUtils.isNotEmpty(relationList)) {
 			for (UserRoleRelationEntity cur : relationList) {
-				String roleCode = cur.getRoleCode();
-				RoleEntity roleEntity = roleRepo.findByCode(roleCode);
+				Long roleId = cur.getRoleId();
+				RoleEntity roleEntity = roleRepo.findOne(roleId);
 				if (null == roleEntity) {
-					throw new StatusException("B-002002",
-							"role code is wrong. roleCode=" + roleCode);
+					throw new StatusException("B-002002", "roleId wrong. roleId=" + roleId);
 				}
 				RoleBean role = new RoleBean(roleEntity.getId(), roleEntity.getCode(),
 						roleEntity.getName());

+ 3 - 1
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/RoleRepo.java

@@ -12,6 +12,8 @@ public interface RoleRepo
 			QueryByExampleExecutor<RoleEntity>,
 			JpaSpecificationExecutor<RoleEntity> {
 
-	RoleEntity findByCode(String code);
+	RoleEntity findByCodeAndRootOrgIdIsNull(String code);
+
+	RoleEntity findByCodeAndRootOrgId(String code, Long rootOrgId);
 
 }

+ 14 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/RoleEntity.java

@@ -40,6 +40,12 @@ public class RoleEntity extends JpaEntity {
 	@Column(unique = true, nullable = false)
 	private String name;
 
+	/**
+	 * 顶级机构.为null时,为全局角色
+	 */
+	@Column(nullable = true)
+	private Long rootOrgId;
+
 	public Long getId() {
 		return id;
 	}
@@ -64,4 +70,12 @@ public class RoleEntity extends JpaEntity {
 		this.name = name;
 	}
 
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
 }

+ 1 - 13
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/UserRoleRelationEntity.java

@@ -27,8 +27,6 @@ public class UserRoleRelationEntity extends JpaEntity {
 	@Id
 	private Long roleId;
 
-	private String roleCode;
-
 	/**
 	 * 构造函数
 	 *
@@ -42,13 +40,11 @@ public class UserRoleRelationEntity extends JpaEntity {
 	 *
 	 * @param userId
 	 * @param roleId
-	 * @param roleCode
 	 */
-	public UserRoleRelationEntity(Long userId, Long roleId, String roleCode) {
+	public UserRoleRelationEntity(Long userId, Long roleId) {
 		super();
 		this.userId = userId;
 		this.roleId = roleId;
-		this.roleCode = roleCode;
 	}
 
 	public Long getUserId() {
@@ -67,12 +63,4 @@ public class UserRoleRelationEntity extends JpaEntity {
 		this.roleId = roleId;
 	}
 
-	public String getRoleCode() {
-		return roleCode;
-	}
-
-	public void setRoleCode(String roleCode) {
-		this.roleCode = roleCode;
-	}
-
 }

+ 4 - 5
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

@@ -169,7 +169,7 @@ public class AuthServiceImpl implements AuthService {
 			orgId = student.getOrgId();
 
 			List<Role> roleList = Lists.newArrayList();
-			Role role = new Role(8L, "STUDENT", "学生");
+			Role role = new Role(null, "STUDENT", "学生");
 			roleList.add(role);
 			user.setRoleList(roleList);
 		}
@@ -387,11 +387,10 @@ public class AuthServiceImpl implements AuthService {
 		List<Role> roleList = Lists.newArrayList();
 		if (CollectionUtils.isNotEmpty(relationList)) {
 			for (UserRoleRelationEntity cur : relationList) {
-				String roleCode = cur.getRoleCode();
-				RoleEntity roleEntity = roleRepo.findByCode(roleCode);
+				Long roleId = cur.getRoleId();
+				RoleEntity roleEntity = roleRepo.findOne(roleId);
 				if (null == roleEntity) {
-					throw new StatusException("B-002002",
-							"role code is wrong. roleCode=" + roleCode);
+					throw new StatusException("B-002002", "roleId is wrong. roleId=" + roleId);
 				}
 				Role role = new Role(roleEntity.getId(), roleEntity.getCode(),
 						roleEntity.getName());