diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/common/InspectionRoleCommon.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/common/InspectionRoleCommon.java new file mode 100644 index 00000000..27d9ae1c --- /dev/null +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/common/InspectionRoleCommon.java @@ -0,0 +1,77 @@ +package cn.iocoder.yudao.common; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 检测相关和角色和其对应的权重 + * + * 权重分配如下: + * 检测业务管理员 + * 检测站老板 + * 检测官方 + * 检测商户 + * 经销商 + * 合作商 + * 引车员 + * 环检员 + * 外检员 + * 外检底检 + * 一审 + * 环检预审 + * 检测用户 + * @author 小李 + * @date 15:39 2024/12/15 +**/ +@AllArgsConstructor +@Getter +public enum InspectionRoleCommon { + + /** 检测业务管理员 */ + JIANCE("jiance", 1), + + /** 检测站老板 */ + JCBOSS("jcboss", 1), + + /** 检测官方 */ + JCGF("jcgf", 2), + + /** 检测商户 */ + JCSHOP("jcshop", 2), + + /** 经销商 */ + DEALERS("dealers", 2), + + /** 合作商 */ + PARTNERS("partners", 2), + + /** 引车员 */ + JCYCY("jcycy", 3), + + /** 环检员 */ + JCHJY("jchjy", 4), + + /** 外检员 */ + JCWJY("jcwjy", 4), + + /** 外检底检 */ + JCWJDJ("jcwjdj", 4), + + /** 一审 */ + JCYSZZ("jcyszz", 4), + + /** 环检预审 */ + JCHJYS("jchjys", 4), + + /** 检测用户 */ + JCYH("jcyh", 4), + + /** 检测员工 */ + JCWORKER("jcworker", 4); + + /** 角色Code */ + private final String code; + + /** 角色权重 */ + private final Integer weight; +} diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionUtilController.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionUtilController.java new file mode 100644 index 00000000..ae322a10 --- /dev/null +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionUtilController.java @@ -0,0 +1,74 @@ +package cn.iocoder.yudao.module.inspection.controller; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.common.InspectionRoleCommon; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; +import cn.iocoder.yudao.module.system.api.permission.PermissionApi; +import cn.iocoder.yudao.module.system.api.permission.RoleApi; +import cn.iocoder.yudao.module.system.api.permission.dto.RoleReqDTO; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +/** + * 检测用的工具Controller + * + * @author 小李 + * @date 15:36 2024/12/15 +**/ +@RestController +@RequestMapping("/admin-api/inspection/util") +public class InspectionUtilController { + + @Resource + private PermissionApi permissionApi; + + @Resource + private RoleApi roleApi; + + /** + * 根据用户取出当前用户的角色,只针对检测 + * + * @author 小李 + * @date 15:15 2024/12/15 + **/ + @GetMapping("/getRoleName") + public CommonResult getRoleName(){ + String name = "未知岗位"; + List roleIdsByUserId = permissionApi.getRoleIdsByUserId(SecurityFrameworkUtils.getLoginUserId()); + if (CollUtil.isEmpty(roleIdsByUserId)){ + return success(name); + } + List roleList = roleApi.getRoleList(); + List roles = roleList.stream().filter(item -> roleIdsByUserId.contains(item.getId())).collect(Collectors.toList()); + List roleCommons = Arrays.asList(InspectionRoleCommon.values()); + List codes = roleCommons.stream().map(InspectionRoleCommon::getCode).collect(Collectors.toList()); + List inspectionRoles = roles.stream().filter(item -> codes.contains(item.getCode())).collect(Collectors.toList()); + if (CollUtil.isEmpty(inspectionRoles)){ + return success(name); + } + Integer index = Integer.MAX_VALUE; + for (RoleReqDTO inspectionRole : inspectionRoles) { + InspectionRoleCommon inspectionRoleCommon = InspectionRoleCommon.valueOf(inspectionRole.getCode().toUpperCase()); + if (ObjectUtil.isEmpty(inspectionRoleCommon)){ + continue; + } + Integer weight = inspectionRoleCommon.getWeight(); + if (weight < index){ + index = weight; + name = inspectionRole.getName(); + } + } + return success(name); + } +} diff --git a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java index bc5b58e4..eee0b6c4 100644 --- a/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java +++ b/dl-module-rescue/src/main/java/cn/iocoder/yudao/module/rescue/app/controller/admin/SysLoginController.java @@ -193,7 +193,6 @@ public class SysLoginController { return success(loginService.login(authLoginReqVO)); } - /** * 汽修小程序登录方法 *