From d3783b1de9d92dbcdb9ff13aef1dd8dc750e60d4 Mon Sep 17 00:00:00 2001 From: Vinjor Date: Thu, 17 Oct 2024 16:18:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=B4=E4=BF=AE=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/DlRepairTicketsService.java | 2 +- .../impl/DlRepairTicketsServiceImpl.java | 80 +++++++++---------- .../impl/DlTicketWaresServiceImpl.java | 43 +++++----- 3 files changed, 63 insertions(+), 62 deletions(-) diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/DlRepairTicketsService.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/DlRepairTicketsService.java index 58fc85d7..e835c805 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/DlRepairTicketsService.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/DlRepairTicketsService.java @@ -97,7 +97,7 @@ public interface DlRepairTicketsService extends IService { * @author 小李 * @date 9:28 2024/10/14 **/ - Integer getUserRole(); + String getUserRole(); /** * 接单 diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java index 00e45845..280272a0 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.tickets.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.common.RepairConstants; import cn.iocoder.yudao.common.RepairErrorCodeConstants; +import cn.iocoder.yudao.common.RepairRoleEnum; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.base.entity.RepairWorker; import cn.iocoder.yudao.module.base.service.RepairWorkerService; @@ -51,21 +51,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.deepoove.poi.XWPFTemplate; import org.springframework.context.annotation.Lazy; -import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import javax.print.Doc; import javax.servlet.http.HttpServletResponse; import java.io.FileOutputStream; import java.io.InputStream; import java.math.BigDecimal; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; import static cn.iocoder.yudao.common.BaseConstants.ORDER_TENANT_NAME; @@ -138,6 +131,8 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl getPageType(DlRepairTicketsReqVO repairTicketsReqVO, Page page){ - Integer userRole = getUserRole(); - switch (userRole){ - case 1: - break; - case 2: - repairTicketsReqVO.setAdviserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId())); - break; - case 3: - // 查自己是什么班组的组长 + String userRoleCode = getUserRole(); + if(userRoleCode.equals(RepairRoleEnum.ADMIN.getCode())|| userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())){ + //维修管理员和总检,看所有数据 + }else if(userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())){ + //服务顾问看自己的 + repairTicketsReqVO.setAdviserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId())); + }else if(userRoleCode.equals(RepairRoleEnum.REPAIR_STAFF.getCode())){ + //维修工,进一步判断是否是班组长 + boolean ifLeader = workerService.getIfLeader(); + if(ifLeader){ + //班组长,看本班组所有数据 RepairWorker one = repairWorkerService.getOne(new LambdaQueryWrapper().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId())); // 查自己班组的员工信息 List list = repairWorkerService.list(new LambdaQueryWrapper().eq(RepairWorker::getWorkType, one.getWorkType())); // 所有的员工信息 List userIds = list.stream().map(RepairWorker::getUserId).collect(Collectors.toList()); repairTicketsReqVO.setUserIds(userIds); - break; - case 4: + }else{ + //普通维修工 repairTicketsReqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId())); - break; - case -1: - default: - return null; + } + }else{ + return null; } return baseMapper.getPageType(repairTicketsReqVO, page); } @@ -426,7 +422,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl byUserId = permissionApi.getRoleIdsByUserId(SecurityFrameworkUtils.getLoginUserId()); @@ -435,29 +431,33 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl collect = roleList.stream().filter(item -> byUserId.contains(item.getId())).collect(Collectors.toList()); // 取出角色名称 - List names = collect.stream().map(RoleReqDTO::getName).collect(Collectors.toList()); + List codes = collect.stream().map(RoleReqDTO::getCode).collect(Collectors.toList()); + // 维修业务管理员--可以看所有数据,但不能做操作 + if (codes.contains(RepairRoleEnum.ADMIN.getCode())){ + return RepairRoleEnum.ADMIN.getCode(); + } // 总检 - if (names.contains(RepairConstants.GENERAL_INSPECTION)){ - return 1; + if (codes.contains(RepairRoleEnum.INSPECTION.getCode())){ + return RepairRoleEnum.INSPECTION.getCode(); } // 服务顾问 - if (names.contains(RepairConstants.SERVICE_ADVISOR)){ - return 2; + if (codes.contains(RepairRoleEnum.ADVISOR.getName())){ + return RepairRoleEnum.ADVISOR.getName(); } - // 班组长 - if (names.contains(RepairConstants.TEAM_LEADER)){ - return 3; - } - // 维修工 - if (names.contains(RepairConstants.REPAIR_STAFF)){ - return 4; + // 维修工(或班组长) + if (codes.contains(RepairRoleEnum.REPAIR_STAFF.getCode())){ + return RepairRoleEnum.REPAIR_STAFF.getCode(); } // 维修仓库管理员 - if(names.contains(RepairConstants.REPAIR_WAREHOUSE)){ - return 5; + if(codes.contains(RepairRoleEnum.WAREHOUSE.getCode())){ + return RepairRoleEnum.WAREHOUSE.getCode(); + } + // 维修财务 + if(codes.contains(RepairRoleEnum.WXCW.getCode())){ + return RepairRoleEnum.WXCW.getCode(); } // 啥也不是 - return -1; + return null; } /** diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlTicketWaresServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlTicketWaresServiceImpl.java index 50c14dab..fb818e61 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlTicketWaresServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlTicketWaresServiceImpl.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.tickets.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.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.base.entity.RepairWorker; import cn.iocoder.yudao.module.base.service.RepairWorkerService; @@ -75,6 +76,8 @@ public class DlTicketWaresServiceImpl extends ServiceImpl getPage(DlTicketWaresReqVO reqVO, Page page){ // 确认查看者身份 - Integer userRole = repairTicketsService.getUserRole(); - // 啥也不是 - if (userRole == -1){ - return null; - } - switch (userRole){ - // 服务顾问 - case 2: - reqVO.setAdviserId(SecurityFrameworkUtils.getLoginUserId()); - break; - // 班组长 - case 3: - // 查自己是什么班组的组长 + String userRoleCode = repairTicketsService.getUserRole(); + if(userRoleCode.equals(RepairRoleEnum.ADMIN.getCode())|| userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())){ + //维修管理员和总检,看所有数据 + }else if(userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())){ + //服务顾问 + reqVO.setAdviserId(SecurityFrameworkUtils.getLoginUserId()); + }else if(userRoleCode.equals(RepairRoleEnum.REPAIR_STAFF.getCode())){ + //维修工,进一步判断是否是班组长 + boolean ifLeader = workerService.getIfLeader(); + if(ifLeader){ + //班组长,看本班组所有数据 RepairWorker one = repairWorkerService.getOne(new LambdaQueryWrapper().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId())); // 查自己班组的员工信息 List list = repairWorkerService.list(new LambdaQueryWrapper().eq(RepairWorker::getWorkType, one.getWorkType())); // 所有的员工信息 List userIds = list.stream().map(RepairWorker::getUserId).collect(Collectors.toList()); reqVO.setUserIds(userIds); - break; - // 维修工 - case 4: + }else{ + //普通维修工 reqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId())); - break; + } + }else if(userRoleCode.equals(RepairRoleEnum.WAREHOUSE.getCode())){ // 维修仓库管理员 - case 5: - reqVO.setStatus(null); - reqVO.setUserRole(5); - break; + reqVO.setStatus(null); + reqVO.setUserRole(5); + }else{ + return null; } return baseMapper.getPage(reqVO, page); }