From 7b782583d4c73e684cab0d5605a41ef9d1b6f30d Mon Sep 17 00:00:00 2001 From: syruan <321359594@qq.com> Date: Thu, 21 Nov 2024 16:43:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E4=BF=AE=E7=AE=A1=E7=90=86=E4=BC=98?= =?UTF-8?q?=E5=8C=96=20=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repair/service/impl/RepairServiceImpl.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairServiceImpl.java index 6bf9c0b9..3de03c8a 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairServiceImpl.java @@ -103,7 +103,9 @@ public class RepairServiceImpl implements RepairService { resultMap.computeIfAbsent(item.getTypeNameId(), origin -> item).getRepairDeviceList().add(repairDeviceVO); resultMap.computeIfPresent(item.getTypeNameId(), (origin, novel) -> { - novel.setTotalCost(novel.getTotalCost().add(Optional.ofNullable(item.getTotalCost()).orElse(BigDecimal.ZERO))); + novel.setTotalCost(Optional.ofNullable(novel.getTotalCost()).orElse(BigDecimal.ZERO) + .add(Optional.ofNullable(item.getTotalCost()).orElse(BigDecimal.ZERO)) + ); return novel; }); }); @@ -150,17 +152,17 @@ public class RepairServiceImpl implements RepairService { public static List mergePartsNum(@NotNull List devices) { try { - Map map = devices.stream().filter(Objects::nonNull).collect( + Map map = devices.stream().filter(Objects::nonNull).collect( Collectors.toConcurrentMap(device -> device.getTypeId() + ":" + device.getPartCost() + ":" + device.getPartName(), device -> device, (existing, recently) -> { existing.setPartNum(existing.getPartNum() + recently.getPartNum()); return existing; }, ConcurrentHashMap::new) - ); + ); List list = new ArrayList<>(map.values()); - list.forEach(item -> { - item.setPartCost(Optional.ofNullable(item.getPartPrice()).orElse(BigDecimal.ZERO).multiply(new BigDecimal(item.getPartNum()))); - }); + list.forEach(item -> item.setPartCost(Optional.ofNullable(item.getPartPrice()).orElse(BigDecimal.ZERO) + .multiply(new BigDecimal(Optional.ofNullable(item.getPartNum()).orElse(0)))) + ); return list; } catch (Exception e) { throw new ServiceException("Error merging parts" + e.getMessage());