20240115-ljl-multiPay
ljl 12 months ago
parent 804a410f0f
commit 120f9933f4

@ -382,6 +382,23 @@ public class DsMessageServiceImpl implements DsMessageService {
DDApi.supplyCenterOrderCancel(param); 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) { private void handlePurchaseOrderRefund(PurchaseOrderDTO purchaseOrderDTO, PurchaseOrder purchaseOrder, AlibabaMessage alibabaMessage) {
if (alibabaMessage == null || purchaseOrderDTO.getRefundInfo() == null || purchaseOrderDTO.getRefundInfo().isEmpty()) { if (alibabaMessage == null || purchaseOrderDTO.getRefundInfo() == null || purchaseOrderDTO.getRefundInfo().isEmpty()) {
return; return;
@ -392,17 +409,9 @@ public class DsMessageServiceImpl implements DsMessageService {
throw new RuntimeException("未找到售后信息"); throw new RuntimeException("未找到售后信息");
} }
saveRefundPurchaseOrder(refundInfo, purchaseOrder); Map<String, String> skuItemIdAndPurSkuOrderIdMap = getSkuItemIdAndPurSkuOrderIdMap(purchaseOrderDTO, purchaseOrder);
Map<String, Long> subItemIdAndSkuIdMap = new HashMap<>(); saveRefundPurchaseOrder(refundInfo, purchaseOrder, skuItemIdAndPurSkuOrderIdMap);
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());
}
SupplyCenterRefundOperateParam param = new SupplyCenterRefundOperateParam(); SupplyCenterRefundOperateParam param = new SupplyCenterRefundOperateParam();
param.setPurOrderId(purchaseOrder.getPurOrderId()); param.setPurOrderId(purchaseOrder.getPurOrderId());
@ -410,16 +419,11 @@ public class DsMessageServiceImpl implements DsMessageService {
List<SkuRefundInfosItem> skuRefundInfosItems = new ArrayList<>(); List<SkuRefundInfosItem> skuRefundInfosItems = new ArrayList<>();
Set<String> subItemIds = refundInfo.getOrderEntryCountMap().keySet(); Set<String> subItemIds = refundInfo.getOrderEntryCountMap().keySet();
for (String subItemId: subItemIds) { for (String subItemId: subItemIds) {
if (!subItemIdAndSkuIdMap.containsKey(subItemId)) { if (!skuItemIdAndPurSkuOrderIdMap.containsKey(subItemId)) {
log.info("sku unFound, subItemId: " + subItemId + "subItemIdAndSkuIdMap: " + subItemIdAndSkuIdMap); log.info("purSkuOrderId unFound subItemId: " + subItemId + "skuItemIdAndPurSkuOrderIdMap: " + skuItemIdAndPurSkuOrderIdMap);
continue;
}
Long skuId = subItemIdAndSkuIdMap.get(subItemId);
if (!skuIdAndPurSkuOrderIdMap.containsKey(String.valueOf(skuId))) {
log.info("purSkuOrderId unFound skuId: " + skuId + "skuIdAndPurSkuOrderIdMap: " + skuIdAndPurSkuOrderIdMap);
continue; continue;
} }
String purSkuOrderId = skuIdAndPurSkuOrderIdMap.get(String.valueOf(skuId)); String purSkuOrderId = skuItemIdAndPurSkuOrderIdMap.get(subItemId);
SkuRefundInfosItem skuRefundInfosItem = buildSkuRefundInfosItem(purSkuOrderId, refundInfo, alibabaMessage); SkuRefundInfosItem skuRefundInfosItem = buildSkuRefundInfosItem(purSkuOrderId, refundInfo, alibabaMessage);
skuRefundInfosItems.add(skuRefundInfosItem); skuRefundInfosItems.add(skuRefundInfosItem);
} }
@ -427,11 +431,26 @@ public class DsMessageServiceImpl implements DsMessageService {
DDApi.supplyCenterRefundOperate(param); 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()); RefundPurchaseOrder refundPurchaseOrder = refundPurchaseOrderMapper.getByRefundId(refundInfo.getRefundId());
List<RefundPurchaseOrderSku> refundPurchaseOrderSkus = new ArrayList<>();
if (refundPurchaseOrder == null) { if (refundPurchaseOrder == null) {
refundPurchaseOrder = new RefundPurchaseOrder(); refundPurchaseOrder = new RefundPurchaseOrder();
refundPurchaseOrder.setGmtCreate(new Date()); 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.setOrderId(String.valueOf(purchaseOrder.getOrderId()));
refundPurchaseOrder.setPurOrderId(purchaseOrder.getPurOrderId()); refundPurchaseOrder.setPurOrderId(purchaseOrder.getPurOrderId());
@ -454,6 +473,9 @@ public class DsMessageServiceImpl implements DsMessageService {
} else { } else {
refundPurchaseOrderMapper.updateByPrimaryKeySelective(refundPurchaseOrder); refundPurchaseOrderMapper.updateByPrimaryKeySelective(refundPurchaseOrder);
} }
if (!refundPurchaseOrderSkus.isEmpty()) {
refundPurchaseOrderSkuMapper.insertBatch(refundPurchaseOrderSkus);
}
} }
private SkuRefundInfosItem buildSkuRefundInfosItem(String purSkuOrderId, RefundInfoDTO refundInfo, AlibabaMessage alibabaMessage) { private SkuRefundInfosItem buildSkuRefundInfosItem(String purSkuOrderId, RefundInfoDTO refundInfo, AlibabaMessage alibabaMessage) {

@ -3,6 +3,8 @@ package com.ms.dal.mapper;
import com.ms.dal.entity.RefundPurchaseOrderSku; import com.ms.dal.entity.RefundPurchaseOrderSku;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/** /**
* @Entity com.ms.dal.entity.RefundPurchaseOrderSku * @Entity com.ms.dal.entity.RefundPurchaseOrderSku
*/ */
@ -23,4 +25,5 @@ public interface RefundPurchaseOrderSkuMapper {
int updateByPrimaryKey(RefundPurchaseOrderSku record); int updateByPrimaryKey(RefundPurchaseOrderSku record);
int insertBatch(List<RefundPurchaseOrderSku> records);
} }

@ -178,4 +178,18 @@
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where refund_purchase_order_sku_id = #{refundPurchaseOrderSkuId,jdbcType=BIGINT} where refund_purchase_order_sku_id = #{refundPurchaseOrderSkuId,jdbcType=BIGINT}
</update> </update>
<insert id="insertBatch" keyColumn="refund_purchase_order_sku_id" keyProperty="refundPurchaseOrderSkuId" useGeneratedKeys="true">
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
<foreach item="item" collection="list" separator="," >
(#{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})
</foreach>
</insert>
</mapper> </mapper>

Loading…
Cancel
Save