From 120f9933f4b7913ded0863d5943a52e03ed96294 Mon Sep 17 00:00:00 2001 From: ljl Date: Mon, 27 Nov 2023 10:11:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DsMessageServiceImpl.java | 60 +++++++++++++------ .../mapper/RefundPurchaseOrderSkuMapper.java | 3 + .../mapper/RefundPurchaseOrderSkuMapper.xml | 14 +++++ 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/ms-biz/src/main/java/com/ms/biz/service/impl/DsMessageServiceImpl.java b/ms-biz/src/main/java/com/ms/biz/service/impl/DsMessageServiceImpl.java index 2c338a7..e98058c 100644 --- a/ms-biz/src/main/java/com/ms/biz/service/impl/DsMessageServiceImpl.java +++ b/ms-biz/src/main/java/com/ms/biz/service/impl/DsMessageServiceImpl.java @@ -382,6 +382,23 @@ public class DsMessageServiceImpl implements DsMessageService { DDApi.supplyCenterOrderCancel(param); } + private Map getSkuItemIdAndPurSkuOrderIdMap(PurchaseOrderDTO purchaseOrderDTO, PurchaseOrder purchaseOrder) { + Map skuIdAndPurSkuOrderIdMap = new HashMap<>(); + List skus = platformPurchaseOrderSkuMapper.getListByPurOrderIds(Collections.singletonList(purchaseOrder.getPurOrderId())); + for (PlatformPurchaseOrderSku sku: skus) { + skuIdAndPurSkuOrderIdMap.put(String.valueOf(sku.getSkuId()), sku.getPurSkuOrderId()); + } + Map skuItemIdAndPurSkuOrderIdMap = new HashMap<>(); + for (PurchaseOrderItemDTO itemDTO: purchaseOrderDTO.getItems()) { + if (!skuIdAndPurSkuOrderIdMap.containsKey(itemDTO.getSkuId().toString())) { + log.info("purSkuOrderId unFound skuId: " + itemDTO.getSkuId() + "skuIdAndPurSkuOrderIdMap: " + skuIdAndPurSkuOrderIdMap); + continue; + } + skuItemIdAndPurSkuOrderIdMap.put(itemDTO.getSubItemId(), skuIdAndPurSkuOrderIdMap.get(itemDTO.getSkuId().toString())); + } + return skuItemIdAndPurSkuOrderIdMap; + } + private void handlePurchaseOrderRefund(PurchaseOrderDTO purchaseOrderDTO, PurchaseOrder purchaseOrder, AlibabaMessage alibabaMessage) { if (alibabaMessage == null || purchaseOrderDTO.getRefundInfo() == null || purchaseOrderDTO.getRefundInfo().isEmpty()) { return; @@ -392,17 +409,9 @@ public class DsMessageServiceImpl implements DsMessageService { throw new RuntimeException("未找到售后信息"); } - saveRefundPurchaseOrder(refundInfo, purchaseOrder); + Map skuItemIdAndPurSkuOrderIdMap = getSkuItemIdAndPurSkuOrderIdMap(purchaseOrderDTO, purchaseOrder); - Map subItemIdAndSkuIdMap = new HashMap<>(); - for (PurchaseOrderItemDTO itemDTO: purchaseOrderDTO.getItems()) { - subItemIdAndSkuIdMap.put(itemDTO.getSubItemId(), itemDTO.getSkuId()); - } - Map skuIdAndPurSkuOrderIdMap = new HashMap<>(); - List skus = platformPurchaseOrderSkuMapper.getListByPurOrderIds(Collections.singletonList(purchaseOrder.getPurOrderId())); - for (PlatformPurchaseOrderSku sku: skus) { - skuIdAndPurSkuOrderIdMap.put(String.valueOf(sku.getSkuId()), sku.getPurSkuOrderId()); - } + saveRefundPurchaseOrder(refundInfo, purchaseOrder, skuItemIdAndPurSkuOrderIdMap); SupplyCenterRefundOperateParam param = new SupplyCenterRefundOperateParam(); param.setPurOrderId(purchaseOrder.getPurOrderId()); @@ -410,16 +419,11 @@ public class DsMessageServiceImpl implements DsMessageService { List skuRefundInfosItems = new ArrayList<>(); Set subItemIds = refundInfo.getOrderEntryCountMap().keySet(); for (String subItemId: subItemIds) { - if (!subItemIdAndSkuIdMap.containsKey(subItemId)) { - log.info("sku unFound, subItemId: " + subItemId + "subItemIdAndSkuIdMap: " + subItemIdAndSkuIdMap); - continue; - } - Long skuId = subItemIdAndSkuIdMap.get(subItemId); - if (!skuIdAndPurSkuOrderIdMap.containsKey(String.valueOf(skuId))) { - log.info("purSkuOrderId unFound skuId: " + skuId + "skuIdAndPurSkuOrderIdMap: " + skuIdAndPurSkuOrderIdMap); + if (!skuItemIdAndPurSkuOrderIdMap.containsKey(subItemId)) { + log.info("purSkuOrderId unFound subItemId: " + subItemId + "skuItemIdAndPurSkuOrderIdMap: " + skuItemIdAndPurSkuOrderIdMap); continue; } - String purSkuOrderId = skuIdAndPurSkuOrderIdMap.get(String.valueOf(skuId)); + String purSkuOrderId = skuItemIdAndPurSkuOrderIdMap.get(subItemId); SkuRefundInfosItem skuRefundInfosItem = buildSkuRefundInfosItem(purSkuOrderId, refundInfo, alibabaMessage); skuRefundInfosItems.add(skuRefundInfosItem); } @@ -427,11 +431,26 @@ public class DsMessageServiceImpl implements DsMessageService { DDApi.supplyCenterRefundOperate(param); } - private void saveRefundPurchaseOrder(RefundInfoDTO refundInfo, PurchaseOrder purchaseOrder) { + private void saveRefundPurchaseOrder(RefundInfoDTO refundInfo, PurchaseOrder purchaseOrder, Map skuItemIdAndPurSkuOrderIdMap) { RefundPurchaseOrder refundPurchaseOrder = refundPurchaseOrderMapper.getByRefundId(refundInfo.getRefundId()); + List refundPurchaseOrderSkus = new ArrayList<>(); if (refundPurchaseOrder == null) { refundPurchaseOrder = new RefundPurchaseOrder(); refundPurchaseOrder.setGmtCreate(new Date()); + for (Map.Entry entry: refundInfo.getOrderEntryCountMap().entrySet()) { + String purSkuOrderId = skuItemIdAndPurSkuOrderIdMap.get(entry.getKey()); + RefundPurchaseOrderSku refundPurchaseOrderSku = new RefundPurchaseOrderSku(); + refundPurchaseOrder.setShopId(purchaseOrder.getShopId()); + refundPurchaseOrderSku.setOrderId(String.valueOf(purchaseOrder.getOrderId())); + refundPurchaseOrderSku.setPurOrderId(purchaseOrder.getPurOrderId()); + refundPurchaseOrderSku.setRefundId(refundInfo.getRefundId()); + refundPurchaseOrderSku.setSubItemId(entry.getKey()); + refundPurchaseOrderSku.setPurSkuOrderId(purSkuOrderId); + refundPurchaseOrderSku.setNum(entry.getValue()); + refundPurchaseOrderSku.setGmtCreate(new Date()); + refundPurchaseOrderSku.setGmtModified(new Date()); + refundPurchaseOrderSkus.add(refundPurchaseOrderSku); + } } refundPurchaseOrder.setOrderId(String.valueOf(purchaseOrder.getOrderId())); refundPurchaseOrder.setPurOrderId(purchaseOrder.getPurOrderId()); @@ -454,6 +473,9 @@ public class DsMessageServiceImpl implements DsMessageService { } else { refundPurchaseOrderMapper.updateByPrimaryKeySelective(refundPurchaseOrder); } + if (!refundPurchaseOrderSkus.isEmpty()) { + refundPurchaseOrderSkuMapper.insertBatch(refundPurchaseOrderSkus); + } } private SkuRefundInfosItem buildSkuRefundInfosItem(String purSkuOrderId, RefundInfoDTO refundInfo, AlibabaMessage alibabaMessage) { diff --git a/ms-dal/src/main/java/com/ms/dal/mapper/RefundPurchaseOrderSkuMapper.java b/ms-dal/src/main/java/com/ms/dal/mapper/RefundPurchaseOrderSkuMapper.java index 8e138e0..4e60520 100644 --- a/ms-dal/src/main/java/com/ms/dal/mapper/RefundPurchaseOrderSkuMapper.java +++ b/ms-dal/src/main/java/com/ms/dal/mapper/RefundPurchaseOrderSkuMapper.java @@ -3,6 +3,8 @@ package com.ms.dal.mapper; import com.ms.dal.entity.RefundPurchaseOrderSku; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * @Entity com.ms.dal.entity.RefundPurchaseOrderSku */ @@ -23,4 +25,5 @@ public interface RefundPurchaseOrderSkuMapper { int updateByPrimaryKey(RefundPurchaseOrderSku record); + int insertBatch(List records); } diff --git a/ms-dal/src/main/resources/mapper/RefundPurchaseOrderSkuMapper.xml b/ms-dal/src/main/resources/mapper/RefundPurchaseOrderSkuMapper.xml index fe8724f..284227d 100644 --- a/ms-dal/src/main/resources/mapper/RefundPurchaseOrderSkuMapper.xml +++ b/ms-dal/src/main/resources/mapper/RefundPurchaseOrderSkuMapper.xml @@ -178,4 +178,18 @@ gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} where refund_purchase_order_sku_id = #{refundPurchaseOrderSkuId,jdbcType=BIGINT} + + insert into refund_purchase_order_sku + ( refund_purchase_order_sku_id,refund_id,shop_id + ,pur_order_id,pur_sku_order_id,order_id + ,sub_item_id,num,gmt_create + ,gmt_modified) + values + + (#{item.refundPurchaseOrderSkuId,jdbcType=BIGINT},#{item.refundId,jdbcType=VARCHAR},#{item.shopId,jdbcType=BIGINT} + ,#{item.purOrderId,jdbcType=VARCHAR},#{item.purSkuOrderId,jdbcType=VARCHAR},#{item.orderId,jdbcType=VARCHAR} + ,#{item.subItemId,jdbcType=VARCHAR},#{item.num,jdbcType=INTEGER},#{item.gmtCreate,jdbcType=TIMESTAMP} + ,#{item.gmtModified,jdbcType=TIMESTAMP}) + +