|
|
|
@ -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, "ju ti")) {
|
|
|
|
|
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("其他", "其它", "卖家负责配送", "点点送", "ju ti").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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|