From a63c015e531553b7d3fabdbd316edbd01d75a625 Mon Sep 17 00:00:00 2001 From: xiaofajia <1665375861@qq.com> Date: Thu, 21 Nov 2024 12:27:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=B7=A5=E5=8D=95=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DlRepairTicketsServiceImpl.java | 164 +++++++++--------- 1 file changed, 81 insertions(+), 83 deletions(-) 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 00dc57b3..019f4bdf 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 @@ -341,13 +341,13 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl waresGroupList = new ArrayList<>(); //查这个工单的配件 List waresList = repairTitemMapper.selectByTicketId(id); if (CollectionUtil.isNotEmpty(waresList)) { //先过滤出itenTypeId为null或空,或者itemTypeName为null或空的,为单独一个组 - List nullList = waresList.stream().filter(item->StringUtils.isEmpty(item.getItemTypeId()) || StringUtils.isEmpty(item.getItemTypeName())).collect(Collectors.toList()); + List nullList = waresList.stream().filter(item -> StringUtils.isEmpty(item.getItemTypeId()) || StringUtils.isEmpty(item.getItemTypeName())).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(nullList)) { AppWaresGroupVO waresGroupVO = new AppWaresGroupVO(); waresGroupVO.setWares(nullList); waresGroupVO.setGroupName("未知分组"); waresGroupVO.setNums(nullList.size()); - waresGroupVO.setTotalAmount(nullList.stream().peek(item->{ - if(null==item.getItemMoney()){ + waresGroupVO.setTotalAmount(nullList.stream().peek(item -> { + if (null == item.getItemMoney()) { item.setItemMoney(new BigDecimal(0)); } - }).map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO,BigDecimal::add)); + }).map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); waresGroupList.add(waresGroupVO); } //过滤出有分类的进行分组 - Map> groupListMap = waresList.stream().filter(item->StringUtils.isNotEmpty(item.getItemTypeId()) && StringUtils.isNotEmpty(item.getItemTypeName())).collect(Collectors.groupingBy(DlRepairTitem::getItemTypeId)); - for (String key:groupListMap.keySet()){ + Map> groupListMap = waresList.stream().filter(item -> StringUtils.isNotEmpty(item.getItemTypeId()) && StringUtils.isNotEmpty(item.getItemTypeName())).collect(Collectors.groupingBy(DlRepairTitem::getItemTypeId)); + for (String key : groupListMap.keySet()) { AppWaresGroupVO waresGroupVO = new AppWaresGroupVO(); waresGroupVO.setWares(groupListMap.get(key)); waresGroupVO.setGroupName(groupListMap.get(key).get(0).getItemTypeName()); waresGroupVO.setGroupId(key); waresGroupVO.setNums(groupListMap.get(key).size()); - waresGroupVO.setTotalAmount(groupListMap.get(key).stream().peek(item->{ - if(null==item.getItemMoney()){ + waresGroupVO.setTotalAmount(groupListMap.get(key).stream().peek(item -> { + if (null == item.getItemMoney()) { item.setItemMoney(new BigDecimal(0)); } - }).map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO,BigDecimal::add)); + }).map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add)); waresGroupList.add(waresGroupVO); } } result.setWaresGroupList(waresGroupList); - }else{ + } else { // 取配件----原有逻辑-电脑端 List wares = items.stream().filter(item -> item.getItemType().equals("02")).collect(Collectors.toList()); if (CollectionUtil.isNotEmpty(wares)) { @@ -1453,47 +1453,47 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl getBossNum(String selectType,String startDate,String endDate) { + public Map getBossNum(String selectType, String startDate, String endDate) { Map rtnMap = new HashMap<>(); //维修中---当前这一时刻 long workingNum = 0; //在厂数--当前这一时刻 long inCompanyNum = 0; //进场数 - long newOrderNum=0; + long newOrderNum = 0; //已完成 - long overNum=0; + long overNum = 0; //已交车 - long giveCusNum=0; + long giveCusNum = 0; List repairTickets = this.list(); if (!repairTickets.isEmpty()) { workingNum = repairTickets.stream().filter(item -> TicketsStatusEnum.WORKING.getCode().equals(item.getTicketsStatus())).count(); inCompanyNum = repairTickets.stream().filter(item -> TicketsStatusEnum.NO_PAY.getCode().equals(item.getTicketsStatus())).count(); LocalDateTime currentTime = LocalDateTime.now(); - if("today".equals(selectType)){ + if ("today".equals(selectType)) { String nowDayStr = DateUtil.formatDate(new Date()); //查当日进厂数、已完成、已交车 newOrderNum = repairTickets.stream().filter(item -> item.getCreateTime().toLocalDate().equals(currentTime.toLocalDate())).count(); //查当日已完成的(总检完成的) - overNum = repairTicketsMapper.selectCountByParams(nowDayStr,RecordTypeEnum.ZJ.getCode(),null,null); + overNum = repairTicketsMapper.selectCountByParams(nowDayStr, RecordTypeEnum.ZJ.getCode(), null, null); //查当日已交车的(已结算的) - giveCusNum = repairTicketsMapper.selectCountByParams(nowDayStr,RecordTypeEnum.JS.getCode(),null,null); - }else if("all".equals(selectType)){ + giveCusNum = repairTicketsMapper.selectCountByParams(nowDayStr, RecordTypeEnum.JS.getCode(), null, null); + } else if ("all".equals(selectType)) { //查累计进厂数、已完成、已交车 newOrderNum = repairTickets.size(); //查累计已完成的(总检完成的) - overNum = repairTicketsMapper.selectCountByParams(null,RecordTypeEnum.ZJ.getCode(),null,null); + overNum = repairTicketsMapper.selectCountByParams(null, RecordTypeEnum.ZJ.getCode(), null, null); //查累计已交车的(已结算的) - giveCusNum = repairTicketsMapper.selectCountByParams(null,RecordTypeEnum.JS.getCode(),null,null); - }else { + giveCusNum = repairTicketsMapper.selectCountByParams(null, RecordTypeEnum.JS.getCode(), null, null); + } else { //查某个时间范围内进厂数、已完成、已交车 - LocalDateTime startTime = LocalDateTime.parse(startDate+" 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - LocalDateTime endTime = LocalDateTime.parse(endDate+" 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + LocalDateTime startTime = LocalDateTime.parse(startDate + " 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); + LocalDateTime endTime = LocalDateTime.parse(endDate + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); newOrderNum = repairTickets.stream().filter(item -> item.getCreateTime().isAfter(startTime) && item.getCreateTime().isBefore(endTime)).count(); //查某区间范围内已完成的(总检完成的) - overNum = repairTicketsMapper.selectCountByParams(null,RecordTypeEnum.ZJ.getCode(), startDate+" 00:00:00", endDate+" 23:59:59"); + overNum = repairTicketsMapper.selectCountByParams(null, RecordTypeEnum.ZJ.getCode(), startDate + " 00:00:00", endDate + " 23:59:59"); //查某区间范围内已交车的(已结算的) - giveCusNum = repairTicketsMapper.selectCountByParams(null,RecordTypeEnum.JS.getCode(), startDate+" 00:00:00", endDate+" 23:59:59"); + giveCusNum = repairTicketsMapper.selectCountByParams(null, RecordTypeEnum.JS.getCode(), startDate + " 00:00:00", endDate + " 23:59:59"); } } rtnMap.put("workingNum", workingNum); @@ -1565,7 +1565,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl list = titemService.list(new LambdaQueryWrapper().eq(DlRepairTitem::getTicketId, ticketId)); - // 计算子表 - if (CollectionUtil.isEmpty(list)) { + // 取主表 + DlRepairTickets tickets = baseMapper.selectById(ticketId); + // 取子表 + List titems = titemService.list(new LambdaQueryWrapper().eq(DlRepairTitem::getTicketId, ticketId)); + if (CollectionUtil.isEmpty(titems)) { throw exception0(500, "没有项目、配件或其他"); } - List updateItems = list.stream().map(item -> { - DlRepairTitem titem = new DlRepairTitem(); - titem.setId(item.getId()); - // 取出折扣 - BigDecimal discount = item.getItemDiscount() == null ? new BigDecimal("1") : item.getItemDiscount(); - BigDecimal itemPrice = item.getItemPrice() == null ? BigDecimal.ZERO : item.getItemPrice(); - titem.setItemMoney(itemPrice.multiply(BigDecimal.valueOf(item.getItemCount())).multiply(discount)); - return titem; - }).collect(Collectors.toList()); - // 更新 - titemService.updateBatchById(updateItems); + // 计算子表 + Map titemsMap = titems.stream().collect(Collectors.toMap( + DlRepairTitem::getId, + item -> { + BigDecimal discount = item.getItemDiscount() == null ? BigDecimal.ONE : item.getItemDiscount(); + BigDecimal itemPrice = item.getItemPrice() == null ? BigDecimal.ZERO : item.getItemPrice(); + return itemPrice.multiply(BigDecimal.valueOf(item.getItemCount())).multiply(discount); + } + )); + titems.forEach(item -> { + item.setItemMoney(titemsMap.get(item.getId())); + }); + titemService.updateBatchById(titems); // 计算主表 - // 查新的子表信息 - List newList = titemService.list(new LambdaQueryWrapper().eq(DlRepairTitem::getTicketId, ticketId)); - DlRepairTickets tickets = new DlRepairTickets(); - // 计算子项总数 - int count = newList.stream().mapToInt(DlRepairTitem::getItemCount).sum(); - tickets.setId(ticketId); - tickets.setCount(count); - // 分类计算各自的总价和最终工单总价 - Map> map = newList.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); + // 总数量 + tickets.setCount(titems.stream().mapToInt(DlRepairTitem::getItemCount).sum()); + // 各类总价 + Map typePrice = titems.stream() + .collect(Collectors.groupingBy(DlRepairTitem::getItemType, + Collectors.mapping(DlRepairTitem::getItemMoney, + Collectors.reducing(BigDecimal.ZERO, BigDecimal::add)))); + BigDecimal itemTotalPrice = new BigDecimal("0"); + for (Map.Entry entry : typePrice.entrySet()) { + itemTotalPrice = itemTotalPrice.add(entry.getValue()); + switch (entry.getKey()){ + case "01": + tickets.setProjectPrice(entry.getValue()); + break; + case "02": + tickets.setPartPrice(entry.getValue()); + break; + case "03": + tickets.setOtherPrice(entry.getValue()); + break; } - }); - - // 工单总价还需要变,把其他新加的费用也需要算上 - // 查主表 - DlRepairTickets oldTicket = baseMapper.selectById(ticketId); + } + // 其他费用 // 管理费 - BigDecimal managerMoney = ObjectUtil.isNotEmpty(oldTicket.getManagerMoney()) ? oldTicket.getManagerMoney() : new BigDecimal("0"); + BigDecimal managerMoney = ObjectUtil.isNotEmpty(tickets.getManagerMoney()) ? tickets.getManagerMoney() : new BigDecimal("0"); // 救援费 - BigDecimal rescueMoney = ObjectUtil.isNotEmpty(oldTicket.getRescueMoney()) ? oldTicket.getRescueMoney() : new BigDecimal("0"); + BigDecimal rescueMoney = ObjectUtil.isNotEmpty(tickets.getRescueMoney()) ? tickets.getRescueMoney() : new BigDecimal("0"); // 三包费 - BigDecimal threePackMoney = ObjectUtil.isNotEmpty(oldTicket.getThreePackMoney()) ? oldTicket.getThreePackMoney() : new BigDecimal("0"); + BigDecimal threePackMoney = ObjectUtil.isNotEmpty(tickets.getThreePackMoney()) ? tickets.getThreePackMoney() : new BigDecimal("0"); // 定损费 - BigDecimal confirmFaultMoney = ObjectUtil.isNotEmpty(oldTicket.getConfirmFaultMoney()) ? oldTicket.getConfirmFaultMoney() : new BigDecimal("0"); + BigDecimal confirmFaultMoney = ObjectUtil.isNotEmpty(tickets.getConfirmFaultMoney()) ? tickets.getConfirmFaultMoney() : new BigDecimal("0"); - tickets.setTotalPrice(tickets.getTotalPrice().add(managerMoney).add(rescueMoney).add(threePackMoney).add(confirmFaultMoney)); + tickets.setTotalPrice(itemTotalPrice.add(managerMoney).add(rescueMoney).add(threePackMoney).add(confirmFaultMoney)); + baseMapper.updateById(tickets); - // 因为订单是在工单创建的时候就新增了,后面加的配件之类的金额没有同步到订单,这里同步一下 + // 更新订单 RepairOrderInfo orderInfo = repairOrderInfoService.getOne(new LambdaQueryWrapper().eq(RepairOrderInfo::getGoodsId, ticketId)); - RepairOrderInfo newOrderInfo = new RepairOrderInfo(); - newOrderInfo.setId(orderInfo.getId()); - // 更新商品原价和实付金额 - newOrderInfo.setGoodsPrice(tickets.getTotalPrice()); - newOrderInfo.setPayMoney(tickets.getTotalPrice()); - repairOrderInfoService.updateById(newOrderInfo); + orderInfo.setGoodsPrice(tickets.getTotalPrice()); + orderInfo.setPayMoney(tickets.getTotalPrice()); + repairOrderInfoService.updateById(orderInfo); return baseMapper.updateById(tickets) > 0; } @@ -1829,12 +1827,12 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl