wangwei 7 年之前
父节点
当前提交
5a07f260b1

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

@@ -13,6 +13,7 @@ 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;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -356,12 +357,37 @@ public class UserController extends ControllerSupport {
 		return ret;
 	}
 
+	/**
+	 * 判断是否是超级管理员
+	 *
+	 * @author WANGWEI
+	 * @param userId
+	 * @return
+	 */
+	private boolean isSuperAdmin(Long userId) {
+		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())) {
+					return true;
+				}
+			}
+		}
+
+		return false;
+	}
+
 	@ApiOperation(value = "重置用户密码", notes = "重置密码")
 	@PutMapping("/resetPass/{id}")
 	public void resetPass(@PathVariable String id) {
 		List<Long> ids = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
+
 		for (Long userId : ids) {
+			if (isSuperAdmin(userId)) {
+				throw new StatusException("B-150410", "超级管理员账号不允许修改");
+			}
 			UserEntity user = userRepo.findOne(userId);
 			user.setPassword(Consts.DEFAULT_PASSWORD);
 			userRepo.save(user);
@@ -375,6 +401,9 @@ public class UserController extends ControllerSupport {
 				.collect(Collectors.toList());
 		List<String> ret = Lists.newArrayList();
 		for (Long userId : userIds) {
+			if (isSuperAdmin(userId)) {
+				throw new StatusException("B-150410", "超级管理员账号不允许修改");
+			}
 			UserEntity user = userRepo.findOne(userId);
 			user.setEnable(true);
 			userRepo.save(user);
@@ -390,6 +419,9 @@ public class UserController extends ControllerSupport {
 				.collect(Collectors.toList());
 		List<String> ret = Lists.newArrayList();
 		for (Long userId : userIds) {
+			if (isSuperAdmin(userId)) {
+				throw new StatusException("B-150410", "超级管理员账号不允许修改");
+			}
 			UserEntity user = userRepo.findOne(userId);
 			user.setEnable(false);
 			userRepo.save(user);