|
|
|
@ -27,6 +27,7 @@ import org.springframework.transaction.TransactionDefinition;
|
|
|
|
|
import org.springframework.transaction.TransactionStatus;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.regex.MatchResult;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
@ -916,71 +917,77 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
|
|
|
|
|
HashMap<Long, Integer> purchaseNumMap = buildPurchaseOrderItemsPurchaseNum(skuIdAndOpOrderChildMap, needRebuildSkuIds, realPurchaseNumMap);
|
|
|
|
|
HashMap<Long, Double> purchasePriceMap = buildPurchaseOrderItemsPurchasePrice(skuIdAndOpOrderChildMap, needRebuildSkuIds, (double) 0, purchaseNumMap);
|
|
|
|
|
|
|
|
|
|
PurchaseOrder purchaseOrder = buildPurchaseOrderByDto(purchaseOrderDto, oldPurchaseOrder, opOrder);
|
|
|
|
|
log.info("savePurchaseOrderInfoSavePurchaseOrder" + purchaseOrder);
|
|
|
|
|
if (purchaseOrder.getPurchaseOrderId() != null && purchaseOrder.getPurchaseOrderId() > 0) {
|
|
|
|
|
purchaseOrderService.updateByPrimaryKeySelective(purchaseOrder);
|
|
|
|
|
} else {
|
|
|
|
|
purchaseOrderService.insertSelective(purchaseOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!purchaseOrderDto.getPurchaseOrderFlow().isEmpty()) {
|
|
|
|
|
purchaseOrderTagService.save(purchaseOrder, PurchaseOrderTagConst.FLOW, purchaseOrderDto.getPurchaseOrderFlow());
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(purchaseOrderDto.getNotFirst1688OrderType(), "normal") || Objects.equals(purchaseOrderDto.getNotFirst1688OrderType(), "force")) {
|
|
|
|
|
purchaseOrderTagService.save(purchaseOrder, PurchaseOrderTagConst.NOT_FIRST1688_ORDER_TYPE, purchaseOrderDto.getNotFirst1688OrderType());
|
|
|
|
|
}
|
|
|
|
|
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
|
|
|
|
try {
|
|
|
|
|
PurchaseOrder purchaseOrder = buildPurchaseOrderByDto(purchaseOrderDto, oldPurchaseOrder, opOrder);
|
|
|
|
|
log.info("savePurchaseOrderInfoSavePurchaseOrder" + purchaseOrder);
|
|
|
|
|
if (purchaseOrder.getPurchaseOrderId() != null && purchaseOrder.getPurchaseOrderId() > 0) {
|
|
|
|
|
purchaseOrderService.updateByPrimaryKeySelective(purchaseOrder);
|
|
|
|
|
} else {
|
|
|
|
|
purchaseOrderService.insertSelective(purchaseOrder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (purchaseOrderDto.getIsDsEncryptOrder() >= 1) {
|
|
|
|
|
PurchaseOrderDsEncrypt log = buildPurchaseOrderDsEncrypt(purchaseOrderDto, opOrder);
|
|
|
|
|
purchaseOrderDsEncryptService.insertSelective(log);
|
|
|
|
|
}
|
|
|
|
|
if (!purchaseOrderDto.getPurchaseOrderFlow().isEmpty()) {
|
|
|
|
|
purchaseOrderTagService.save(purchaseOrder, PurchaseOrderTagConst.FLOW, purchaseOrderDto.getPurchaseOrderFlow());
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(purchaseOrderDto.getNotFirst1688OrderType(), "normal") || Objects.equals(purchaseOrderDto.getNotFirst1688OrderType(), "force")) {
|
|
|
|
|
purchaseOrderTagService.save(purchaseOrder, PurchaseOrderTagConst.NOT_FIRST1688_ORDER_TYPE, purchaseOrderDto.getNotFirst1688OrderType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<Long, PurchaseOrderItemDTO> skuIdAndItemMap = purchaseOrderDto.getSkuIdAndItemMap();
|
|
|
|
|
System.out.println("needRebuildSkuIds" + needRebuildSkuIds);
|
|
|
|
|
for (Long skuId: needRebuildSkuIds) {
|
|
|
|
|
OpOrderChild opOrderChild = skuIdAndOpOrderChildMap.get(skuId);
|
|
|
|
|
PurchaseOrderItem oldPurchaseOrderitem = oldPurchaseOrderItemMap.get(skuId);
|
|
|
|
|
PurchaseOrderItemDTO newPurchaseOrderItem = skuIdAndItemMap.get(skuId);
|
|
|
|
|
String purchaseUrl = newPurchaseOrderItem.getPurchaseUrl();
|
|
|
|
|
Integer purchaseNum = purchaseNumMap.get(skuId);
|
|
|
|
|
Double purchasePrice = purchasePriceMap.get(skuId);
|
|
|
|
|
if (oldPurchaseOrderitem != null) {
|
|
|
|
|
purchaseUrl = StringUtils.isBlank(oldPurchaseOrderitem.getPurchaseUrl()) ? oldPurchaseOrderitem.getPurchaseUrl() : purchaseUrl;
|
|
|
|
|
purchaseNum = purchaseNum != null ? purchaseNum : oldPurchaseOrderitem.getPurchaseNum();
|
|
|
|
|
purchasePrice = purchasePrice != null ? purchasePrice : oldPurchaseOrderitem.getPurchasePrice().doubleValue();
|
|
|
|
|
if (purchaseOrderDto.getIsDsEncryptOrder() >= 1) {
|
|
|
|
|
PurchaseOrderDsEncrypt log = buildPurchaseOrderDsEncrypt(purchaseOrderDto, opOrder);
|
|
|
|
|
purchaseOrderDsEncryptService.insertSelective(log);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PurchaseOrderItem purchaseOrderItem = new PurchaseOrderItem();
|
|
|
|
|
purchaseOrderItem.setPurchaseOrderId(purchaseOrder.getPurchaseOrderId().intValue());
|
|
|
|
|
purchaseOrderItem.setOrderId(purchaseOrder.getOrderId());
|
|
|
|
|
purchaseOrderItem.setShopId(purchaseOrder.getShopId());
|
|
|
|
|
purchaseOrderItem.setWareId(opOrderChild.getProductId());
|
|
|
|
|
purchaseOrderItem.setSkuId(skuId);
|
|
|
|
|
purchaseOrderItem.setStatus(StatusConst.normal);
|
|
|
|
|
purchaseOrderItem.setPurchaseUrl(purchaseUrl);
|
|
|
|
|
purchaseOrderItem.setPurchaseNum(purchaseNum);
|
|
|
|
|
purchaseOrderItem.setPurchasePrice(BigDecimal.valueOf(purchasePrice));
|
|
|
|
|
purchaseOrderItem.setRealPurchaseUrl(newPurchaseOrderItem.getRealPurchaseUrl());
|
|
|
|
|
purchaseOrderItem.setGmtModified(new Date());
|
|
|
|
|
purchaseOrderItem.setPurchasePlatform(purchaseOrderDto.getPurchasePlatform());
|
|
|
|
|
if (oldPurchaseOrderitem != null) {
|
|
|
|
|
purchaseOrderItemService.updateByPrimaryKeySelective(purchaseOrderItem);
|
|
|
|
|
} else {
|
|
|
|
|
purchaseOrderItemService.insertSelective(purchaseOrderItem);
|
|
|
|
|
Map<Long, PurchaseOrderItemDTO> skuIdAndItemMap = purchaseOrderDto.getSkuIdAndItemMap();
|
|
|
|
|
System.out.println("needRebuildSkuIds" + needRebuildSkuIds);
|
|
|
|
|
for (Long skuId: needRebuildSkuIds) {
|
|
|
|
|
OpOrderChild opOrderChild = skuIdAndOpOrderChildMap.get(skuId);
|
|
|
|
|
PurchaseOrderItem oldPurchaseOrderitem = oldPurchaseOrderItemMap.get(skuId);
|
|
|
|
|
PurchaseOrderItemDTO newPurchaseOrderItem = skuIdAndItemMap.get(skuId);
|
|
|
|
|
String purchaseUrl = newPurchaseOrderItem.getPurchaseUrl();
|
|
|
|
|
Integer purchaseNum = purchaseNumMap.get(skuId);
|
|
|
|
|
Double purchasePrice = purchasePriceMap.get(skuId);
|
|
|
|
|
if (oldPurchaseOrderitem != null) {
|
|
|
|
|
purchaseUrl = StringUtils.isBlank(oldPurchaseOrderitem.getPurchaseUrl()) ? oldPurchaseOrderitem.getPurchaseUrl() : purchaseUrl;
|
|
|
|
|
purchaseNum = purchaseNum != null ? purchaseNum : oldPurchaseOrderitem.getPurchaseNum();
|
|
|
|
|
purchasePrice = purchasePrice != null ? purchasePrice : oldPurchaseOrderitem.getPurchasePrice().doubleValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PurchaseOrderItem purchaseOrderItem = new PurchaseOrderItem();
|
|
|
|
|
purchaseOrderItem.setPurchaseOrderId(purchaseOrder.getPurchaseOrderId().intValue());
|
|
|
|
|
purchaseOrderItem.setOrderId(purchaseOrder.getOrderId());
|
|
|
|
|
purchaseOrderItem.setShopId(purchaseOrder.getShopId());
|
|
|
|
|
purchaseOrderItem.setWareId(opOrderChild.getProductId());
|
|
|
|
|
purchaseOrderItem.setSkuId(skuId);
|
|
|
|
|
purchaseOrderItem.setStatus(StatusConst.normal);
|
|
|
|
|
purchaseOrderItem.setPurchaseUrl(purchaseUrl);
|
|
|
|
|
purchaseOrderItem.setPurchaseNum(purchaseNum);
|
|
|
|
|
purchaseOrderItem.setPurchasePrice(BigDecimal.valueOf(purchasePrice));
|
|
|
|
|
purchaseOrderItem.setRealPurchaseUrl(newPurchaseOrderItem.getRealPurchaseUrl());
|
|
|
|
|
purchaseOrderItem.setGmtModified(new Date());
|
|
|
|
|
purchaseOrderItem.setPurchasePlatform(purchaseOrderDto.getPurchasePlatform());
|
|
|
|
|
if (oldPurchaseOrderitem != null) {
|
|
|
|
|
purchaseOrderItemService.updateByPrimaryKeySelective(purchaseOrderItem);
|
|
|
|
|
} else {
|
|
|
|
|
purchaseOrderItemService.insertSelective(purchaseOrderItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!needCancelPurchaseOrderIds.isEmpty()) {
|
|
|
|
|
purchaseOrderService.updateStatusByIds(StatusConst.cancel, needCancelPurchaseOrderIds);
|
|
|
|
|
purchaseOrderItemService.updateStatusByPurchaseIds(StatusConst.cancel, needCancelPurchaseOrderIds);
|
|
|
|
|
}
|
|
|
|
|
if (!needCancelPurchaseOrderItemIds.isEmpty()) {
|
|
|
|
|
purchaseOrderItemService.updateStatusByIds(StatusConst.cancel, needCancelPurchaseOrderItemIds);
|
|
|
|
|
}
|
|
|
|
|
if (!purchaseOrderCancelLogs.isEmpty()) {
|
|
|
|
|
for (PurchaseOrderCancelLog log: purchaseOrderCancelLogs) {
|
|
|
|
|
purchaseOrderCancelLogService.insertSelective(log);
|
|
|
|
|
if (!needCancelPurchaseOrderIds.isEmpty()) {
|
|
|
|
|
purchaseOrderService.updateStatusByIds(StatusConst.cancel, needCancelPurchaseOrderIds);
|
|
|
|
|
purchaseOrderItemService.updateStatusByPurchaseIds(StatusConst.cancel, needCancelPurchaseOrderIds);
|
|
|
|
|
}
|
|
|
|
|
if (!needCancelPurchaseOrderItemIds.isEmpty()) {
|
|
|
|
|
purchaseOrderItemService.updateStatusByIds(StatusConst.cancel, needCancelPurchaseOrderItemIds);
|
|
|
|
|
}
|
|
|
|
|
if (!purchaseOrderCancelLogs.isEmpty()) {
|
|
|
|
|
for (PurchaseOrderCancelLog log: purchaseOrderCancelLogs) {
|
|
|
|
|
purchaseOrderCancelLogService.insertSelective(log);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dataSourceTransactionManager.commit(transactionStatus);
|
|
|
|
|
} catch (Throwable e) {
|
|
|
|
|
dataSourceTransactionManager.rollback(transactionStatus);
|
|
|
|
|
}
|
|
|
|
|
updateOpOrderFilterPurchaseStatus(opOrder.getOrderId(), null);
|
|
|
|
|
opOrderDsService.updateOpOrderDsFilterStatus(opOrder.getOrderId(), purchaseOrderDto.getPurchasePlatform());
|
|
|
|
@ -1007,11 +1014,17 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
|
|
|
|
|
|
|
|
|
|
Date purchaseOrderSendTime = null;
|
|
|
|
|
Date purchaseOrderStartTime = null;
|
|
|
|
|
if (StringUtils.isNotBlank(purchaseOrderDto.getPurchaseOrderStartTime())) {
|
|
|
|
|
purchaseOrderStartTime = DateUtils.parseDate(purchaseOrderDto.getPurchaseOrderStartTime(), new String[]{"yyyy-MM-dd HH:mm:ss"});
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(purchaseOrderDto.getPurchaseOrderSendTime())) {
|
|
|
|
|
purchaseOrderSendTime = DateUtils.parseDate(purchaseOrderDto.getPurchaseOrderSendTime(), new String[]{"yyyy-MM-dd HH:mm:ss"});
|
|
|
|
|
System.out.println("purchaseOrderDto: " + purchaseOrderDto);
|
|
|
|
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
try {
|
|
|
|
|
if (StringUtils.isNotBlank(purchaseOrderDto.getPurchaseOrderStartTime())) {
|
|
|
|
|
purchaseOrderStartTime = dateFormat.parse(purchaseOrderDto.getPurchaseOrderStartTime());
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotBlank(purchaseOrderDto.getPurchaseOrderSendTime())) {
|
|
|
|
|
purchaseOrderSendTime = dateFormat.parse(purchaseOrderDto.getPurchaseOrderSendTime());
|
|
|
|
|
}
|
|
|
|
|
} catch (java.text.ParseException e) {
|
|
|
|
|
throw new RuntimeException("时间格式错误");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String purchaseStatus = purchaseOrderDto.getPurchaseOrderStatus();
|
|
|
|
|