Merge remote-tracking branch 'origin/master'

20230922-ljl-fixBug
qiushengjie 1 year ago
commit 270dd680f2

@ -1,5 +1,10 @@
package com.ms.api.consts;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author: laixw
* @Date: 2023/9/1
@ -31,4 +36,74 @@ public class LogisticsConst {
public static final String ddSvcCodeWbHomeDelivery = "SVC-WBHOMEDELIVERY";
public static List<String> getIgnoreNoticeLogisticsNameList() {
String[] logisticsNames = {
"达达快递",
"龍行天下家居物流",
"E速宝",
"壹米滴答快运",
"壹米滴答快运(95058)",
"留单",
"AAE全球专递",
"菜鸟网络",
"菜鸟裹裹商家寄件",
"卖家负责配送",
"菜鸟仓配业务",
"其他",
"其它",
"其它快递",
"其他物流",
"停发",
"如风达配送",
"商桥物流",
"东莞市京广速递有限公司",
"疫情停发",
"官方物流",
"官方直送",
"立捷广州C2M产地仓",
"安鲜达快递",
"九谦物流",
"贝海国际速递",
"贝海国际",
"安世通",
"安世通国际快递",
"阿明物流",
"佳胜物流",
"西藏新疆",
"亿隆速运",
"远成快运",
"传化陆鲸科技有限公司",
"黑猫宅急便",
"农村淘宝",
"村服务站",
"ss",
"八方",
"平安达腾飞快递",
"Couriers本地发货",
"汇森速运",
"宅急送快递",
"百世物流(4008856561)",
"优速",
"京东",
"海瑞物流",
"苏宁快递",
"百世物流",
"湘源物流",
"德邦物流",
"联昊通物流",
"CP471906",
"平安达腾飞快递新业务",
"东骏快捷",
"D速物流",
"长宇",
"st",
"递速快运",
"瑞安置信物流",
"东骏快捷",
"未发出",
"青岛汇海源物流"
};
return Arrays.stream(logisticsNames).collect(Collectors.toList());
}
}

@ -2,6 +2,8 @@ package com.ms.api.service;
import com.ms.dal.entity.PurchaseLogisticsMatchRule;
import java.util.List;
/**
*
*/
@ -18,4 +20,6 @@ public interface PurchaseLogisticsMatchRuleService {
int updateByPrimaryKeySelective(PurchaseLogisticsMatchRule record);
int updateByPrimaryKey(PurchaseLogisticsMatchRule record);
List<PurchaseLogisticsMatchRule> getListByPurchasePlatform(String purchasePlatform);
}

@ -13,7 +13,6 @@ import com.doudian.open.api.order_logisticsAddMultiPack.param.ShippedOrderInfoIt
import com.doudian.open.api.order_logisticsEditByPack.OrderLogisticsEditByPackRequest;
import com.doudian.open.api.order_logisticsEditByPack.OrderLogisticsEditByPackResponse;
import com.doudian.open.api.order_logisticsEditByPack.param.OrderLogisticsEditByPackParam;
import com.jinritemai.cloud.base.core.util.AuthThreadLocalUtil;
import com.ms.api.bo.ShopBO;
import com.ms.api.consts.*;
import com.ms.api.dto.dsorder.DeliverInfoDTO;
@ -38,6 +37,8 @@ import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@ -69,6 +70,7 @@ public class OutstorageServiceImpl implements OutstorageService {
private PurchaseOrderTagService purchaseOrderTagService;
private PurchaseOrderItemService purchaseOrderItemService;
private OpOrderDelayOutstorageBufferService opOrderDelayOutstorageBufferService;
private PurchaseLogisticsMatchRuleService purchaseLogisticsMatchRuleService;
@Override
public ResultDTO orderMultiPackageOutstorage(ShopBO shopBO, String orderId, List<OrderMultiPackageOutstorageDTO.PackageInfoDTO> packageList) {
@ -276,7 +278,7 @@ public class OutstorageServiceImpl implements OutstorageService {
}
} catch (RuntimeException e) {
log.error("dsPurchaseAutoOutStorageError_" + opOrder.getOrderId(), e);
opOrderOutstorageHistoryService.addOrderOutstorageHistory(shopBO.getShopId(), Collections.singletonList(opOrder.getOrderId()), 0, purchaseOrder.getPurchaseOrderWaybillCode(), LogisticsConst.outstorageSourceDsAuto, 0, ResultDTO.fail(e.getMessage()));;
opOrderOutstorageHistoryService.addOrderOutstorageHistory(shopBO.getShopId(), Collections.singletonList(opOrder.getOrderId()), 0, purchaseOrder.getPurchaseOrderWaybillCode(), LogisticsConst.outstorageSourceDsAuto, 0, ResultDTO.fail(e.getMessage()));
}
}
@ -565,6 +567,7 @@ public class OutstorageServiceImpl implements OutstorageService {
}
Map<String, OpLogisticsPlatformBO> logisticsNameAndLogisticsInfoMap = opLogisticsPlatformService.getDdLogisticsNameAndLogisticsInfoMap();
log.info("logisticsNameAndLogisticsInfoMap: " + logisticsNameAndLogisticsInfoMap);
List<OpOrderChild> children = opOrderChildService.getChildrenByOrderId(opOrder.getOrderId(), true);
Map<Long, List<OpOrderChild>> skuIdAndChildOrderInfoMap = new HashMap<>();
for (OpOrderChild child: children) {
@ -605,6 +608,7 @@ public class OutstorageServiceImpl implements OutstorageService {
}
String logisticsName = PurchaseTool.getDdLogisticsNameByDsLogisticsName(purchaseOrder.getPurchaseOrderLogisticsName());
log.info("logisticsName: " + logisticsName);
OpLogisticsPlatformBO logisticsPlatformBO = logisticsNameAndLogisticsInfoMap.get(logisticsName);
log.info("logisticsPlatformBO: " + logisticsPlatformBO);
if(logisticsPlatformBO == null) {
@ -723,4 +727,222 @@ public class OutstorageServiceImpl implements OutstorageService {
}
return new ArrayList<>(packageIdAndPackageMap.values());
}
private Map<String, String> matchPurchaseLogisticsInfo(String purchasePlatform, String originLogisticsName, String originWaybillCode, Map<String, OpLogisticsPlatformBO> logisticsNameAndLogisticsInfoMap) {
if (logisticsNameAndLogisticsInfoMap == null) {
logisticsNameAndLogisticsInfoMap = opLogisticsPlatformService.getDdLogisticsNameAndLogisticsInfoMap();
}
String logisticsName = correctLogisticsNameByLogisticsMatchRule(originLogisticsName, originWaybillCode, purchasePlatform);
if (!isMatchDdLogistics(logisticsNameAndLogisticsInfoMap, logisticsName, originWaybillCode)) {
originWaybillCode = getCorrectDdWaybillCode(originWaybillCode, logisticsName);
logisticsName = correctLogisticsName(logisticsName, originWaybillCode);
}
boolean isMatch = logisticsNameAndLogisticsInfoMap.containsKey(logisticsName);
if (!isMatch && !isIgnoreNoticeLogisticsNameMismatch(logisticsName, originWaybillCode)) {
log.error("matchPurchaseLogisticsInfoError: " + logisticsName);
}
Map<String, String> result = new HashMap<>();
result.put("logisticsName", logisticsName);
result.put("waybillCode", originWaybillCode);
return result;
}
private String correctLogisticsNameByLogisticsMatchRule(String logisticsName, String purchaseOrderWaybillCode, String purchasePlatform) {
List<PurchaseLogisticsMatchRule> rules = purchaseLogisticsMatchRuleService.getListByPurchasePlatform(purchasePlatform);
if (rules.isEmpty()) {
return logisticsName;
}
// TODO array_multisort 排序?
for (PurchaseLogisticsMatchRule rule: rules) {
String realLogisticsName = rule.getLogisticsName();
if (!"all".equals(rule.getPurchasePlatform()) && !rule.getPurchasePlatform().equals(purchasePlatform)) {
break;
}
String purchaseLogisticsName = rule.getPurchaseLogisticsName().toLowerCase();
String waybillCodeRule = rule.getWaybillCodeRule();
if (!purchaseLogisticsName.equals(logisticsName.toLowerCase())) {
continue;
}
if (!waybillCodeRule.isEmpty() && !purchaseOrderWaybillCode.isEmpty()) {
Pattern p = Pattern.compile(waybillCodeRule);
Matcher m = p.matcher(purchaseOrderWaybillCode);
if (!m.find()) {
continue;
}
}
logisticsName = realLogisticsName;
break;
}
return logisticsName;
}
private boolean isMatchDdLogistics(Map<String, OpLogisticsPlatformBO> logisticsNameAndLogisticsInfoMap, String logisticsName, String waybillCode) {
boolean isMatch = logisticsNameAndLogisticsInfoMap.containsKey(logisticsName);
Pattern p = Pattern.compile("^JT\\d+$");
Matcher m = p.matcher(waybillCode.trim().toLowerCase());
if (m.find() && logisticsName.trim().toLowerCase().contains("龙邦速递")) {
isMatch = false;
}
return isMatch;
}
public String getCorrectDdWaybillCode(String waybillCode, String logisticsName) {
waybillCode = waybillCode.trim().toUpperCase();
Pattern p = Pattern.compile("^([T|W])JT\\d+$");
Matcher m = p.matcher(waybillCode);
if (m.find()) {
String field = m.group(1);
waybillCode = waybillCode.replaceAll("^([T|W])JT\\d+$", field);
}
p = Pattern.compile("^\\d+$");
m = p.matcher(waybillCode);
if ("极兔快递".equals(logisticsName) && m.find()) {
return "JT" + waybillCode;
}
String[] others = {"其他", "其它", "其它快递"};
List<String> otherList = Arrays.stream(others).collect(Collectors.toList());
if (otherList.contains(logisticsName)) {
Matcher m2 = Pattern.compile("^[A-Z]{2}YT\\d+$").matcher(waybillCode);
Matcher m3 = Pattern.compile("^[A-Z]{2}JT\\d+$").matcher(waybillCode);
p = Pattern.compile("^T77[03567]\\d+$");
if (p.matcher(waybillCode).find()) {
return waybillCode.trim();
} else if (Pattern.compile("^77[03567]\\d+ST$").matcher(waybillCode).find()) {
return waybillCode.replaceAll("^ST", "");
} else if (Pattern.compile("^A78299\\d+$").matcher(waybillCode).find()) {
return waybillCode.replaceAll("^A", "");
} else if (Pattern.compile("^YT\\d+YT$").matcher(waybillCode).find()) {
return waybillCode.replaceAll("^YT", "");
} else if (Pattern.compile("^TYT\\d+$").matcher(waybillCode).find()) {
return waybillCode.replaceAll("^T", "");
} else if (m2.find()) {
String field = m.group(1);
return waybillCode.replaceAll("^([A-Z]{2})(YT\\d+)$", field);
} else if (m3.find()) {
String field = m.group(1);
return waybillCode.replaceAll("^([A-Z]{2})(JT\\d+)$", field);
}
}
if (Pattern.compile("^WL77[03567]\\d+$").matcher(waybillCode).find() && Objects.equals(logisticsName, "点点送")) {
return waybillCode.replaceAll("^WL", "");
}
if (Pattern.compile("^WLJT\\d+$").matcher(waybillCode).find() && Objects.equals(logisticsName, "点点送")) {
return waybillCode.replaceAll("^WL", "");
}
if (Pattern.compile("^T462\\d+$").matcher(waybillCode).find() && Objects.equals(logisticsName, "官方物流")) {
return waybillCode.replaceAll("^T", "");
}
if (Pattern.compile("^CS\\d+$").matcher(waybillCode).find() && Objects.equals(logisticsName, "其他物流")) {
return waybillCode.replaceAll("^CS", "");
}
if (Pattern.compile("^KF\\d+$").matcher(waybillCode).find() && Objects.equals(logisticsName, "其他物流")) {
return waybillCode.replaceAll("^KF", "");
}
if (Pattern.compile("^EN\\d+$").matcher(waybillCode).find() && Objects.equals(logisticsName, "其他物流")) {
return waybillCode.replaceAll("^EN", "");
}
if (Pattern.compile("^JT\\d+Q$").matcher(waybillCode).find() && Objects.equals(logisticsName, "juti")) {
return waybillCode.replaceAll("^Q", "");
}
return waybillCode;
}
public String correctLogisticsName(String logisticsName, String waybillCode) {
if (logisticsName.contains("丹鸟")) {
logisticsName = "丹鸟";
}
logisticsName = logisticsName.replaceAll("\\([^\\\\(]+\\)", "");
logisticsName = logisticsName.replace("股份", "");
logisticsName = logisticsName.replace("'有限公司'", "");
if (logisticsName.contains("无界")) {
logisticsName = logisticsName.replace("无界", "");
if (!Pattern.compile("速递").matcher(logisticsName).find()) {
logisticsName += "快递";
}
}
if (logisticsName.contains("中通") && logisticsName.contains("中通快运") || Arrays.asList("其他", "其它", "其它快递", "卖家负责配送").contains(logisticsName) && Pattern.compile("^78299\\d+$").matcher(waybillCode).find()) {
logisticsName = "中通快递";
}
if (logisticsName.contains("EMS") || logisticsName.contains("邮政标准")) {
logisticsName = "邮政EMS";
} else if (logisticsName.contains("邮政") && logisticsName.contains("邮政电商标快")) {
logisticsName = "邮政快递包裹";
}
if (logisticsName.contains("圆通") && logisticsName.contains("圆通快运") || Arrays.asList("其他", "其它", "其它快递", "卖家负责配送").contains(logisticsName) && Pattern.compile("^YT\\d+$").matcher(waybillCode).find()) {
logisticsName = "圆通快递";
}
if (logisticsName.contains("国通")) {
logisticsName = "国通快递";
}
if (logisticsName.contains("申通达") || ( Arrays.asList("点点送", "菜鸟裹裹商家寄件", "官方直送", "其他", "其它", "其它快递", "卖家负责配送").contains(logisticsName) && Pattern.compile("^77[03567]\\d+$").matcher(waybillCode).find())) {
logisticsName = "申通快递";
}
if ((logisticsName.contains("韵达") && logisticsName.contains("韵达快运")) || ("官方物流".equals(logisticsName) && Pattern.compile("^462\\d+$").matcher(waybillCode).find())) {
logisticsName = "韵达快递";
}
if (logisticsName.contains("德邦") && (logisticsName.contains("德邦物流") || Pattern.compile("^DPK\\d+$").matcher(waybillCode).find())) {
logisticsName = "德邦快递";
}
if (Arrays.asList("其他", "其它", "卖家负责配送").contains(logisticsName) && Pattern.compile("^2\\d{8,9}").matcher(waybillCode).find()) {
logisticsName = "德邦快递";
}
if (Pattern.compile("圆通.+快递").matcher(logisticsName).find()) {
logisticsName = "圆通快递";
}
if (Pattern.compile("^JT\\d+$").matcher(waybillCode).find() && (logisticsName.contains("龙邦速递") || logisticsName.contains("百世") || logisticsName.contains("极兔") || Arrays.asList("其他", "其它", "卖家负责配送", "点点送", "juti").contains(logisticsName))) {
logisticsName = "极兔速递";
}
if (logisticsName.contains("百世物流") && Pattern.compile("^919\\d+$").matcher(waybillCode).find()) {
logisticsName = "百世快运";
}
if (Pattern.compile("^SF\\d+$").matcher(waybillCode).find()) {
logisticsName = "顺丰快递";
}
if (logisticsName.contains("丰网")) {
logisticsName = "丰网速运";
}
if (Pattern.compile("^JD[a-zA-Z0-9]+$").matcher(waybillCode).find() && logisticsName.contains("京东")) {
logisticsName = "京东快递";
}
return logisticsName;
}
private boolean isIgnoreNoticeLogisticsNameMismatch(String logisticsName, String waybillCode) {
if (logisticsName.isEmpty() && waybillCode.isEmpty()) {
return true;
}
if (LogisticsConst.getIgnoreNoticeLogisticsNameList().contains(logisticsName)) {
return true;
}
Pattern p1 = Pattern.compile("^(LE)?\\d+$");
Matcher m1 = p1.matcher(logisticsName);
if (m1.find()) {
return true;
}
Pattern p2 = Pattern.compile("^[\\da-zA-Z]+$");
Matcher m2 = p2.matcher(waybillCode);
if (Objects.equals(waybillCode, "-") || !m2.find()) {
return true;
}
if (waybillCode.contains("停发")) {
return true;
}
if (logisticsName.contains("停发")) {
return true;
}
if (logisticsName.contains("疫情")) {
return true;
}
if (logisticsName.contains("C2M")) {
return true;
}
return waybillCode.length() <= 5;
}
}

@ -6,6 +6,8 @@ import com.ms.dal.mapper.PurchaseLogisticsMatchRuleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
@ -46,6 +48,10 @@ public class PurchaseLogisticsMatchRuleServiceImpl implements PurchaseLogisticsM
return purchaseLogisticsMatchRuleMapper.updateByPrimaryKey(record);
}
@Override
public List<PurchaseLogisticsMatchRule> getListByPurchasePlatform(String purchasePlatform) {
return purchaseLogisticsMatchRuleMapper.getListByPurchasePlatform(purchasePlatform);
}
}

@ -1606,7 +1606,7 @@ public class PurchaseOrderServiceImpl implements PurchaseOrderService {
long hasShippedNum = logisticsInfos.stream().mapToLong(OpOrderChildLogistics::getShippedNum).sum();
JSONObject returnItem = (JSONObject) JSON.toJSON(item);
returnItem.put("skuName", item.getProductName() + "_" + String.join(" ", skuSubNames));
returnItem.put("jdPrice", CommonTool.correctCentToYuan(item.getCouponAmount()));
returnItem.put("jdPrice", CommonTool.correctCentToYuan(item.getComboAmount()));
returnItem.put("skuSubName", String.join(" ", skuSubNames));
returnItem.put("couponPrice", CommonTool.correctCentToYuan(item.getCouponAmount()));
returnItem.put("shopCouponAmount", CommonTool.correctCentToYuan(item.getShopCouponAmount()));

@ -2,6 +2,9 @@ package com.ms.dal.mapper;
import com.ms.dal.entity.PurchaseLogisticsMatchRule;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @Entity com.ms.dal.entity.PurchaseLogisticsMatchRule
@ -23,4 +26,5 @@ public interface PurchaseLogisticsMatchRuleMapper {
int updateByPrimaryKey(PurchaseLogisticsMatchRule record);
List<PurchaseLogisticsMatchRule> getListByPurchasePlatform(@Param("purchasePlatform") String purchasePlatform);
}

@ -27,6 +27,12 @@
from purchase_logistics_match_rule
where purchase_logistics_match_rule_id = #{purchaseLogisticsMatchRuleId,jdbcType=INTEGER}
</select>
<select id="getListByPurchasePlatform" resultType="com.ms.dal.entity.PurchaseLogisticsMatchRule">
select
<include refid="Base_Column_List" />
from purchase_logistics_match_rule
where purchase_platform in ('all', #{purchasePlatform,jdbcType=VARCHAR})
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete from purchase_logistics_match_rule

Loading…
Cancel
Save