From 21e12b339ca1037f8552a80cf74f71765c32929e Mon Sep 17 00:00:00 2001 From: xiaofajia <1665375861@qq.com> Date: Mon, 14 Oct 2024 17:24:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E4=BF=AE=E5=B7=A5=E6=8E=A5=E5=8D=95/?= =?UTF-8?q?=E7=BB=B4=E4=BF=AE=E7=8F=AD=E7=BB=84=E9=95=BF=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E6=8C=87=E6=B4=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/RepairWorkerController.java | 23 ++++ .../base/service/RepairWorkerService.java | 16 +++ .../service/impl/RepairWorkerServiceImpl.java | 49 ++++++- .../admin/DlRepairTicketsController.java | 40 ++++++ .../tickets/entity/DlRepairTickets.java | 6 + .../service/DlRepairTicketsService.java | 26 ++++ .../impl/DlRepairTicketsServiceImpl.java | 121 ++++++++++++++---- .../mapper/tickets/DlRepairTicketsMapper.xml | 26 ++-- 8 files changed, 275 insertions(+), 32 deletions(-) diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/controller/admin/RepairWorkerController.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/controller/admin/RepairWorkerController.java index 5b6de31f..bb20e700 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/controller/admin/RepairWorkerController.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/base/controller/admin/RepairWorkerController.java @@ -90,5 +90,28 @@ public class RepairWorkerController { return success(workerService.queryListPage(pageReqVO,page)); } + /** + * 通过工单ID查到工单ID中所选择的员工信息 + * + * @author 小李 + * @date 15:53 2024/10/14 + * @param ticketId 工单ID + **/ + @GetMapping("/listByTicketId") + @Operation(summary = "通过工单ID查到工单ID中所选择的员工信息") + public CommonResult listByTicketId(@RequestParam("ticketId") String ticketId) { + return success(workerService.listByTicketId(ticketId)); + } + /** + * 通过班组长的id查该班组的员工 + * + * @author 小李 + * @date 16:55 2024/10/14 + **/ + @GetMapping("/listByLeadsId") + @Operation(summary = "通过班组长的id查该班组的员工") + public CommonResult listByLeads() { + return success(workerService.listByLeads()); + } } \ No newline at end of file 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 e4eec1c1..a14c8721 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 @@ -60,4 +60,20 @@ public interface RepairWorkerService extends IService { **/ IPage queryListPage(RepairWorkerPageReqVO pageReqVO, Page page); + /** + * 通过工单ID查到工单ID中所选择的员工信息 + * + * @author 小李 + * @date 15:53 2024/10/14 + * @param ticketId 工单ID + **/ + List listByTicketId(String ticketId); + + /** + * 通过班组长的id查该班组的员工 + * + * @author 小李 + * @date 16:55 2024/10/14 + **/ + List listByLeads(); } 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 26ae84be..e2117ec2 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 @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.base.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.base.entity.RepairWorker; import cn.iocoder.yudao.module.base.mapper.RepairWorkerMapper; import cn.iocoder.yudao.module.base.service.RepairWorkerService; @@ -9,15 +10,19 @@ import cn.iocoder.yudao.module.base.vo.RepairWorkerPageReqVO; import cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO; import cn.iocoder.yudao.module.base.vo.RepairWorkerSaveReqVO; import cn.iocoder.yudao.module.system.api.user.dto.UserDTO; +import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem; +import cn.iocoder.yudao.module.tickets.service.DlRepairTitemService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.ArrayList; -import java.util.List; +import java.util.*; +import java.util.stream.Collectors; /** * 维修工人 Service 实现类 @@ -31,6 +36,10 @@ public class RepairWorkerServiceImpl extends ServiceImpl listByTicketId(String ticketId){ + // 查工单的项目信息 + List titems = dlRepairTitemService.list(new LambdaQueryWrapper() + .and(item -> { + item.eq(DlRepairTitem::getTicketId, ticketId) + .eq(DlRepairTitem::getItemType, "01"); + })); + // 取所有的员工ID + Set ids = titems.stream().flatMap(item -> Arrays.stream(item.getRepairIds().split(","))).collect(Collectors.toSet()); + return baseMapper.selectList(new LambdaQueryWrapper().in(RepairWorker::getUserId, ids)); + + } + + /** + * 通过班组长的id查该班组的员工 + * + * @author 小李 + * @date 16:55 2024/10/14 + **/ + @Override + public List listByLeads(){ + // 取班组长的记录 + RepairWorker worker = baseMapper.selectOne(new LambdaQueryWrapper().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId())); + // 根据班组长的工种查所有该工程的工人 + List workerList = baseMapper.selectList(new LambdaQueryWrapper().eq(RepairWorker::getWorkType, worker.getWorkType())); + // 去掉班组长自己 + return workerList.stream().filter(item -> !Objects.equals(item.getUserId(), worker.getUserId())).collect(Collectors.toList()); + } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTicketsController.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTicketsController.java index 97113d61..659d5ad0 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTicketsController.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTicketsController.java @@ -173,5 +173,45 @@ public class DlRepairTicketsController { Page page = new Page<>(pageNo, pageSize); return success(dlRepairTicketsService.getPageType(repairTicketsReqVO, page)); } + + /** + * 判断登录用户的角色,针对维修工单中的四个角色 + * + * @author 小李 + * @date 9:28 2024/10/14 + **/ + @GetMapping("/userRole") + @Operation(summary = "判断登录用户的角色,针对维修工单中的四个角色") + public CommonResult getUserRole(){ + return success(dlRepairTicketsService.getUserRole()); + } + + /** + * 接单 + * + * @author 小李 + * @date 11:48 2024/10/14 + * @param id 工单ID + **/ + @GetMapping("/take") + @Operation(summary = "接单") + public CommonResult updateTake(@RequestParam("id") String id){ + dlRepairTicketsService.updateTake(id); + return CommonResult.ok(); + } + + /** + * 指派员工,通知施工 + * + * @author 小李 + * @date 15:34 2024/10/14 + * @param reqVO 请求对象 + **/ + @PostMapping("/notify") + @Operation(summary = "指派员工,通知施工") + public CommonResult updateRepair(@RequestBody DlRepairTicketsReqVO reqVO){ + dlRepairTicketsService.updateRepair(reqVO); + return CommonResult.ok(); + } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/entity/DlRepairTickets.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/entity/DlRepairTickets.java index a9901ea0..21fbfe84 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/entity/DlRepairTickets.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/entity/DlRepairTickets.java @@ -178,4 +178,10 @@ public class DlRepairTickets extends TenantBaseDO { /** 工单完成情况(0:未完成,1:已完成) */ private String isFinish; + + /** 工单当前施工人id */ + private Long nowRepairId; + + /** 工单当前施工人name */ + private String nowRepairName; } 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 78ef350a..58fc85d7 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 @@ -90,4 +90,30 @@ public interface DlRepairTicketsService extends IService { * @param repairTicketsReqVO 查询对象 **/ IPage getPageType(DlRepairTicketsReqVO repairTicketsReqVO, Page page); + + /** + * 判断登录用户的角色,针对维修工单中的四个角色 + * + * @author 小李 + * @date 9:28 2024/10/14 + **/ + Integer getUserRole(); + + /** + * 接单 + * + * @author 小李 + * @date 11:48 2024/10/14 + * @param id 工单ID + **/ + void updateTake(String id); + + /** + * 指派员工,通知施工 + * + * @author 小李 + * @date 15:34 2024/10/14 + * @param reqVO 请求对象 + **/ + void updateRepair(DlRepairTicketsReqVO reqVO); } 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 7bfa842d..6e6736d2 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 @@ -45,6 +45,7 @@ import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO; import cn.iocoder.yudao.module.tickets.vo.DlRepairTitemReqVO; import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -69,6 +70,7 @@ import java.util.stream.Collectors; import static cn.iocoder.yudao.common.BaseConstants.ORDER_TENANT_NAME; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0; /** * 针对表【dl_repair_tickets(维修工单表)】的数据库操作Service实现 @@ -168,8 +170,8 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl itemList = ticketsRespVO.getItemList(); List collect = itemList.stream().filter(item -> item.getItemType().equals("02")).collect(Collectors.toList()); ticketsRespVO.setPartStatus(CollectionUtil.isEmpty(collect) ? "01" : "02"); - // 工单进行状态 默认是未派工 - ticketsRespVO.setTicketsWorkStatus("04"); + // 工单进行状态 默认是等待接单 + ticketsRespVO.setTicketsWorkStatus("01"); // 新增主表 baseMapper.insert(ticketsRespVO); @@ -391,6 +393,40 @@ 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: + // 查自己是什么班组的组长 + 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: + repairTicketsReqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId())); + break; + case -1: + default: + return null; + } + return baseMapper.getPageType(repairTicketsReqVO, page); + } + + /** + * 判断登录用户的角色,针对维修工单中的四个角色 + * + * @author 小李 + * @date 9:28 2024/10/14 + **/ + @Override + public Integer getUserRole(){ // 查看当前登录用户是什么角色 // 当前登录用户的角色信息 List byUserId = permissionApi.getRoleIdsByUserId(SecurityFrameworkUtils.getLoginUserId()); @@ -400,27 +436,68 @@ 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()); + // 总检 + if (names.contains(RepairConstants.GENERAL_INSPECTION)){ + return 1; + } + // 服务顾问 if (names.contains(RepairConstants.SERVICE_ADVISOR)){ - // 服务顾问的ID - repairTicketsReqVO.setAdviserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId())); - }else if (names.contains(RepairConstants.TEAM_LEADER)){ - // 班组长 - // 查自己是什么班组的组长 - 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()); - // 可能指定的时候指定的有班组长,所以还要加班组长的id也加进去 - userIds.add(one.getUserId()); - repairTicketsReqVO.setUserIds(userIds); - }else if (names.contains(RepairConstants.REPAIR_STAFF)){ - // 维修工的ID - repairTicketsReqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId())); - }else if (names.contains(RepairConstants.GENERAL_INSPECTION)){ - // 维修总检,不操作 - }else return null; - return baseMapper.getPageType(repairTicketsReqVO, page); + return 2; + } + // 班组长 + if (names.contains(RepairConstants.TEAM_LEADER)){ + return 3; + } + // 维修工 + if (names.contains(RepairConstants.REPAIR_STAFF)){ + return 4; + } + // 啥也不是 + return -1; + } + + /** + * 接单 + * + * @author 小李 + * @date 11:48 2024/10/14 + * @param id 工单ID + **/ + @Override + public void updateTake(String id){ + // 改变时看看是否已经被接了 + int update = baseMapper.update(new LambdaUpdateWrapper() + .set(DlRepairTickets::getTicketsWorkStatus, "02") + .and(item -> { + item.eq(DlRepairTickets::getId, id) + .eq(DlRepairTickets::getTicketsWorkStatus, "01"); + })); + if (update != 1){ + throw exception0(500, "工单已被其他人接单了"); + } + } + + /** + * 指派员工,通知施工 + * + * @author 小李 + * @date 15:34 2024/10/14 + * @param reqVO 请求对象 + **/ + @Override + public void updateRepair(DlRepairTicketsReqVO reqVO){ + // 指派的时候看下是不是已经有人接单了 + int update = baseMapper.update(new LambdaUpdateWrapper() + .set(DlRepairTickets::getNowRepairId, reqVO.getNowRepairId()) + .set(DlRepairTickets::getNowRepairName, reqVO.getNowRepairName()) + .and(item -> { + item.eq(DlRepairTickets::getId, reqVO.getId()) + .eq(DlRepairTickets::getTicketsWorkStatus, "01"); + }) + ); + if (update != 1){ + throw exception0(500, "工单已开始"); + } } } diff --git a/dl-module-repair/src/main/resources/mapper/tickets/DlRepairTicketsMapper.xml b/dl-module-repair/src/main/resources/mapper/tickets/DlRepairTicketsMapper.xml index e26cc488..f74b20f2 100644 --- a/dl-module-repair/src/main/resources/mapper/tickets/DlRepairTicketsMapper.xml +++ b/dl-module-repair/src/main/resources/mapper/tickets/DlRepairTicketsMapper.xml @@ -43,6 +43,8 @@ + + @@ -83,7 +85,9 @@ profit, part_status, tickets_work_status, - is_finish + is_finish, + now_repair_id, + now_repair_name from dl_repair_tickets drt where drt.deleted = '0' @@ -128,7 +132,7 @@ - - - -