Merge branch 'master' of codeup.aliyun.com:64d9c5feeceb191898f636d7/honor-dd-light-ds-java

20230922-ljl-fixBug
cxxxxxxx详 1 year ago
commit 748cd87635

@ -142,7 +142,7 @@ public class GetPurchaseOrderItemsAndSourceItemsResponseDTO extends CommonRespon
private String tradeTypeDesc;
private String tradeTypeCode;
private String waybill;
private Integer logisticsId;
private Long logisticsId;
private String logisticsName;
private String alibabaLogisticsIds;
private String toFullNameMd5;

@ -0,0 +1,9 @@
package com.ms.api.bo;
import lombok.Data;
@Data
public class MovePublishBufferRandShopIdAndPriorityBO {
private Long shopId;
private Integer prioirty;
}

@ -1,5 +1,6 @@
package com.ms.api.consts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -90,6 +91,6 @@ public class AfterSaleConst {
public static final String WARNING_SOURCE_DISTRIBUTION = "distribution";
public static List<Integer> getAfterSaleCloseOrCancelStatusList() {
return Arrays.asList(AFTERSALE_STATUS_CLOSE, AFTERSALE_STATUS_REFUSE_AFTER_SALE_APPLY);
return new ArrayList<>(Arrays.asList(AFTERSALE_STATUS_CLOSE, AFTERSALE_STATUS_REFUSE_AFTER_SALE_APPLY));
}
}

@ -430,10 +430,12 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
for (PlatformOrderDTO platformOrder: platformOrders) {
OpOrder opOrder = orderIdAndOrderMap.get(platformOrder.getPlatformOrderId());
if (purchaseSetting.getIsAutoFillRemark() >= 1) {
platformOrder.setSourceOrderSellerMemo(buildSourceOrderRemarkAndMemo(shop, purchaseSetting.getAutoFillRemarkTpl(), opOrder));
String autoFillRemarkTpl = buildRemarkTplHtml(purchaseSetting.getAutoFillRemarkTpl());
platformOrder.setSourceOrderSellerMemo(buildSourceOrderRemarkAndMemo(shop, autoFillRemarkTpl, opOrder));
}
if (purchaseSetting.getIsAutoFillOrderMemo() >= 1) {
platformOrder.setSourceOrderSellerMemo(buildSourceOrderRemarkAndMemo(shop, purchaseSetting.getAutoFillOrderMemoTpl(), opOrder));
String autoFillOrderMemoTpl = buildRemarkTplHtml(purchaseSetting.getAutoFillOrderMemoTpl());
platformOrder.setSourceOrderSellerMemo(buildSourceOrderRemarkAndMemo(shop, autoFillOrderMemoTpl, opOrder));
}
}
}

@ -84,7 +84,11 @@ public class OpOrderChildLogisticsServiceImpl implements OpOrderChildLogisticsSe
public List<OpOrderChildLogistics> getListByOrderId(String orderId) {
List<String> list = new ArrayList<>();
list.add(orderId);
return getOrderIdAndChildLogisticsListMap(list).get(orderId);
if (getOrderIdAndChildLogisticsListMap(list).containsKey(orderId)) {
return getOrderIdAndChildLogisticsListMap(list).get(orderId);
} else {
return new ArrayList<>();
}
}
@Override

@ -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();
}

@ -343,7 +343,9 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
continue;
}
OpOrderOutstorageHistory orderOutstorageResult = orderIdAndOpOrderOutstrorageHistoryMap.get(order.getString("orderId"));
order.put("outstorageFailReason", orderOutstorageResult.getStatus().equals(StatusConst.fail) ? orderOutstorageResult.getReason() : "");
if (orderOutstorageResult != null) {
order.put("outstorageFailReason", orderOutstorageResult.getStatus().equals(StatusConst.fail) ? orderOutstorageResult.getReason() : "");
}
}
}

@ -44,8 +44,8 @@ public class DsMessageConsumeMsgTaskService extends TaskBaseService {
@Resource(name = "dsMessageConsumeMsgTaskPool")
protected Executor taskPool;
// @Async("dsMessageConsumeMsgTaskPool")
// @Scheduled(fixedRate = 10000)
@Async("dsMessageConsumeMsgTaskPool")
@Scheduled(fixedRate = 10000)
@Override
public void runTask() {
super.runTask();

@ -32,8 +32,8 @@ public class DsMessageMoveBufferTaskService extends TaskBaseService {
@Resource(name = "dsMessageMoveBufferTaskPool")
protected Executor taskPool;
// @Async("dsMessageMoveBufferTaskPool")
// @Scheduled(fixedRate = 10000)
@Async("dsMessageMoveBufferTaskPool")
@Scheduled(fixedRate = 10000)
@Override
public void runTask() {
super.runTask();

@ -1,6 +1,6 @@
package com.ms.api.task;
import com.ms.api.common.E;
import com.ms.api.bo.MovePublishBufferRandShopIdAndPriorityBO;
import com.ms.api.common.StrObjMap;
import com.ms.api.common.TaskBaseService;
import com.ms.api.consts.RedisKeyConst;
@ -20,9 +20,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import javax.annotation.Resource;
import java.util.*;
@ -252,38 +249,127 @@ public class MovePublishBufferTaskService extends TaskBaseService {
}
private Map<Long, Integer> allocProductPublishQuota(int leftCount, Map<Integer, Map<Long, Integer>> priorityShopsMap, Map<Long, Integer> shopLimitQuotaArray) {
// TODO 根据一定算法给每个店铺一个搬家的数量
// $needSkipShopIdMap = $this->getNeedSkipShopIdMap($shopLimitQuotaArray);
// $selectedShopMap = array();
// do {
// if (empty($priorityShopsMap)) {
// break;
// }
//
// $priorityArr = $this->randPriority();
// list ($shopId, $priority) = $this->getMovePublishBufferRandShopIdByPriorityArr($priorityArr, $priorityShopsMap, $needSkipShopIdMap);
// if (empty($shopId)) {
// break;
// }
//
// $shopLimitQuotaArray[$shopId]--;
// if ($shopLimitQuotaArray[$shopId] <= 0) {
// $needSkipShopIdMap[$shopId] = true;
// }
//
// $selectedShopMap[$shopId] = isset($selectedShopMap[$shopId]) ? $selectedShopMap[$shopId] + 1 : 1;
// $leftCount--;
// if ($leftCount <= 0) {
// break;
// }
// $priorityShopsMap[$priority][$shopId]--;
// if (empty($priorityShopsMap[$priority][$shopId])) {
// unset($priorityShopsMap[$priority][$shopId]);
// }
// } while (true);
//
// return $selectedShopMap;
return shopLimitQuotaArray;
// 根据一定算法给每个店铺一个搬家的数量
Map<Long, Boolean> needSkipShopIdMap = getNeedSkipShopIdMap(shopLimitQuotaArray);
Map<Long, Integer> selectedShopMap = new HashMap<>();
do {
if (priorityShopsMap == null || priorityShopsMap.isEmpty()) {
break;
}
int[] priorityArr = randPriority();
MovePublishBufferRandShopIdAndPriorityBO movePublishBufferRandShopIdAndPriorityBO = getMovePublishBufferRandShopIdByPriorityArr(priorityArr, priorityShopsMap, needSkipShopIdMap);
Long shopId = movePublishBufferRandShopIdAndPriorityBO.getShopId();
Integer priority = movePublishBufferRandShopIdAndPriorityBO.getPrioirty();
if (shopId == null) {
break;
}
if (shopLimitQuotaArray.containsKey(shopId)) {
shopLimitQuotaArray.put(shopId, shopLimitQuotaArray.get(shopId) - 1);
} else {
shopLimitQuotaArray.put(shopId, -1);
}
if (shopLimitQuotaArray.get(shopId) <= 0) {
needSkipShopIdMap.put(shopId, true);
}
if (selectedShopMap.containsKey(shopId)) {
selectedShopMap.put(shopId, selectedShopMap.get(shopId) + 1);
} else {
selectedShopMap.put(shopId, 1);
}
leftCount--;
if (leftCount <= 0) {
break;
}
if (priorityShopsMap.containsKey(priority) && priorityShopsMap.get(priority).containsKey(shopId)) {
int val = priorityShopsMap.get(priority).get(shopId) - 1;
if (val == 0) {
priorityShopsMap.get(priority).remove(shopId);
} else {
priorityShopsMap.get(priority).put(shopId, val);
}
if (priorityShopsMap.get(priority).isEmpty()) {
priorityShopsMap.remove(priority);
}
}
} while (true);
return selectedShopMap;
}
private int[] randPriority() {
int pc = (new Random()).nextInt(100) + 1;
int[] pl;
if (pc >= 1 && pc <= 35) {
pl = new int[] {98, 99, 100, 101, 110};
} else if (pc >= 36 && pc <= 50) {
pl = new int[] {99, 100, 101, 103, 110};
} else if (pc >= 51 && pc <= 65) {
pl = new int[] {100, 103, 105, 110};
} else if (pc >= 66 && pc <= 75) {
pl = new int[] {101, 103, 105, 110};
} else if (pc >= 76 && pc <= 85) {
pl = new int[] {103, 105, 110};
} else if (pc >= 86 && pc <= 95) {
pl = new int[] {105, 110};
} else {
pl = new int[] {110};
}
return pl;
}
private MovePublishBufferRandShopIdAndPriorityBO getMovePublishBufferRandShopIdByPriorityArr(int[] priorityArr, Map<Integer, Map<Long, Integer>> priorityShopsMap, Map<Long, Boolean> needSkipShopIdMap) {
Set<Long> shopIds = new HashSet<>();
int minPriority = Arrays.stream(priorityArr).min().getAsInt();
Map<Long, List<Integer>> shopIdPriorityMap = new HashMap<>();
for (Integer currPriority : priorityShopsMap.keySet()) {
Map<Long, Integer> shopIdAndCountMap = priorityShopsMap.get(currPriority);
Set<Long> priorityShopIds = new HashSet<>();
for (Long shopId : shopIdAndCountMap.keySet()) {
if (needSkipShopIdMap.containsKey(shopId)) {
continue;
}
priorityShopIds.add(shopId);
if (!shopIdPriorityMap.containsKey(shopId)) {
shopIdPriorityMap.put(shopId, new ArrayList<Integer>());
}
List<Integer> priorityList = shopIdPriorityMap.get(shopId);
if (!priorityList.contains(currPriority)) {
priorityList.add(currPriority);
}
}
shopIds.addAll(priorityShopIds);
if (currPriority >= minPriority && !shopIds.isEmpty()) {
break;
}
}
MovePublishBufferRandShopIdAndPriorityBO ret = new MovePublishBufferRandShopIdAndPriorityBO();
if (!shopIds.isEmpty()) {
ArrayList<Long> shopIdList = new ArrayList<>(shopIds);
Long shopId = shopIdList.get(new Random().nextInt(shopIdList.size()));
Integer prioirty = shopIdPriorityMap.get(shopId).get(0);
ret.setShopId(shopId);
ret.setPrioirty(prioirty);
}
return ret;
}
private Map<Long, Boolean> getNeedSkipShopIdMap(Map<Long, Integer> shopLimitQuotaArray) {
Map<Long, Boolean> needSkipShopIdMap = new HashMap<>();
for (Map.Entry<Long, Integer> entry : shopLimitQuotaArray.entrySet()) {
Integer count = entry.getValue();
Long shopId = entry.getKey();
if (count <= 0) {
needSkipShopIdMap.put(shopId, true);
}
}
return needSkipShopIdMap;
}
// Buffer移到Queue中

Loading…
Cancel
Save