Commit 97b31bf2 authored by cq990612's avatar cq990612

优化代码结构

parent 28e69919
...@@ -283,14 +283,13 @@ public class WorkUserServiceImpl implements WorkUserService { ...@@ -283,14 +283,13 @@ public class WorkUserServiceImpl implements WorkUserService {
workCentreService.updateById(centre); workCentreService.updateById(centre);
} }
} }
}
}else { workUserRoleMapper.insertBatch(userId, roleIds);
int roleCountByRoleId = UserRoleLevelUtils.getRoleCountByRoleId(4,userId); // 判断管理员是否至少有一个
int roleCountByRoleId = UserRoleLevelUtils.getRoleCountByRoleId(4);
if (roleCountByRoleId == 0) { if (roleCountByRoleId == 0) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.ATLEASTONEADMINISTRATORISREQUIRED); throw new BaseCustomException(BASE_RESP_CODE_ENUM.ATLEASTONEADMINISTRATORISREQUIRED);
} }
}
workUserRoleMapper.insertBatch(userId, roleIds);
return true; return true;
} }
......
...@@ -200,20 +200,15 @@ public class UserRoleLevelUtils { ...@@ -200,20 +200,15 @@ public class UserRoleLevelUtils {
return ranks; return ranks;
} }
public static int getRoleCountByRoleId(Integer roleId,Integer userId) { public static int getRoleCountByRoleId(Integer roleId) {
if (null == roleId) { if (null == roleId) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL); throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
} }
List<WorkUser> users = utils.workUserRoleMapper.getUserRoleDeptDtoByRoleId(roleId); List<WorkUser> users = utils.workUserRoleMapper.getUserRoleDeptDtoByRoleId(roleId);
int i = 0;
if (!CollectionUtils.isEmpty(users)) { if (!CollectionUtils.isEmpty(users)) {
for (WorkUser user : users) { return users.size();
if (!user.getId().equals(userId)) {
i++;
} }
} return 0;
}
return i;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment