|
|
|
@ -382,6 +382,23 @@ public class DsMessageServiceImpl implements DsMessageService {
|
|
|
|
|
DDApi.supplyCenterOrderCancel(param);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, String> getSkuItemIdAndPurSkuOrderIdMap(PurchaseOrderDTO purchaseOrderDTO, PurchaseOrder purchaseOrder) {
|
|
|
|
|
Map<String, String> skuIdAndPurSkuOrderIdMap = new HashMap<>();
|
|
|
|
|
List<PlatformPurchaseOrderSku> skus = platformPurchaseOrderSkuMapper.getListByPurOrderIds(Collections.singletonList(purchaseOrder.getPurOrderId()));
|
|
|
|
|
for (PlatformPurchaseOrderSku sku: skus) {
|
|
|
|
|
skuIdAndPurSkuOrderIdMap.put(String.valueOf(sku.getSkuId()), sku.getPurSkuOrderId());
|
|
|
|
|
}
|
|
|
|
|
Map<String, String> 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<String, String> skuItemIdAndPurSkuOrderIdMap = getSkuItemIdAndPurSkuOrderIdMap(purchaseOrderDTO, purchaseOrder);
|
|
|
|
|
|
|
|
|
|
Map<String, Long> subItemIdAndSkuIdMap = new HashMap<>();
|
|
|
|
|
for (PurchaseOrderItemDTO itemDTO: purchaseOrderDTO.getItems()) {
|
|
|
|
|
subItemIdAndSkuIdMap.put(itemDTO.getSubItemId(), itemDTO.getSkuId());
|
|
|
|
|
}
|
|
|
|
|
Map<String, String> skuIdAndPurSkuOrderIdMap = new HashMap<>();
|
|
|
|
|
List<PlatformPurchaseOrderSku> 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<SkuRefundInfosItem> skuRefundInfosItems = new ArrayList<>();
|
|
|
|
|
Set<String> 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<String, String> skuItemIdAndPurSkuOrderIdMap) {
|
|
|
|
|
RefundPurchaseOrder refundPurchaseOrder = refundPurchaseOrderMapper.getByRefundId(refundInfo.getRefundId());
|
|
|
|
|
List<RefundPurchaseOrderSku> refundPurchaseOrderSkus = new ArrayList<>();
|
|
|
|
|
if (refundPurchaseOrder == null) {
|
|
|
|
|
refundPurchaseOrder = new RefundPurchaseOrder();
|
|
|
|
|
refundPurchaseOrder.setGmtCreate(new Date());
|
|
|
|
|
for (Map.Entry<String, Integer> 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) {
|
|
|
|
|