角色优化
This commit is contained in:
@ -0,0 +1,65 @@
|
||||
package org.dromara.common.enums;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Getter
|
||||
public enum AppUserTypeEnum {
|
||||
|
||||
|
||||
SG("0", "施工人员", 2L),
|
||||
BZZ("0", "施工人员(班组长)", 3L),
|
||||
GL("1", "管理", 4L),
|
||||
FB("2", "分包", 5L),
|
||||
;
|
||||
|
||||
private final String type;
|
||||
|
||||
private final String value;
|
||||
|
||||
private final Long roleId;
|
||||
|
||||
AppUserTypeEnum(String type, String value,Long roleId) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
|
||||
public static final List<Long> ROLE_ID_LIST = Arrays.asList(SG.roleId, BZZ.roleId, FB.roleId, GL.roleId);
|
||||
|
||||
/**
|
||||
* roleId获取枚举
|
||||
*
|
||||
* @param roleId 角色
|
||||
* @return 枚举
|
||||
*/
|
||||
public static AppUserTypeEnum getByRoleId(Long roleId) {
|
||||
for (AppUserTypeEnum value : AppUserTypeEnum.values()) {
|
||||
if (value.getRoleId().equals(roleId)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* type获取枚举
|
||||
*
|
||||
* @param type 类型
|
||||
* @return 枚举
|
||||
*/
|
||||
public static AppUserTypeEnum getByType(String type) {
|
||||
for (AppUserTypeEnum value : AppUserTypeEnum.values()) {
|
||||
if (value.getType().equals(type)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -19,6 +19,7 @@ import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.DateUtils;
|
||||
import org.dromara.common.core.utils.ObjectUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.enums.AppUserTypeEnum;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.oss.core.OssClient;
|
||||
@ -276,7 +277,7 @@ public class SubConstructionUserServiceImpl extends ServiceImpl<SubConstructionU
|
||||
userRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery()
|
||||
.eq(SysUserRole::getUserId, constructionUser.getSysUserId())
|
||||
.eq(SysUserRole::getProjectId, dto.getProjectId())
|
||||
.in(SysUserRole::getRoleId, Arrays.asList(2L, 3L))
|
||||
.in(SysUserRole::getRoleId, AppUserTypeEnum.ROLE_ID_LIST)
|
||||
);
|
||||
//再添加分配角色
|
||||
Long roleId = "0".equals(dto.getPostId()) ? 2L : 3L;
|
||||
|
||||
@ -13,6 +13,7 @@ import org.dromara.common.core.constant.HttpStatus;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.ObjectUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.enums.AppUserTypeEnum;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
@ -198,14 +199,14 @@ public class BusProjectTeamMemberServiceImpl extends ServiceImpl<BusProjectTeamM
|
||||
relevancy.setProjectId(req.getProjectId());
|
||||
userProjectRelevancyService.save(relevancy);
|
||||
}
|
||||
//设置基础角色 先清空已有角色
|
||||
//设置基础角色 清空所有App权限角色
|
||||
userRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery()
|
||||
.eq(SysUserRole::getUserId, constructionUser.getSysUserId())
|
||||
.eq(SysUserRole::getProjectId, req.getProjectId())
|
||||
.in(SysUserRole::getRoleId, Arrays.asList(2L, 3L))
|
||||
.in(SysUserRole::getRoleId, AppUserTypeEnum.ROLE_ID_LIST)
|
||||
);
|
||||
//再添加分配角色
|
||||
Long roleId = "0".equals(req.getPostId()) ? 2L : 3L;
|
||||
Long roleId = "0".equals(req.getPostId()) ? AppUserTypeEnum.SG.getRoleId() : AppUserTypeEnum.BZZ.getRoleId();
|
||||
SysUserRole sysUserRole = new SysUserRole();
|
||||
sysUserRole.setUserId(constructionUser.getSysUserId());
|
||||
sysUserRole.setRoleId(roleId);
|
||||
|
||||
@ -16,6 +16,7 @@ import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.StreamUtils;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.encrypt.annotation.ApiEncrypt;
|
||||
import org.dromara.common.enums.AppUserTypeEnum;
|
||||
import org.dromara.common.excel.core.ExcelResult;
|
||||
import org.dromara.common.excel.utils.ExcelUtil;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
@ -45,6 +46,8 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 用户信息
|
||||
@ -224,6 +227,29 @@ public class SysUserController extends BaseController {
|
||||
.flatMap(dto -> dto.getRoleIds().stream())
|
||||
.distinct()
|
||||
.toList();
|
||||
//校验roleId (2,3,4,5)的数量,只能选择1个
|
||||
|
||||
// 过滤出roleList中包含的目标元素
|
||||
List<Long> matchedRoles = roleList.stream()
|
||||
.filter(AppUserTypeEnum.ROLE_ID_LIST::contains)
|
||||
.toList();
|
||||
|
||||
// 统计数量
|
||||
long count = matchedRoles.size();
|
||||
|
||||
// 数量校验
|
||||
if (count > 1) {
|
||||
return R.fail("app用户类型角色只能选择一个");
|
||||
}
|
||||
|
||||
// 获取具体包含的元素(或提示不包含)
|
||||
if (count == 1) {
|
||||
Long matchedRole = matchedRoles.get(0);
|
||||
AppUserTypeEnum byRoleId = AppUserTypeEnum.getByRoleId(matchedRole);
|
||||
if (byRoleId != null) {
|
||||
user.setAppUserType(byRoleId.getType());
|
||||
}
|
||||
}
|
||||
deptService.checkDeptMatchRole(user.getUserId(), roleList);
|
||||
if (!userService.checkUserNameUnique(user)) {
|
||||
return R.fail("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
|
||||
|
||||
@ -16,6 +16,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.apache.bcel.generic.RET;
|
||||
import org.dromara.common.core.constant.CacheNames;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.dto.UserDTO;
|
||||
@ -23,6 +24,7 @@ import org.dromara.common.core.enums.UserType;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.service.UserService;
|
||||
import org.dromara.common.core.utils.*;
|
||||
import org.dromara.common.enums.AppUserTypeEnum;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
@ -495,6 +497,14 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
if (flag < 1) {
|
||||
throw new ServiceException("修改用户" + user.getUserName() + "信息失败");
|
||||
}
|
||||
//修改construction_user表
|
||||
if(user.getAppUserType() != null){
|
||||
constructionUserService.lambdaUpdate()
|
||||
.set(SubConstructionUser::getUserRole, user.getAppUserType())
|
||||
.eq(SubConstructionUser::getSysUserId, user.getUserId())
|
||||
.update();
|
||||
}
|
||||
|
||||
// 没有修改部门则不需要修改用户与项目的关联
|
||||
// if (oldUser.getDeptId().equals(user.getDeptId())) {
|
||||
// return flag;
|
||||
@ -897,6 +907,9 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
if (sysUser == null) {
|
||||
throw new ServiceException("用户不存在!");
|
||||
}
|
||||
if(appUserType.equals(sysUser.getAppUserType())){
|
||||
throw new ServiceException("当前已是选中用户类型 !");
|
||||
}
|
||||
Long contractorId = null;
|
||||
SubConstructionUser constructionUser = constructionUserService.lambdaQuery()
|
||||
.eq(SubConstructionUser::getSysUserId, userId)
|
||||
@ -912,7 +925,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
contractorId = constructionUser.getContractorId();
|
||||
}
|
||||
String oldType = sysUser.getAppUserType();
|
||||
if ("0".equals(oldType)) { //施工人员->管理人员/分包人员
|
||||
if (AppUserTypeEnum.SG.getType().equals(oldType)) { //施工人员->管理人员/分包人员
|
||||
//清除app所有角色
|
||||
userRoleMapper.deleteAppRoleByUserId(userId);
|
||||
}else { //管理人员 <-> 施工人员
|
||||
@ -931,7 +944,10 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
||||
projects = projectIds;
|
||||
}
|
||||
|
||||
Long roleId = "1".equals(appUserType)?4L:5L;
|
||||
Long roleId = 2L;
|
||||
if(!AppUserTypeEnum.SG.getType().equals(appUserType)){
|
||||
roleId = AppUserTypeEnum.getByType(appUserType).getRoleId();
|
||||
}
|
||||
ArrayList<SysUserRole> sysUserRoles = new ArrayList<>();
|
||||
for (Long project : projects) {
|
||||
SysUserRole sysUserRole = new SysUserRole();
|
||||
|
||||
Reference in New Issue
Block a user