Commit 0e036896 authored by cq990612's avatar cq990612

优化代码结构

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