|
|
|
@ -1687,7 +1687,8 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancelPurchaseOrderRelateFromDs(OpOrder opOrder, List<PurchaseOrderCancelMessageDTO.Item> items, String source) {
|
|
|
|
|
|
|
|
|
|
cancelPurchaseOrderRelateFromMsgPush(opOrder, items, source);
|
|
|
|
|
buildAndUpdateNewPurchaseOrderRemark(opOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancelPurchaseOrderRelateFromMsgPush(OpOrder opOrder, List<PurchaseOrderCancelMessageDTO.Item> items, String source) {
|
|
|
|
@ -1700,9 +1701,77 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
List<PurchaseOrder> purchaseOrders = purchaseOrderService.getListByOrderId(opOrder.getShopId(), opOrder.getOrderId(), StatusConst.normal, true);
|
|
|
|
|
|
|
|
|
|
Map<String, List<PurchaseOrderCancelMessageDTO.Item>> sourceOrderIdAndPlatformOrderItemsMap = new HashMap<>();
|
|
|
|
|
for (PurchaseOrderCancelMessageDTO.Item item: items) {
|
|
|
|
|
List<PurchaseOrderCancelMessageDTO.Item> orderItems = new ArrayList<>();
|
|
|
|
|
if (sourceOrderIdAndPlatformOrderItemsMap.containsKey(item.getSourceOrderId())) {
|
|
|
|
|
orderItems = sourceOrderIdAndPlatformOrderItemsMap.get(item.getSourceOrderId());
|
|
|
|
|
}
|
|
|
|
|
orderItems.add(item);
|
|
|
|
|
sourceOrderIdAndPlatformOrderItemsMap.put(item.getSourceOrderId(), orderItems);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<PurchaseOrderCancelLog> purchaseOrderCancelLogs = new ArrayList<>();
|
|
|
|
|
List<Long> needCancelPurchaseOrderIds = new ArrayList<>();
|
|
|
|
|
List<Long> needCancelPurchaseOrderItemIds = new ArrayList<>();
|
|
|
|
|
for (PurchaseOrder purchaseOrder: purchaseOrders) {
|
|
|
|
|
|
|
|
|
|
List<PurchaseOrderCancelMessageDTO.Item> loopPlatformOrderItems = sourceOrderIdAndPlatformOrderItemsMap.get(purchaseOrder.getPurchaseOrderSn());
|
|
|
|
|
if (loopPlatformOrderItems == null || loopPlatformOrderItems.isEmpty()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!Objects.equals(purchaseOrder.getStatus(), StatusConst.normal)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Map<Long, PurchaseOrderCancelMessageDTO.Item> 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) {
|
|
|
|
|