Commit 0e036896 authored by cq990612's avatar cq990612

优化代码结构

parent 34b9ba79
......@@ -84,6 +84,7 @@ public enum BASE_RESP_CODE_ENUM {
CHOOSEATLEASTONEROLE("667", "至少保留一个角色"),
DOWNLOAD_ERROR("668", "下载出错"),
PLEASE_CANCELTHE_MANAGEMENTROLE("669", "注销账号,请取消管理角色"),
ATLEASTONEADMINISTRATORISREQUIRED("670", "至少需要一个系统管理员!"),
;
......
......@@ -264,32 +264,30 @@ public class WorkUserServiceImpl implements WorkUserService {
}
}
//判断当前是否已经有部门经理和中心管理
for (Integer roleId : roleIds) {
// 设置部门经理
if (2 == roleId) {
if (0 == DeptUpdateIndex && null != workDept.getDeptManagerId()) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.DEPARTMENT_MANAGER_ALREADY_EXISTS);
if (status != 1) {
for (Integer roleId : roleIds) {
// 设置部门经理
if (2 == roleId) {
if (0 == DeptUpdateIndex && null != workDept.getDeptManagerId()) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.DEPARTMENT_MANAGER_ALREADY_EXISTS);
}
workDept.setDeptManagerId(userId);
workDeptService.updateById(workDept);
}
workDept.setDeptManagerId(userId);
workDeptService.updateById(workDept);
}
// 设置中心管理员
if (3 == roleId) {
if (0 == centreUpdateIndex && null != centre.getCentreManagerId()) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.CENTERMANAGERALREADYEXISTS);
// 设置中心管理员
if (3 == roleId) {
if (0 == centreUpdateIndex && null != centre.getCentreManagerId()) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.CENTERMANAGERALREADYEXISTS);
}
centre.setCentreManagerId(userId);
workCentreService.updateById(centre);
}
centre.setCentreManagerId(userId);
workCentreService.updateById(centre);
}
}
if (null != status && status == 0 && !CollectionUtils.isEmpty(roleIds)) {
if (roleIds.size() == 1 && roleIds.get(0).equals(0)) {
}else{
throw new BaseCustomException(BASE_RESP_CODE_ENUM.PLEASE_CANCELTHE_MANAGEMENTROLE);
int roleCountByRoleId = UserRoleLevelUtils.getRoleCountByRoleId(4,userId);
if (roleCountByRoleId == 0) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.ATLEASTONEADMINISTRATORISREQUIRED);
}
}
workUserRoleMapper.insertBatch(userId, roleIds);
return true;
}
......
......@@ -8,6 +8,7 @@ import cn.wisenergy.mapper.WorkRoleMapper;
import cn.wisenergy.mapper.WorkUserRoleMapper;
import cn.wisenergy.model.app.WorkLevel;
import cn.wisenergy.model.app.WorkRole;
import cn.wisenergy.model.app.WorkUser;
import cn.wisenergy.model.dto.UserRoleLevelDto;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
......@@ -199,5 +200,20 @@ public class UserRoleLevelUtils {
return ranks;
}
public static int getRoleCountByRoleId(Integer roleId,Integer userId) {
if (null == roleId) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.INPUT_PARAM_IS_NULL);
}
List<WorkUser> users = utils.workUserRoleMapper.getUserRoleDeptDtoByRoleId(roleId);
int i = 0;
if (!CollectionUtils.isEmpty(users)) {
for (WorkUser user : users) {
if (!user.getId().equals(userId)) {
i++;
}
}
}
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