From 9f0105d88aa14b06334f300743dd0f606f26665f Mon Sep 17 00:00:00 2001 From: zt Date: Mon, 20 Oct 2025 14:21:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=92=E8=89=B2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/common/enums/AppUserTypeEnum.java | 65 +++++++++++++++++++ .../impl/SubConstructionUserServiceImpl.java | 3 +- .../impl/BusProjectTeamMemberServiceImpl.java | 7 +- .../controller/system/SysUserController.java | 26 ++++++++ .../service/impl/SysUserServiceImpl.java | 20 +++++- 5 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/enums/AppUserTypeEnum.java diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/enums/AppUserTypeEnum.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/enums/AppUserTypeEnum.java new file mode 100644 index 00000000..9d6cee1f --- /dev/null +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/common/enums/AppUserTypeEnum.java @@ -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 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; + } + +} diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/contractor/service/impl/SubConstructionUserServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/contractor/service/impl/SubConstructionUserServiceImpl.java index 2126c602..f7e489a2 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/contractor/service/impl/SubConstructionUserServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/contractor/service/impl/SubConstructionUserServiceImpl.java @@ -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 ServiceImpllambdaQuery() .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; diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/service/impl/BusProjectTeamMemberServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/service/impl/BusProjectTeamMemberServiceImpl.java index 006c815f..7c36cab1 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/service/impl/BusProjectTeamMemberServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/project/service/impl/BusProjectTeamMemberServiceImpl.java @@ -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 ServiceImpllambdaQuery() .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); diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysUserController.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysUserController.java index 5e198e19..034ddbcd 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysUserController.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysUserController.java @@ -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 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() + "'失败,登录账号已存在"); diff --git a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java index 8b252e39..63d73a5c 100644 --- a/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java +++ b/xinnengyuan/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java @@ -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 sysUserRoles = new ArrayList<>(); for (Long project : projects) { SysUserRole sysUserRole = new SysUserRole();