From 71cb5249a6207e3cb5c759788e7e58245fc3f725 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Tue, 31 Dec 2024 18:31:29 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E9=94=80=E5=94=AE=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=94=AE=E5=90=8E=E7=BB=B4=E6=8A=A4=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=87=BA=E5=BA=93=E7=9A=84=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=A1=AE=E8=AE=A4=E9=AA=8C=E6=94=B6=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=9A=E4=BF=AE=E6=94=B9=E5=A4=84=E7=90=86=E6=9C=89?= =?UTF-8?q?=E5=87=BA=E8=B4=A7=E8=AE=BE=E5=A4=87id=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=AF=B9=E4=BA=8Eid?= =?UTF-8?q?=E7=9B=B8=E5=90=8C=E7=9A=84=E6=95=B0=E6=8D=AE=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=88=86=E7=BB=84=E6=93=8D=E4=BD=9C=EF=BC=8C=E7=84=B6=E5=90=8E?= =?UTF-8?q?=E4=BC=9A=E5=90=88=E8=AE=A1=E7=9B=B8=E5=90=8Cid=E7=9A=84?= =?UTF-8?q?=E5=B7=B2=E6=94=B6=E8=B4=A7=E6=95=B0=EF=BC=8C=E7=84=B6=E5=90=8E?= =?UTF-8?q?=E5=8F=AA=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=90=8Cid=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=95=B0=E6=8D=AE=E7=9A=84=E5=B7=B2=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=E6=95=B0=EF=BC=9B=E6=A0=B9=E6=8D=AE=20shipping=5Finfo?= =?UTF-8?q?rm=5Fdetail=5Fid=20=E5=88=86=E7=BB=84=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=90=88=E8=AE=A1=E6=AF=8F=E7=BB=84=E7=9A=84=20getThisCheckedN?= =?UTF-8?q?um=EF=BC=9B=E4=B8=BB=E8=A1=A8=E6=A0=B9=E6=8D=AE=E6=89=80?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E5=AD=90=E8=A1=A8=E7=9A=84=E5=B7=B2=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=E6=95=B0=E5=92=8C=E5=B7=B2=E9=AA=8C=E6=94=B6=E6=95=B0?= =?UTF-8?q?=E8=BF=9B=E8=A1=8C=E6=AF=94=E8=BE=83=E3=80=82=E5=B7=B2=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=E6=95=B0=E7=AD=89=E4=BA=8E=E6=9C=AC=E5=B7=B2=E9=AA=8C?= =?UTF-8?q?=E6=94=B6=E6=95=B0=E4=B8=BA=E5=85=A8=E9=83=A8=E9=AA=8C=E6=94=B6?= =?UTF-8?q?=EF=BC=9B=E5=B7=B2=E9=AA=8C=E6=94=B6=E6=95=B0=E5=A4=A7=E4=BA=8E?= =?UTF-8?q?0=E5=B0=8F=E4=BA=8E=E5=B7=B2=E6=94=B6=E8=B4=A7=E6=95=B0?= =?UTF-8?q?=E4=B8=BA=E9=83=A8=E5=88=86=E9=AA=8C=E6=94=B6=EF=BC=9B=E5=B7=B2?= =?UTF-8?q?=E9=AA=8C=E6=94=B6=E6=95=B0=E7=AD=89=E4=BA=8E0=E4=B8=BA?= =?UTF-8?q?=E5=BE=85=E9=AA=8C=E6=94=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AftersalesOutOrderServiceImpl.java | 250 ++++++++---------- 1 file changed, 108 insertions(+), 142 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java index 6eaee598..014d49d2 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java @@ -1,6 +1,7 @@ package com.ruoyi.aftersales.service.impl; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; import com.ruoyi.aftersales.domain.AfterSalesShippingDevice; @@ -670,6 +671,9 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService aftersalesOutOrder.setOutOrderCode(sysSalesShippingInform.getOutOrderCode()); + //更新销售订单子表的数据 + confirmCheckUpdateSalesOrderChild(shippingInformDetailList,sysSalesShippingInform); + String salesOrderCode = oldsSalesShippingInform.getSalesOrderCode(); List salesOrderCodes = new ArrayList<>(); @@ -714,29 +718,49 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService } - //设置为全部验收 - if (allWithoutCheckFlag == 1 && allWithCheckFlag == 1){ + + // 检查所有详情记录的验收数与已售后数对比,确定最终状态 + boolean allChecked = false; + boolean partiallyChecked = false; + + + int allHasCheckNum = shippingInformDetailList.stream().mapToInt(SysSalesShippingInformDetail::getHasCheckNum).sum(); + int allHasReceivingNum = shippingInformDetailList.stream().mapToInt(SysSalesShippingInformDetail::getHasReceivingNum).sum(); + + if (allHasReceivingNum == allHasCheckNum) { + allChecked = true; + } else if (allHasCheckNum > 0 && allHasCheckNum < allHasReceivingNum) { + partiallyChecked = true; + } + + + if (allChecked) { + // 已验收数等于已收货数 aftersalesOutOrder.setWarehouseOutStatus("12"); - sysSalesShippingInform.setWarehouseOutStatus("12"); -// sysSalesOrders.forEach(item->{ -// item.setDeliveryStatus("8");//全部验收 -// }); - }else { + sysSalesShippingInform.setWarehouseOutStatus("12");//设置为全部验收 + } else if (partiallyChecked) { //设置为部分验收 - aftersalesOutOrder.setWarehouseOutStatus("11"); -// sysSalesOrders.forEach(item->{ -// item.setDeliveryStatus("7");//部分验收 -// }); + aftersalesOutOrder.setWarehouseOutStatus("11");//设置为部分验收 + } else { + // 已验收数等于0 + aftersalesOutOrder.setWarehouseOutStatus("10");//设置为待验收 } -// for (SysSalesOrder sysSalesOrder : sysSalesOrders) { -// sysSalesOrder.setUpdateTime(new Date()); -// sysSalesOrder.setUpdateBy(loginName); -// int updateSysSalesOrderResult = sysSalesOrderMapper.updateSysSalesOrderBySalesOrderCode(sysSalesOrder); -// if (updateSysSalesOrderResult <= 0){ -// throw new BusinessException("更新销售订单数据失败"); -// } + + + +// //设置为全部验收 +// if (allWithoutCheckFlag == 1 && allWithCheckFlag == 1){ +// aftersalesOutOrder.setWarehouseOutStatus("12"); +// sysSalesShippingInform.setWarehouseOutStatus("12"); +// }else { +// //设置为部分验收 +// aftersalesOutOrder.setWarehouseOutStatus("11"); // } + + + + sysSalesShippingInform.setSalesOrderCode(oldsSalesShippingInform.getSalesOrderCode()); int updateShippingInformResult = shippingInformMapper.updateSysSalesShippingInformByOutOrderCode(sysSalesShippingInform); if (updateShippingInformResult <= 0){ @@ -755,32 +779,19 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService return updateAftersalesOutOrderResult; } - - private Integer processWithoutShippingDeviceId(List withoutShippingDeviceIdList,Integer allWithoutCheckFlag,SysSalesShippingInform sysSalesShippingInform) { - - - String loginName = ShiroUtils.getLoginName(); - - for (SysSalesShippingInformDetail sysSalesShippingInformDetail : withoutShippingDeviceIdList) { - Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); - SysSalesShippingInformDetail tempShippingInformDetail = shippingInformDetailMapper.selectSysSalesShippingInformDetailById(shippingInformDetailId); - - if (tempShippingInformDetail.getHasCheckNum() == null || tempShippingInformDetail.getHasCheckNum() == 0) { - sysSalesShippingInformDetail.setHasCheckNum(sysSalesShippingInformDetail.getThisCheckNum()); - } else { - sysSalesShippingInformDetail.setHasCheckNum(tempShippingInformDetail.getHasCheckNum() + sysSalesShippingInformDetail.getThisCheckNum()); - } - - if (sysSalesShippingInformDetail.getHasCheckNum() > sysSalesShippingInformDetail.getHasReceivingNum()) { - throw new BusinessException("已验收数和本次验收数之和不能大于已收货数"); - } - sysSalesShippingInformDetail.setThisCheckNum(null); - sysSalesShippingInformDetail.setUpdateTime(new Date()); - sysSalesShippingInformDetail.setUpdateBy(loginName); - if (Objects.equals(tempShippingInformDetail.getThisShippingNum(), sysSalesShippingInformDetail.getHasCheckNum())){ - allWithoutCheckFlag = 1; - } - + private void confirmCheckUpdateSalesOrderChild(List shippingInformDetailList, SysSalesShippingInform sysSalesShippingInform) { + // 根据 shipping_inform_detail_id 分组,并合计每组的 getThisReceivingNum + Map groupedDetails = shippingInformDetailList.stream() + .collect(Collectors.toMap( + SysSalesShippingInformDetail::getShippingInformDetailId, + Function.identity(), + (existing, replacement) -> { + existing.setThisReceivingNum(existing.getThisReceivingNum() + replacement.getThisReceivingNum()); + return existing; + }, + LinkedHashMap::new // 保持插入顺序 + )); + for (SysSalesShippingInformDetail sysSalesShippingInformDetail : groupedDetails.values()) { // 当前时间 Date now = new Date(); @@ -818,7 +829,7 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService } orderChild.setUpdateTime(new Date()); - orderChild.setUpdateBy(loginName); + orderChild.setUpdateBy(ShiroUtils.getLoginName()); // 检查数据库中是否有已有的 hasCheckNum,如果有则进行合计 Integer existingHasCheckNum = orderChild.getHasCheckNum(); @@ -842,8 +853,34 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService shouldContinue = false; } } + } + } + + + private Integer processWithoutShippingDeviceId(List withoutShippingDeviceIdList,Integer allWithoutCheckFlag,SysSalesShippingInform sysSalesShippingInform) { + + + String loginName = ShiroUtils.getLoginName(); + + for (SysSalesShippingInformDetail sysSalesShippingInformDetail : withoutShippingDeviceIdList) { + Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); + SysSalesShippingInformDetail tempShippingInformDetail = shippingInformDetailMapper.selectSysSalesShippingInformDetailById(shippingInformDetailId); + if (tempShippingInformDetail.getHasCheckNum() == null || tempShippingInformDetail.getHasCheckNum() == 0) { + sysSalesShippingInformDetail.setHasCheckNum(sysSalesShippingInformDetail.getThisCheckNum()); + } else { + sysSalesShippingInformDetail.setHasCheckNum(tempShippingInformDetail.getHasCheckNum() + sysSalesShippingInformDetail.getThisCheckNum()); + } + if (sysSalesShippingInformDetail.getHasCheckNum() > sysSalesShippingInformDetail.getHasReceivingNum()) { + throw new BusinessException("已验收数和本次验收数之和不能大于已收货数"); + } + sysSalesShippingInformDetail.setThisCheckNum(null); + sysSalesShippingInformDetail.setUpdateTime(new Date()); + sysSalesShippingInformDetail.setUpdateBy(loginName); + if (Objects.equals(tempShippingInformDetail.getThisShippingNum(), sysSalesShippingInformDetail.getHasCheckNum())){ + allWithoutCheckFlag = 1; + } int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(sysSalesShippingInformDetail); if (updateShippingInformDetailResult <= 0) { @@ -866,7 +903,21 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService throw new BusinessException("本次验收数量只能为0或1"); } - for (SysSalesShippingInformDetail sysSalesShippingInformDetail : withShippingDeviceIdList) { + + // 根据 shipping_inform_detail_id 分组,并合计每组的 getThisReceivingNum + Map groupedDetails = withShippingDeviceIdList.stream() + .collect(Collectors.toMap( + SysSalesShippingInformDetail::getShippingInformDetailId, + Function.identity(), + (existing, replacement) -> { + existing.setThisCheckNum(existing.getThisCheckNum() + replacement.getThisCheckNum()); + return existing; + }, + LinkedHashMap::new // 保持插入顺序 + )); + + + for (SysSalesShippingInformDetail sysSalesShippingInformDetail : groupedDetails.values()) { String shippingDeviceId = sysSalesShippingInformDetail.getShippingDeviceId(); AfterSalesShippingDevice afterSalesShippingDevice = afterSalesShippingDeviceMapper.selectAfterSalesShippingDeviceByShippingDeviceId(shippingDeviceId); if (sysSalesShippingInformDetail.getThisCheckNum() == 1){ @@ -881,108 +932,23 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService } - Integer allCheckNum = withShippingDeviceIdList.stream() - .mapToInt(SysSalesShippingInformDetail::getThisCheckNum) - .sum(); - - SysSalesShippingInformDetail sysSalesShippingInformDetail = withShippingDeviceIdList.get(0); - Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); - SysSalesShippingInformDetail tempShippingInformDetail = shippingInformDetailMapper.selectSysSalesShippingInformDetailById(shippingInformDetailId); - - if (tempShippingInformDetail.getHasCheckNum() == null) { - tempShippingInformDetail.setHasCheckNum(allCheckNum); - } else { - tempShippingInformDetail.setHasCheckNum(tempShippingInformDetail.getHasCheckNum() + allCheckNum); - } - - if (Objects.equals(tempShippingInformDetail.getThisShippingNum(), tempShippingInformDetail.getHasCheckNum())){ - allWithCheckFlag = 1; - } - -// //当前时间 -// Date now = new Date(); -// SysSalesShippingInform sysSalesShippingInform = shippingInformMapper.selectSysSalesShippingInformByCode(sysSalesShippingInformDetail.getOutOrderCode()); -// String salesOrderCode = sysSalesShippingInform.getSalesOrderCode(); -// String materialNo = sysSalesShippingInformDetail.getMaterialNo(); -// List salesOrderCodes = new ArrayList<>(); -// -// if (StringUtils.isNotEmpty(salesOrderCode)){ -// String[] splitSalesOrderCode = salesOrderCode.split(","); -// salesOrderCodes = Arrays.asList(splitSalesOrderCode); -// } -// for (String orderCode : salesOrderCodes) { -// SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); -// sysSalesOrderChild.setMaterialCode(materialNo); -// sysSalesOrderChild.setQuoteId(orderCode); -// SysSalesOrderChild tempSalesOrderChild = salesOrderChildMapper.selectSalesOrderChildByCodeAndNo(sysSalesOrderChild); -// long time = tempSalesOrderChild.getDeliveryTime().getTime(); -// } - - - // 当前时间 - Date now = new Date(); - - // 从数据库中查询销售出库单信息 - sysSalesShippingInform = shippingInformMapper.selectSysSalesShippingInformByCode(sysSalesShippingInform.getOutOrderCode()); - String salesOrderCode = sysSalesShippingInform.getSalesOrderCode(); - String materialNo = sysSalesShippingInformDetail.getMaterialNo(); - List salesOrderCodes = new ArrayList<>(); - - if (StringUtils.isNotEmpty(salesOrderCode)) { - salesOrderCodes = Arrays.asList(salesOrderCode.split(",")); - } - - // 存储每个销售订单详情及其计划交付时间 - List orderChildren = new ArrayList<>(); - - for (String orderCode : salesOrderCodes) { - SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); - sysSalesOrderChild.setMaterialCode(materialNo); - sysSalesOrderChild.setQuoteId(orderCode); - SysSalesOrderChild tempSalesOrderChild = salesOrderChildMapper.selectSalesOrderChildByCodeAndNo(sysSalesOrderChild); - if (tempSalesOrderChild != null) { - orderChildren.add(tempSalesOrderChild); - } - } - - // 按照计划交付时间与当前时间的差值排序 - orderChildren.sort(Comparator.comparing(o -> Math.abs(o.getDeliveryTime().getTime() - now.getTime()))); - - // 更新 HasCheckNum 数据 - boolean shouldContinue = true; - for (SysSalesOrderChild orderChild : orderChildren) { - if (!shouldContinue) { - break; - } - - - // 检查数据库中是否有已有的 hasCheckNum,如果有则进行合计 - Integer existingHasCheckNum = orderChild.getHasCheckNum(); - Integer currentHasCheckNum = tempShippingInformDetail.getHasCheckNum(); + // 只更新每个分组中的一个代表性记录 + for (SysSalesShippingInformDetail sysSalesShippingInformDetail : groupedDetails.values()) { + Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); + SysSalesShippingInformDetail tempShippingInformDetail = shippingInformDetailMapper.selectSysSalesShippingInformDetailById(shippingInformDetailId); - if (existingHasCheckNum != null) { - orderChild.setHasCheckNum(existingHasCheckNum + currentHasCheckNum); + Integer checkNumToAdd = sysSalesShippingInformDetail.getThisCheckNum(); + if (tempShippingInformDetail.getHasCheckNum() == null) { + sysSalesShippingInformDetail.setHasCheckNum(checkNumToAdd); } else { - orderChild.setHasCheckNum(currentHasCheckNum); - } - - int updateSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(orderChild); - if (updateSalesOrderChildResult <= 0) { - throw new RuntimeException("更新销售订单子表数据失败"); + sysSalesShippingInformDetail.setHasCheckNum(tempShippingInformDetail.getHasCheckNum() + checkNumToAdd); } - // 检查是否需要继续更新下一个 - if (orderChild.getHasCheckNum().equals(orderChild.getMaterialNum())) { - shouldContinue = true; - } else { - shouldContinue = false; + int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(sysSalesShippingInformDetail); + if (updateShippingInformDetailResult <= 0) { + throw new BusinessException("更新销售出货通知单详情数据失败"); } } - - int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(tempShippingInformDetail); - if (updateShippingInformDetailResult <= 0) { - throw new BusinessException("更新销售出货通知单详情数据失败"); - } return allWithCheckFlag; }