From 9ae8344f1085c4524f13d3f2427f56c8b84e4f15 Mon Sep 17 00:00:00 2001 From: xiaofajia <1665375861@qq.com> Date: Thu, 24 Oct 2024 20:27:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=A1=BE=E9=97=AE=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=8F=96=E8=BD=A6=E5=89=8D=E7=9A=84=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E5=89=8D=E7=9A=84=E7=BC=96=E8=BE=91=E5=B7=A5=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/DlRepairTicketsController.java | 14 ++++ .../admin/DlRepairTitemController.java | 40 +++++++++ .../service/DlRepairTicketsService.java | 18 ++++ .../tickets/service/DlRepairTitemService.java | 26 ++++++ .../impl/DlRepairTicketsServiceImpl.java | 83 +++++++++++++++++-- .../impl/DlRepairTitemServiceImpl.java | 67 +++++++++++++++ 6 files changed, 240 insertions(+), 8 deletions(-) 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 04bddcbf..97d8114d 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 @@ -308,5 +308,19 @@ public class DlRepairTicketsController { dlRepairTicketsService.noticeCus(noticeCusVO); return CommonResult.ok(); } + + /** + * 新增工单子项 + * + * @author 小李 + * @date 19:59 2024/10/24 + * @param respVO 主要有两个参数,主表ID,itemList(这个需要前端处理成子表的对象能接收的数据) + **/ + @PostMapping("/addItems") + @Operation(summary = "新增工单子项") + public CommonResult addItems(@RequestBody DlRepairTicketsRespVO respVO) { + dlRepairTicketsService.addItems(respVO); + return CommonResult.ok(); + } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTitemController.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTitemController.java index f6ca7c1d..0848686e 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTitemController.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/controller/admin/DlRepairTitemController.java @@ -69,5 +69,45 @@ public class DlRepairTitemController { public CommonResult updateRepairAndSale(@RequestBody DlRepairTitemReqVO dlRepairTitemReqVO){ return success(dlRepairTitemService.updateRepairAndSale(dlRepairTitemReqVO)); } + + /** + * 查看单个维修子表的数据 + * + * @author 小李 + * @param id 子表ID + **/ + @GetMapping("/getById") + @Operation(summary = "查看单个维修子表的数据") + public CommonResult getItemById(@RequestParam("id") String id){ + return success(dlRepairTitemService.getItemById(id)); + } + + /** + * 修改单个工单子项的内容 + * + * @author 小李 + * @date 15:41 2024/10/24 + * @param dlRepairTitemReqVO 对象 + **/ + @PostMapping("/updateById") + @Operation(summary = "修改单个工单子项的内容") + public CommonResult updateItemById(@RequestBody DlRepairTitemReqVO dlRepairTitemReqVO){ + dlRepairTitemService.updateItemById(dlRepairTitemReqVO); + return CommonResult.ok(); + } + + /** + * 维修工单单个子项 + * + * @author 小李 + * @date 20:18 2024/10/24 + * @param id 工单子项ID + **/ + @DeleteMapping("/removeById") + @Operation(summary = "维修工单单个子项") + public CommonResult removeItemById(@RequestParam("id") String id){ + dlRepairTitemService.removeItemById(id); + return CommonResult.ok(); + } } 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 10cf9d58..35855801 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 @@ -173,4 +173,22 @@ public interface DlRepairTicketsService extends IService { * @param noticeCusVO 请求对象 **/ void noticeCus(NoticeCusVO noticeCusVO); + + /** + * 重新计算工单的一些数值 + * + * @author 小李 + * @date 15:47 2024/10/24 + * @param ticketId 工单ID + **/ + boolean computeTicket(String ticketId); + + /** + * 新增工单子项 + * + * @author 小李 + * @date 19:59 2024/10/24 + * @param respVO 主要有两个参数,主表ID,itemList(这个需要前端处理成子表的对象能接收的数据) + **/ + void addItems(DlRepairTicketsRespVO respVO); } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/DlRepairTitemService.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/DlRepairTitemService.java index ed7bd6f3..a365d7ff 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/DlRepairTitemService.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/DlRepairTitemService.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.tickets.service; import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem; +import cn.iocoder.yudao.module.tickets.vo.DlRepairTitemReqVO; import cn.iocoder.yudao.module.tickets.vo.DlRepairTitemRespVO; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -41,4 +42,29 @@ public interface DlRepairTitemService extends IService { */ DlRepairTitem updateRepairAndSale(DlRepairTitem dlRepairTitem); + /** + * 查看单个维修子表的数据 + * + * @author 小李 + * @param id 子表ID + **/ + DlRepairTitem getItemById(String id); + + /** + * 修改单个工单子项的内容 + * + * @author 小李 + * @date 15:41 2024/10/24 + * @param dlRepairTitemReqVO 对象 + **/ + void updateItemById(DlRepairTitemReqVO dlRepairTitemReqVO); + + /** + * 维修工单单个子项 + * + * @author 小李 + * @date 20:18 2024/10/24 + * @param id 工单子项ID + **/ + void removeItemById(String id); } 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 f739d2ac..f8c7d8d1 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 @@ -187,10 +187,10 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl { item.setTicketId(ticketsRespVO.getId()); - if("01".equals(item.getItemType())){ + if ("01".equals(item.getItemType())) { //维修项目,初始状态,待派工 item.setItemStatus(TicketsItemStatusEnum.WAITING_WORK.getCode()); - }else if("02".equals(item.getItemType())){ + } else if ("02".equals(item.getItemType())) { //维修配件,初始状态,待领料 item.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode()); } @@ -432,13 +432,13 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl() @@ -792,7 +792,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl item.getValue().equals(tickets.getRepairType())) .findFirst() .orElse(null); - if (dictDataRespDTO != null){ + if (dictDataRespDTO != null) { type = dictDataRespDTO.getLabel(); } // 构建消息 @@ -804,6 +804,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl list = titemService.list(new LambdaQueryWrapper().eq(DlRepairTitem::getTicketId, ticketId)); + // 计算 + DlRepairTickets tickets = new DlRepairTickets(); + // 计算子项总数 + int count = list.stream().mapToInt(DlRepairTitem::getItemCount).sum(); + tickets.setId(ticketId); + tickets.setCount(count); + // 分类计算各自的总价和最终工单总价 + Map> map = list.stream().collect(Collectors.groupingBy(DlRepairTitem::getItemType)); + // 01项目,02,配件,03,其他 + tickets.setTotalPrice(BigDecimal.ZERO); + map.forEach((k, v) -> { + BigDecimal reduce = v.stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add); + tickets.setTotalPrice(tickets.getTotalPrice().add(reduce)); + if (k.equals("01")) { + tickets.setProjectPrice(reduce); + } else if (k.equals("02")) { + tickets.setPartPrice(reduce); + } else if (k.equals("03")) { + tickets.setOtherPrice(reduce); + } + }); + return baseMapper.updateById(tickets) > 0; + } + + /** + * 新增工单子项 + * + * @author 小李 + * @date 19:59 2024/10/24 + * @param respVO 主要有两个参数,主表ID,itemList(这个需要前端处理成子表的对象能接收的数据) + **/ + @Override + @DSTransactional + public void addItems(DlRepairTicketsRespVO respVO){ + // 先判断是否施工人员和销售人员是否都设置了 + respVO.getItemList().forEach(item -> { + if (ObjectUtil.isEmpty(item.getRepairIds())){ + throw exception0(500, "施工人员尚未设置"); + } + if (ObjectUtil.isEmpty(item.getSaleId())){ + throw exception0(500, "销售人员尚未设置"); + } + }); + // 新增子表 + List itemList = respVO.getItemList(); + itemList.forEach(item -> item.setTicketId(respVO.getId())); + titemService.saveBatch(itemList); + + // 更新主表 + boolean flag = computeTicket(respVO.getId()); + if (!flag){ + throw exception0(500, "系统错误"); + } + } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTitemServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTitemServiceImpl.java index cf65ce36..487721de 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTitemServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTitemServiceImpl.java @@ -2,16 +2,23 @@ package cn.iocoder.yudao.module.tickets.service.impl; import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem; import cn.iocoder.yudao.module.tickets.mapper.DlRepairTitemMapper; +import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService; import cn.iocoder.yudao.module.tickets.service.DlRepairTitemService; +import cn.iocoder.yudao.module.tickets.vo.DlRepairTitemReqVO; import cn.iocoder.yudao.module.tickets.vo.DlRepairTitemRespVO; +import com.baomidou.dynamic.datasource.annotation.DSTransactional; 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.stereotype.Service; +import javax.annotation.Resource; +import java.math.BigDecimal; import java.util.List; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0; + /** * 针对表【dl_repair_titem(维修工单子表)】的数据库操作Service实现 * @@ -22,6 +29,9 @@ import java.util.List; public class DlRepairTitemServiceImpl extends ServiceImpl implements DlRepairTitemService { + @Resource + private DlRepairTicketsService repairTicketsService; + /** * 维修工单子表 分页 * @@ -60,6 +70,63 @@ public class DlRepairTitemServiceImpl extends ServiceImpl