|
|
|
@ -2,6 +2,7 @@ package com.ms.api.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.doudian.open.api.order_logisticsAddMultiPack.OrderLogisticsAddMultiPackRequest;
|
|
|
|
@ -28,6 +29,7 @@ import com.ms.dal.entity.*;
|
|
|
|
|
import com.ms.dal.mapper.OpOrderChildAfterSaleMapper;
|
|
|
|
|
import com.ms.dal.mapper.OpOrderMapper;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
@ -39,6 +41,7 @@ import java.util.stream.Stream;
|
|
|
|
|
* @author elf
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
@AllArgsConstructor
|
|
|
|
|
public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
private OpOrderMapper opOrderMapper;
|
|
|
|
@ -100,6 +103,7 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
try {
|
|
|
|
|
checkCanOutStorage(Collections.singletonList(orderId), packageList);
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
|
log.error("checkCanOutStorage", e);
|
|
|
|
|
return ResultDTO.fail(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -128,6 +132,7 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
|
|
|
|
|
request.setParam(param);
|
|
|
|
|
OrderLogisticsAddMultiPackResponse response = request.execute();
|
|
|
|
|
log.error("OrderLogisticsAddMultiPackResponse: " + response);
|
|
|
|
|
if (!response.isSuccess()) {
|
|
|
|
|
throw new RuntimeException(response.getSubMsg());
|
|
|
|
|
}
|
|
|
|
@ -147,7 +152,7 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<String> invalidStatusOrderIds = orderList.stream()
|
|
|
|
|
.filter(e -> (OrderConst.ORDER_STATUS_WAIT_SELLER_SEND_GOODS.equals(e.getOrderStatus()) || OrderConst.ORDER_STATUS_PART_DELIVERY.equals(e.getOrderStatus())))
|
|
|
|
|
.filter(e -> (!OrderConst.ORDER_STATUS_WAIT_SELLER_SEND_GOODS.equals(e.getOrderStatus()) && !OrderConst.ORDER_STATUS_PART_DELIVERY.equals(e.getOrderStatus())))
|
|
|
|
|
.map(OpOrder::getOrderId).collect(Collectors.toList());
|
|
|
|
|
if (CollectionUtil.isNotEmpty(invalidStatusOrderIds)) {
|
|
|
|
|
throw new RuntimeException(String.format("订单:%s 当前状态不能进行发货操作", invalidStatusOrderIds));
|
|
|
|
@ -233,6 +238,11 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
@Override
|
|
|
|
|
public void dsPurchaseAutoOutStorage(ShopBO shopBO, OpOrder opOrder, PurchaseOrder purchaseOrder) {
|
|
|
|
|
DsPurchaseSetting dsPurchaseSetting = dsPurchaseSettingService.getShopSetting(opOrder.getShopId());
|
|
|
|
|
if (purchaseOrder.getItems() == null) {
|
|
|
|
|
List<PurchaseOrderItem> items = purchaseOrderItemService.getRelatePurchaseOrderItemsByPurchaseOrderId(purchaseOrder.getPurchaseOrderId());
|
|
|
|
|
purchaseOrder.setItems(items);
|
|
|
|
|
}
|
|
|
|
|
log.info("getOrderStatus: " + opOrder.getOrderStatus());
|
|
|
|
|
if (opOrder.getOrderStatus().equals(OrderConst.ORDER_STATUS_WAIT_SELLER_SEND_GOODS)) {
|
|
|
|
|
dsOrderOutStorage(shopBO, opOrder, purchaseOrder, dsPurchaseSetting);
|
|
|
|
|
} else if (opOrder.getOrderStatus().equals(OrderConst.ORDER_STATUS_WAIT_BUYER_CONFIRM_GOODS) || opOrder.getOrderStatus().equals(OrderConst.ORDER_STATUS_PART_DELIVERY)) {
|
|
|
|
@ -243,6 +253,7 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dsOrderOutStorage(ShopBO shopBO, OpOrder opOrder, PurchaseOrder purchaseOrder, DsPurchaseSetting dsPurchaseSetting) {
|
|
|
|
|
log.info("dsOrderOutStorage begin");
|
|
|
|
|
Long nearExpShipTime;
|
|
|
|
|
try {
|
|
|
|
|
nearExpShipTime = checkDsPurchaseAutoOutStorage(opOrder, purchaseOrder, dsPurchaseSetting);
|
|
|
|
@ -257,7 +268,9 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
List<PurchaseOrder> purchaseOrders = new ArrayList<>();
|
|
|
|
|
purchaseOrders.add(purchaseOrder);
|
|
|
|
|
OrderPackageInfoDTO orderPackageInfoDTO = packOrderDeliveryInfos(opOrder, purchaseOrders, isShipAfterLogisticsAccept, false, false);
|
|
|
|
|
log.info("dsOrderOutStorage[orderPackageInfoDTO]: " + orderPackageInfoDTO);
|
|
|
|
|
ResultDTO result = orderMultiPackageOutstorage(shopBO, opOrder, orderPackageInfoDTO.getPackageList(), LogisticsConst.outstorageSourceDsAuto);
|
|
|
|
|
log.info("dsOrderOutStorage[result]: " + result);
|
|
|
|
|
if (result.isSuccess()) {
|
|
|
|
|
opOrderDsService.updateOpOrderDsOrderStatus(opOrder);
|
|
|
|
|
}
|
|
|
|
@ -290,6 +303,7 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
List<PurchaseOrder> purchaseOrders = new ArrayList<>();
|
|
|
|
|
purchaseOrders.add(purchaseOrder);
|
|
|
|
|
OrderPackageInfoDTO orderPackageInfoDTO = packOrderDeliveryInfos(opOrder, purchaseOrders, false, false, true);
|
|
|
|
|
log.info("dsOrderOutStorageOrUpdateOutStorageLogistics[orderPackageInfoDTO]: " + orderPackageInfoDTO);
|
|
|
|
|
if (orderPackageInfoDTO.getPackageList() == null || orderPackageInfoDTO.getPackageList().isEmpty()) {
|
|
|
|
|
throw new RuntimeException("没有需要出库的包裹");
|
|
|
|
|
}
|
|
|
|
@ -340,6 +354,7 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
errorMessages.add(e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
ResultDTO result = orderMultiPackageOutstorage(shopBO, opOrder, new ArrayList<>(newPackages.values()), LogisticsConst.outstorageSourceDsAuto);
|
|
|
|
|
log.info("dsOrderOutStorageOrUpdateOutStorageLogistics[result]: " + result);
|
|
|
|
|
if (result.isSuccess()) {
|
|
|
|
|
opOrderDsService.updateOpOrderDsOrderStatus(opOrder);
|
|
|
|
|
} else {
|
|
|
|
@ -353,6 +368,7 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
hasProcessOutstorage = true;
|
|
|
|
|
try {
|
|
|
|
|
doUpdateLogistics(shopBO, opOrder, opPackage.getDdPackId(), orderPackageInfoDTO.getDeliveryInfo(), LogisticsConst.outstorageSourceDsLogisticsChangeUpdate);
|
|
|
|
|
log.info("dsOrderOutStorageOrUpdateOutStorageLogistics[doUpdateLogistics]: ");
|
|
|
|
|
} catch (RuntimeException e) {
|
|
|
|
|
errorMessages.add("包裹:" + opPackage.getDdPackId() + ",失败原因:" + e.getMessage());
|
|
|
|
|
}
|
|
|
|
@ -561,6 +577,7 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
|
|
|
|
|
String logisticsName = PurchaseTool.getDdLogisticsNameByDsLogisticsName(purchaseOrder.getPurchaseOrderLogisticsName());
|
|
|
|
|
OpLogisticsPlatformBO logisticsPlatformBO = logisticsNameAndLogisticsInfoMap.get(logisticsName);
|
|
|
|
|
log.info("logisticsPlatformBO: " + logisticsPlatformBO);
|
|
|
|
|
if(logisticsPlatformBO == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -578,9 +595,11 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
for (PurchaseOrderItem item: purchaseOrder.getItems()) {
|
|
|
|
|
if (skuIds.contains(item.getSkuId())) {
|
|
|
|
|
List<OpOrderChild> childOrderInfoList = skuIdAndChildOrderInfoMap.get(item.getSkuId());
|
|
|
|
|
System.out.println("childOrderInfoList: " + childOrderInfoList);
|
|
|
|
|
for (OpOrderChild child: childOrderInfoList) {
|
|
|
|
|
JSONObject opOrderChildAfterSale = child.getAfterSaleInfo();
|
|
|
|
|
if (opOrderChildAfterSale != null && opOrderChildAfterSale.get("after_sale_type").equals(AfterSaleConst.AFTERSALE_TYPE_REFUND_ONLY_BEFORE_SALE) && !AfterSaleConst.getAfterSaleCloseOrCancelStatusList().equals(opOrderChildAfterSale.get("after_sale_status"))) {
|
|
|
|
|
System.out.println("opOrderChildAfterSale: " + opOrderChildAfterSale);
|
|
|
|
|
if (opOrderChildAfterSale != null && !ObjectUtil.isEmpty(opOrderChildAfterSale) && opOrderChildAfterSale.get("after_sale_type").equals(AfterSaleConst.AFTERSALE_TYPE_REFUND_ONLY_BEFORE_SALE) && !AfterSaleConst.getAfterSaleCloseOrCancelStatusList().equals(opOrderChildAfterSale.get("after_sale_status"))) {
|
|
|
|
|
hasAfterSaleChildOrder = true;
|
|
|
|
|
}
|
|
|
|
|
packageList = buildChildOrderPackageList(packageList, child, childOrderIdAndLogisticsMap.get(child.getChildOrderId()), deliveryInfo, isIgnoreOrderStatus, isUpdateDelivery);
|
|
|
|
@ -600,14 +619,14 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
|
|
|
|
|
private List<OrderMultiPackageOutstorageDTO.PackageInfoDTO> buildChildOrderPackageList(List<OrderMultiPackageOutstorageDTO.PackageInfoDTO> packageList, OpOrderChild orderChild, List<OpOrderChildLogistics> childOrderLogisticsList, DeliverInfoDTO deliverInfoDTO, boolean isIgnoreOrderStatus, boolean isUpdateDelivery) {
|
|
|
|
|
if (!isIgnoreOrderStatus) {
|
|
|
|
|
if (!isUpdateDelivery && orderChild.getOrderStatus().equals(OrderConst.ORDER_STATUS_WAIT_SELLER_SEND_GOODS)) {
|
|
|
|
|
if (!isUpdateDelivery && !orderChild.getOrderStatus().equals(OrderConst.ORDER_STATUS_WAIT_SELLER_SEND_GOODS)) {
|
|
|
|
|
return packageList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Set<Integer> tmpOrderStatusSet = new HashSet<>();
|
|
|
|
|
tmpOrderStatusSet.add(OrderConst.ORDER_STATUS_WAIT_BUYER_CONFIRM_GOODS);
|
|
|
|
|
tmpOrderStatusSet.add(OrderConst.ORDER_STATUS_FINISH);
|
|
|
|
|
if (isUpdateDelivery && tmpOrderStatusSet.contains(orderChild.getOrderStatus())) {
|
|
|
|
|
if (isUpdateDelivery && !tmpOrderStatusSet.contains(orderChild.getOrderStatus())) {
|
|
|
|
|
return packageList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -633,6 +652,9 @@ public class OutstorageServiceImpl implements OutstorageService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int shippedNum = 0;
|
|
|
|
|
if (childOrderLogisticsList == null) {
|
|
|
|
|
childOrderLogisticsList = new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
for (OpOrderChildLogistics childLogistics: childOrderLogisticsList) {
|
|
|
|
|
shippedNum += childLogistics.getShippedNum().intValue();
|
|
|
|
|
}
|
|
|
|
|