diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java b/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java index 00cbeaf8..35b8ed74 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/common/BaseConstants.java @@ -129,4 +129,6 @@ public class BaseConstants { /** 字典:超时自动总检配置 */ public static final String AUTO_INSPECTION = "auto_inspection"; + public static final String MAP_NO_DATA = "map_no_data"; + } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/mapper/RepairWorkerMapper.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/mapper/RepairWorkerMapper.java index a371e049..589ea9bf 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/mapper/RepairWorkerMapper.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/mapper/RepairWorkerMapper.java @@ -44,4 +44,12 @@ public interface RepairWorkerMapper extends BaseMapper { * @return cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO **/ RepairWorkerRespVO getByUserId(Long userId); + + /** + * 查询所有维修工信息 + * @author PQZ + * @date 17:28 2024/11/4 + * @return cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO + **/ + List listAllWorker(); } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/RepairWorkerService.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/RepairWorkerService.java index a8e393cc..72ac833c 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/RepairWorkerService.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/RepairWorkerService.java @@ -28,14 +28,14 @@ public interface RepairWorkerService extends IService { **/ void saveWorkers(List userList); + /** - * 根据用户id查询对应维修的角色,维修工人则查询班组,非维修工人查询角色 + * 查询所有维修工 * @author PQZ - * @date 17:21 2024/11/4 - * @param userId 用户id - * @return java.lang.String + * @date 14:07 2024/11/7 + * @return java.util.List **/ - String getWorkerRoleName(Long userId); + List listAllWorker(); /** * 更新维修工人 diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/impl/RepairRecordsServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/impl/RepairRecordsServiceImpl.java index d3c8d0fb..db3ad74a 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/impl/RepairRecordsServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/impl/RepairRecordsServiceImpl.java @@ -1,23 +1,29 @@ package cn.iocoder.yudao.module.base.service.impl; +import cn.iocoder.yudao.common.RepairRoleEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.base.entity.RepairRecords; import cn.iocoder.yudao.module.base.entity.RepairRecordsItem; +import cn.iocoder.yudao.module.base.entity.RepairWorker; import cn.iocoder.yudao.module.base.mapper.RepairRecordsMapper; import cn.iocoder.yudao.module.base.service.RepairRecordsItemService; import cn.iocoder.yudao.module.base.service.RepairRecordsService; import cn.iocoder.yudao.module.base.service.RepairWorkerService; import cn.iocoder.yudao.module.base.vo.RepairRecordsPageReqVO; import cn.iocoder.yudao.module.base.vo.RepairRecordsRespVO; +import cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO; +import cn.iocoder.yudao.module.system.api.permission.PermissionApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static cn.iocoder.yudao.common.BaseConstants.REPAIR_RECORD_TYPE_RECORD; @@ -39,7 +45,9 @@ public class RepairRecordsServiceImpl extends ServiceImpl queryList(RepairRecordsPageReqVO pageReqVO) { //根据条件查询维修记录 List list = repairRecordsMapper.queryRepairRecords(pageReqVO); + List userIds = list.stream().map(RepairRecords::getDealUserId).collect(Collectors.toList()); + //所有维修工 + List allWorker = workerService.listAllWorker(); + //转换成map + Map mapWorker = allWorker.stream().collect(Collectors.toMap(RepairWorker::getUserId,worker -> worker)); + //用户及角色 + Map> userRoleMap = permissionApi.roleCodesByUserIds(userIds); //为每一条维修记录设置查询附件 list.forEach(item -> { - item.setRoleName(workerService.getWorkerRoleName(item.getDealUserId())); + String workerName = mapWorker.getOrDefault(item.getDealUserId(),new RepairWorkerRespVO()).getWorkerTypeStr(); + if (null != workerName) { + item.setRoleName(workerName); + } else { + item.setRoleName(getRoleName(userRoleMap.get(item.getDealUserId()))); + } List itemList = itemService.getByMainId(REPAIR_RECORD_TYPE_RECORD, item.getId(), pageReqVO.getIsOpen()); item.setItemList(itemList); //相对路径按照“,”分隔 @@ -94,6 +114,37 @@ public class RepairRecordsServiceImpl extends ServiceImpl codes) { + //维修业务管理员 + if (codes.contains(RepairRoleEnum.ADMIN.getCode())) { + return RepairRoleEnum.ADMIN.getName(); + } + // 总检 + if (codes.contains(RepairRoleEnum.INSPECTION.getCode())) { + return RepairRoleEnum.INSPECTION.getName(); + } + // 服务顾问 + if (codes.contains(RepairRoleEnum.ADVISOR.getCode())) { + return RepairRoleEnum.ADVISOR.getName(); + } + // 维修仓库管理员 + if (codes.contains(RepairRoleEnum.WAREHOUSE.getCode())) { + return RepairRoleEnum.WAREHOUSE.getName(); + } + // 维修财务 + if (codes.contains(RepairRoleEnum.WXCW.getCode())) { + return RepairRoleEnum.WXCW.getName(); + } + return null; + } + /** * 根据当前用户和工单主表id查询当前在维修的项目信息 * diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/impl/RepairWorkerServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/impl/RepairWorkerServiceImpl.java index 5128a232..52f29168 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/impl/RepairWorkerServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/service/impl/RepairWorkerServiceImpl.java @@ -1,10 +1,8 @@ package cn.iocoder.yudao.module.base.service.impl; import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.common.RepairRoleEnum; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; -import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.module.app.controller.admin.NotifyMessageSocket; @@ -22,9 +20,6 @@ import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi; import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO; 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 cn.iocoder.yudao.module.system.api.user.AdminUserApi; -import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import cn.iocoder.yudao.module.system.api.user.dto.UserDTO; import cn.iocoder.yudao.module.tickets.entity.DlRepairTickets; import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem; @@ -39,7 +34,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; -import org.yaml.snakeyaml.events.Event; import javax.annotation.Resource; import java.io.IOException; @@ -116,50 +110,18 @@ public class RepairWorkerServiceImpl extends ServiceImpl * @author PQZ - * @date 17:21 2024/11/4 + * @date 14:07 2024/11/7 **/ @Override - public String getWorkerRoleName(Long userId) { - RepairWorkerRespVO worker = workerMapper.getByUserId(userId); - //如果为空说明不是维修工,查询当前用户的角色 - if (null != worker) { - return worker.getWorkerTypeStr(); - } else { - List roleIds = permissionApi.getRoleIdsByUserId(userId); - // 所有的角色信息 - List roleList = roleApi.getRoleList(); - // 过滤出登录用户有的角色信息 - List collect = roleList.stream().filter(item -> roleIds.contains(item.getId())).collect(Collectors.toList()); - // 取出角色code - List codes = collect.stream().map(RoleReqDTO::getCode).collect(Collectors.toList()); - //维修业务管理员 - if (codes.contains(RepairRoleEnum.ADMIN.getCode())) { - return RepairRoleEnum.ADMIN.getName(); - } - // 总检 - if (codes.contains(RepairRoleEnum.INSPECTION.getCode())) { - return RepairRoleEnum.INSPECTION.getName(); - } - // 服务顾问 - if (codes.contains(RepairRoleEnum.ADVISOR.getCode())) { - return RepairRoleEnum.ADVISOR.getName(); - } - // 维修仓库管理员 - if (codes.contains(RepairRoleEnum.WAREHOUSE.getCode())) { - return RepairRoleEnum.WAREHOUSE.getName(); - } - // 维修财务 - if (codes.contains(RepairRoleEnum.WXCW.getCode())) { - return RepairRoleEnum.WXCW.getName(); - } - } - return null; + public List listAllWorker() { + return workerMapper.listAllWorker(); } @Override diff --git a/dl-module-repair/src/main/resources/mapper/base/RepairWorkerMapper.xml b/dl-module-repair/src/main/resources/mapper/base/RepairWorkerMapper.xml index 68b75801..bfd5afe6 100644 --- a/dl-module-repair/src/main/resources/mapper/base/RepairWorkerMapper.xml +++ b/dl-module-repair/src/main/resources/mapper/base/RepairWorkerMapper.xml @@ -48,6 +48,16 @@ main.deleted = 0 AND main.user_id = #{userId} + diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApi.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApi.java index 914e1005..a4931512 100644 --- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApi.java +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApi.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespD import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -73,6 +74,15 @@ public interface PermissionApi { **/ List getRoleIdsByUserId(Long userId); + /** + * 通过用户id查询角色 + * @author PQZ + * @date 14:29 2024/11/7 + * @param userIds 用户id集合 + * @return key用户id,value角色codes + **/ + Map> roleCodesByUserIds(List userIds); + /** * 根据权限ID拿拥有该权限的所有人 * @author 小李 diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/dto/UserRoleDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/dto/UserRoleDTO.java new file mode 100644 index 00000000..fb49c588 --- /dev/null +++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/user/dto/UserRoleDTO.java @@ -0,0 +1,9 @@ +package cn.iocoder.yudao.module.system.api.user.dto; + +import lombok.Data; + +@Data +public class UserRoleDTO { + private Long userId; + private String roleCode; +} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApiImpl.java index 01154e35..2df4b009 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/permission/PermissionApiImpl.java @@ -1,12 +1,14 @@ package cn.iocoder.yudao.module.system.api.permission; import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO; +import cn.iocoder.yudao.module.system.api.user.dto.UserRoleDTO; import cn.iocoder.yudao.module.system.service.permission.PermissionService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -77,6 +79,21 @@ public class PermissionApiImpl implements PermissionApi { return roleIds.stream().collect(Collectors.toList()); } + /** + * 通过用户id查询角色 + * + * @param userIds 用户id集合 + * @return key用户id,value角色codes + * @author PQZ + * @date 14:29 2024/11/7 + **/ + @Override + public Map> roleCodesByUserIds(List userIds) { + List userRoleDTOList = permissionService.userRoleDTOList(userIds); + Map> resultMap = userRoleDTOList.stream().collect(Collectors.groupingBy(UserRoleDTO::getUserId,Collectors.mapping(UserRoleDTO::getRoleCode,Collectors.toList()))); + return resultMap; + } + /** * 根据权限ID拿拥有该权限的所有人 * @author 小李 diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleMapper.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleMapper.java index a1a489cc..1ee41bef 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleMapper.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/permission/UserRoleMapper.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.system.dal.mysql.permission; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.system.api.user.dto.UserDTO; +import cn.iocoder.yudao.module.system.api.user.dto.UserRoleDTO; import cn.iocoder.yudao.module.system.controller.admin.permission.vo.role.RolePageReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.UserRoleDO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -42,4 +42,13 @@ public interface UserRoleMapper extends BaseMapperX { List selectByRoleCode(@Param("tenantId") Long tenantId, @Param("roleCode") String roleCode); IPage selectListByRoleId(@Param("page") Page page,@Param("role") RolePageReqVO role); + + /** + * 通过用户id查询用户关联角色code + * @author PQZ + * @date 14:39 2024/11/7 + * @param userIds 用户id集合 + * @return java.util.List + **/ + List userCodes(@Param("userIds") List userIds); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionService.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionService.java index 07dda53f..3dd7c59e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionService.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionService.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.system.service.permission; import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO; +import cn.iocoder.yudao.module.system.api.user.dto.UserRoleDTO; import java.util.Collection; import java.util.List; @@ -26,6 +27,15 @@ public interface PermissionService { */ boolean hasAnyPermissions(Long userId, String... permissions); + /** + * 查询用户及角色 + * @author PQZ + * @date 14:42 2024/11/7 + * @param userIds 用户id + * @return java.util.List + **/ + List userRoleDTOList(List userIds); + /** * 判断是否有角色,任一一个即可 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java index 51e1c8dd..f5bc4295 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/permission/PermissionServiceImpl.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; import cn.iocoder.yudao.module.system.api.permission.dto.DeptDataPermissionRespDTO; +import cn.iocoder.yudao.module.system.api.user.dto.UserRoleDTO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.MenuDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO; import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleMenuDO; @@ -38,7 +39,6 @@ import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; -import static javafx.scene.input.KeyCode.H; /** * 权限 Service 实现类 @@ -87,6 +87,19 @@ public class PermissionServiceImpl implements PermissionService { return roleService.hasAnySuperAdmin(convertSet(roles, RoleDO::getId)); } + /** + * 查询用户及角色 + * + * @param userIds 用户id + * @return java.util.List + * @author PQZ + * @date 14:42 2024/11/7 + **/ + @Override + public List userRoleDTOList(List userIds) { + return userRoleMapper.userCodes(userIds); + } + /** * 判断指定角色,是否拥有该 permission 权限 * diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/UserRoleMapper.xml b/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/UserRoleMapper.xml index ced943c8..c9850c51 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/UserRoleMapper.xml +++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/mapper/UserRoleMapper.xml @@ -35,4 +35,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" +