From 7a01bdf1dedf855a0a30a03401fb6e29b5efa6ad Mon Sep 17 00:00:00 2001 From: elf <360197197@qq.com> Date: Thu, 7 Sep 2023 23:29:00 +0800 Subject: [PATCH] yh --- .../impl/DistributionOrderServiceImpl.java | 73 ++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/ms-biz/src/main/java/com/ms/api/service/impl/DistributionOrderServiceImpl.java b/ms-biz/src/main/java/com/ms/api/service/impl/DistributionOrderServiceImpl.java index 70773e6c..9a76745e 100644 --- a/ms-biz/src/main/java/com/ms/api/service/impl/DistributionOrderServiceImpl.java +++ b/ms-biz/src/main/java/com/ms/api/service/impl/DistributionOrderServiceImpl.java @@ -1687,7 +1687,8 @@ public class DistributionOrderServiceImpl implements DistributionOrderService { } private void cancelPurchaseOrderRelateFromDs(OpOrder opOrder, List items, String source) { - + cancelPurchaseOrderRelateFromMsgPush(opOrder, items, source); + buildAndUpdateNewPurchaseOrderRemark(opOrder); } private void cancelPurchaseOrderRelateFromMsgPush(OpOrder opOrder, List items, String source) { @@ -1700,9 +1701,77 @@ public class DistributionOrderServiceImpl implements DistributionOrderService { } } List purchaseOrders = purchaseOrderService.getListByOrderId(opOrder.getShopId(), opOrder.getOrderId(), StatusConst.normal, true); + + Map> sourceOrderIdAndPlatformOrderItemsMap = new HashMap<>(); + for (PurchaseOrderCancelMessageDTO.Item item: items) { + List orderItems = new ArrayList<>(); + if (sourceOrderIdAndPlatformOrderItemsMap.containsKey(item.getSourceOrderId())) { + orderItems = sourceOrderIdAndPlatformOrderItemsMap.get(item.getSourceOrderId()); + } + orderItems.add(item); + sourceOrderIdAndPlatformOrderItemsMap.put(item.getSourceOrderId(), orderItems); + } + + List purchaseOrderCancelLogs = new ArrayList<>(); + List needCancelPurchaseOrderIds = new ArrayList<>(); + List needCancelPurchaseOrderItemIds = new ArrayList<>(); for (PurchaseOrder purchaseOrder: purchaseOrders) { - + List loopPlatformOrderItems = sourceOrderIdAndPlatformOrderItemsMap.get(purchaseOrder.getPurchaseOrderSn()); + if (loopPlatformOrderItems == null || loopPlatformOrderItems.isEmpty()) { + continue; + } + if (!Objects.equals(purchaseOrder.getStatus(), StatusConst.normal)) { + continue; + } + Map platformSkuIdAndPlatformOrderItemMap = loopPlatformOrderItems.stream().collect(Collectors.toMap(PurchaseOrderCancelMessageDTO.Item::getPlatformSkuId, x -> x)); + int cancelPurchaseOrderItemCount = 0; + for (PurchaseOrderItem item: purchaseOrder.getItems()) { + if (item.getStatus().equals(StatusConst.normal)) { + cancelPurchaseOrderItemCount ++; + } + if (!platformSkuIdAndPlatformOrderItemMap.containsKey(item.getSkuId())) { + continue; + } + needCancelPurchaseOrderItemIds.add(item.getPurchaseOrderItemId()); + cancelPurchaseOrderItemCount ++; + } + if (cancelPurchaseOrderItemCount > 0) { + PurchaseOrderCancelLog log = new PurchaseOrderCancelLog(); + log.setShopId(opOrder.getShopId()); + log.setOrderId(opOrder.getOrderId()); + log.setPurchaseOrderId(purchaseOrder.getPurchaseOrderId()); + log.setPurchaseOrderSn(purchaseOrder.getPurchaseOrderSn()); + log.setSource(source); + log.setOperateShopId(0L); + log.setOperateIp(""); + log.setGmtCreate(new Date()); + log.setGmtModified(new Date()); + purchaseOrderCancelLogs.add(log); + } + + if (cancelPurchaseOrderItemCount == purchaseOrder.getItems().size()) { + needCancelPurchaseOrderIds.add(purchaseOrder.getPurchaseOrderId()); + } + } + + if (needCancelPurchaseOrderItemIds.isEmpty()) { + throw new RuntimeException("该商品没有关联外部订单"); + } + + // TODO 事务 + if (!needCancelPurchaseOrderIds.isEmpty()) { + purchaseOrderService.updateStatusByIds(StatusConst.cancel, needCancelPurchaseOrderIds); + } + purchaseOrderItemService.updateStatusByIds(StatusConst.cancel, needCancelPurchaseOrderItemIds); + + updateOpOrderFilterPurchaseStatus(opOrder.getOrderId(), null); + + if (!purchaseOrderCancelLogs.isEmpty()) { + for (PurchaseOrderCancelLog log: purchaseOrderCancelLogs) { + purchaseOrderCancelLogService.insertSelective(log); + } } + updateOpOrderDsFilterStatus(opOrder.getOrderId(), "1688DS"); } private void dsUpdatePurchaseOrder(OpOrder opOrder, PurchaseOrderDTO dto) {