From ddc8b0752aed586a056f52548e92cc32627ef0c7 Mon Sep 17 00:00:00 2001 From: liuxiaoxu <1793812695@qq.com> Date: Thu, 14 Nov 2024 09:05:32 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=E5=94=AE=E5=90=8E=E7=AE=A1=E7=90=86=20?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E5=94=AE=E5=90=8E=E7=A1=AE=E8=AE=A4?= =?UTF-8?q?=E9=AA=8C=E6=94=B6=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3=EF=BC=9A?= =?UTF-8?q?=E9=AA=8C=E6=94=B6=E7=9A=84=E5=90=8C=E6=97=B6=EF=BC=8C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E6=9B=B4=E6=96=B0=E9=94=80=E5=94=AE=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E7=9A=84=E5=87=BA=E8=B4=A7=E7=8A=B6=E6=80=81=EF=BC=8C=E5=9B=A0?= =?UTF-8?q?=E4=B8=BA=E9=94=80=E5=94=AE=E8=AE=A2=E5=8D=95=E5=8F=B7=E6=98=AF?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5=E7=9A=84=EF=BC=8C=E9=9C=80=E8=A6=81=E9=81=8D?= =?UTF-8?q?=E5=8E=86=E5=85=B6=E6=AF=8F=E4=B8=80=E4=B8=AA=E5=AD=90=E8=A1=A8?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E4=B8=94=E8=A6=81=E7=AD=89=E6=AF=8F=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=AD=90=E8=A1=A8=E7=9A=84=E8=AE=A2=E5=8D=95=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E5=92=8C=E5=B7=B2=E9=AA=8C=E6=94=B6=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E7=9B=B8=E7=AD=89=E6=89=8D=E8=83=BD=E8=AE=BE=E7=BD=AE=E8=AF=A5?= =?UTF-8?q?=E9=94=80=E5=94=AE=E8=AE=A2=E5=8D=95=E5=85=A8=E9=83=A8=E9=AA=8C?= =?UTF-8?q?=E6=94=B6=EF=BC=8C=E5=90=A6=E5=88=99=E9=83=A8=E5=88=86=E9=AA=8C?= =?UTF-8?q?=E6=94=B6=EF=BC=9B=20=E4=BF=AE=E6=94=B9=20=E5=88=86=E5=88=AB?= =?UTF-8?q?=E5=A4=84=E7=90=86=E6=B2=A1=E6=9C=89=E8=AE=BE=E5=A4=87id?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E5=92=8C=E6=9C=89=E8=AE=BE=E5=A4=87?= =?UTF-8?q?id=E7=9A=84=E6=95=B0=E6=8D=AE=EF=BC=8C=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=EF=BC=9A=E6=8C=89=E7=85=A7=E4=BA=A4=E4=BB=98=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=92=8C=E5=BD=93=E5=89=8D=E6=97=B6=E9=97=B4=E7=9A=84=E5=89=8D?= =?UTF-8?q?=E5=90=8E=E6=9B=B4=E6=96=B0=E5=B7=B2=E9=AA=8C=E6=94=B6=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/AftersalesOutOrderServiceImpl.java | 151 +++++++++++++++++- 1 file changed, 144 insertions(+), 7 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 9566b4c1..05495858 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 @@ -14,9 +14,11 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.SysSalesOrder; +import com.ruoyi.system.domain.SysSalesOrderChild; import com.ruoyi.system.domain.SysSalesShippingInform; import com.ruoyi.system.domain.SysSalesShippingInformDetail; import com.ruoyi.system.domain.Vo.ConfirmReceivingDetailVo; +import com.ruoyi.system.mapper.SysSalesOrderChildMapper; import com.ruoyi.system.mapper.SysSalesOrderMapper; import com.ruoyi.system.mapper.SysSalesShippingInformDetailMapper; import com.ruoyi.system.mapper.SysSalesShippingInformMapper; @@ -33,7 +35,6 @@ import com.ruoyi.common.core.text.Convert; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import static com.ruoyi.common.config.datasource.DynamicDataSourceContextHolder.log; /** * 售后维护设备出库Service业务层处理 @@ -66,6 +67,9 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService @Autowired private SysSalesOrderMapper sysSalesOrderMapper; + @Autowired + private SysSalesOrderChildMapper salesOrderChildMapper; + /** * 查询售后维护设备出库 * @@ -649,12 +653,12 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService if (!CollectionUtils.isEmpty(withoutShippingDeviceIdList)){ // 处理没有出货设备ID的数据 - allWithoutCheckFlag = processWithoutShippingDeviceId(withoutShippingDeviceIdList, allWithoutCheckFlag); + allWithoutCheckFlag = processWithoutShippingDeviceId(withoutShippingDeviceIdList, allWithoutCheckFlag,sysSalesShippingInform); } if (!CollectionUtils.isEmpty(withShippingDeviceIdList)){ // 处理有出货设备ID的数据 - allWithCheckFlag = processWithShippingDeviceId(withShippingDeviceIdList, allWithCheckFlag); + allWithCheckFlag = processWithShippingDeviceId(withShippingDeviceIdList, allWithCheckFlag,sysSalesShippingInform); } @@ -674,7 +678,40 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService salesOrderCodes = Arrays.asList(splitSalesOrderCode); } - // List sysSalesOrders = sysSalesOrderMapper.selectSysSalesOrderListByCodeList(salesOrderCodes); + List sysSalesOrders = sysSalesOrderMapper.selectSysSalesOrderListByCodeList(salesOrderCodes); + List sysSalesOrderChildren = salesOrderChildMapper.selectBatchOrderChildListBySalesOrderCode(salesOrderCodes); + + //创建映射,用于快速查找每个销售订单号对应的子表数据 + Map> orderCodeToChildrenMap = sysSalesOrderChildren.stream().collect(Collectors.groupingBy(SysSalesOrderChild::getQuoteId)); + + + //遍历每个销售订单主表的数据 + for (SysSalesOrder sysSalesOrder : sysSalesOrders) { + String orderCode = sysSalesOrder.getSalesOrderCode(); + List childrenList = orderCodeToChildrenMap.get(orderCode); + + if (!CollectionUtils.isEmpty(childrenList)){ + + //检查子表数据的所有订单数量和已验收数量是否相等 + boolean allNumbersEqual = childrenList.stream() + .allMatch(child -> Objects.equals(child.getMaterialNum(), child.getHasCheckNum())); + if (allNumbersEqual){ + sysSalesOrder.setDeliveryStatus("8"); + }else { + sysSalesOrder.setDeliveryStatus("7"); + } + }else { + sysSalesOrder.setDeliveryStatus("7"); + } + + sysSalesOrder.setUpdateTime(new Date()); + sysSalesOrder.setUpdateBy(loginName); + int updateSysSalesOrderResult = sysSalesOrderMapper.updateSysSalesOrderBySalesOrderCode(sysSalesOrder); + if (updateSysSalesOrderResult <= 0){ + throw new BusinessException("更新销售订单数据失败"); + } + } + //设置为全部验收 if (allWithoutCheckFlag == 1 && allWithCheckFlag == 1){ @@ -718,9 +755,10 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService } - private Integer processWithoutShippingDeviceId(List withoutShippingDeviceIdList,Integer allWithoutCheckFlag) { + private Integer processWithoutShippingDeviceId(List withoutShippingDeviceIdList,Integer allWithoutCheckFlag,SysSalesShippingInform sysSalesShippingInform) { + String loginName = ShiroUtils.getLoginName(); for (SysSalesShippingInformDetail sysSalesShippingInformDetail : withoutShippingDeviceIdList) { Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); @@ -736,10 +774,50 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService throw new BusinessException("已验收数和本次验收数之和不能大于已收货数"); } sysSalesShippingInformDetail.setThisCheckNum(null); - + sysSalesShippingInformDetail.setUpdateTime(new Date()); + sysSalesShippingInformDetail.setUpdateBy(loginName); if (Objects.equals(tempShippingInformDetail.getThisShippingNum(), sysSalesShippingInformDetail.getHasCheckNum())){ allWithoutCheckFlag = 1; } + // 当前时间 + 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 数据 + for (SysSalesOrderChild orderChild : orderChildren) { + orderChild.setUpdateTime(new Date()); + orderChild.setUpdateBy(loginName); + orderChild.setHasCheckNum(sysSalesShippingInformDetail.getHasCheckNum()); + int updateSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(orderChild); + if (updateSalesOrderChildResult <= 0) { + throw new BusinessException("更新销售订单子表数据失败"); + } + } + int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(sysSalesShippingInformDetail); if (updateShippingInformDetailResult <= 0) { @@ -749,7 +827,7 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService return allWithoutCheckFlag; } - private Integer processWithShippingDeviceId(List withShippingDeviceIdList,Integer allWithCheckFlag) { + private Integer processWithShippingDeviceId(List withShippingDeviceIdList,Integer allWithCheckFlag,SysSalesShippingInform sysSalesShippingInform) { String loginName = ShiroUtils.getLoginName(); // List filterShippingDeviceIdList = withShippingDeviceIdList.stream() @@ -795,6 +873,65 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService 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 数据 + for (SysSalesOrderChild orderChild : orderChildren) { + orderChild.setUpdateTime(new Date()); + orderChild.setUpdateBy(loginName); + orderChild.setHasCheckNum(sysSalesShippingInformDetail.getHasCheckNum()); + int updateSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(orderChild); + if (updateSalesOrderChildResult <= 0) { + throw new BusinessException("更新销售订单子表数据失败"); + } + } + int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(tempShippingInformDetail); if (updateShippingInformDetailResult <= 0) { throw new BusinessException("更新销售出货通知单详情数据失败");