From f9e404d6b90a59be38013185b4805a85bff5867b Mon Sep 17 00:00:00 2001 From: ljl Date: Wed, 22 Nov 2023 20:46:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9butg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ms/biz/consts/LogisticsConst.java | 13 +- .../service/LogisticsMatchRuleService.java | 21 ++ .../com/ms/biz/service/LogisticsService.java | 25 ++ .../service/impl/DsMessageServiceImpl.java | 50 +++- .../impl/LogisticsMatchRuleServiceImpl.java | 53 ++++ .../service/impl/LogisticsServiceImpl.java | 276 ++++++++++++++++++ .../src/main/java/com/ms/biz/util/DDApi.java | 30 +- .../java/com/ms/dal/entity/Logistics.java | 51 ++++ .../com/ms/dal/entity/LogisticsMatchRule.java | 51 ++++ .../com/ms/dal/mapper/LogisticsMapper.java | 32 ++ .../dal/mapper/LogisticsMatchRuleMapper.java | 30 ++ .../main/resources/mapper/LogisticsMapper.xml | 153 ++++++++++ .../mapper/LogisticsMatchRuleMapper.xml | 148 ++++++++++ .../main/java/com/ms/web/controller/Test.java | 9 + 14 files changed, 924 insertions(+), 18 deletions(-) create mode 100644 ms-biz/src/main/java/com/ms/biz/service/LogisticsMatchRuleService.java create mode 100644 ms-biz/src/main/java/com/ms/biz/service/LogisticsService.java create mode 100644 ms-biz/src/main/java/com/ms/biz/service/impl/LogisticsMatchRuleServiceImpl.java create mode 100644 ms-biz/src/main/java/com/ms/biz/service/impl/LogisticsServiceImpl.java create mode 100644 ms-dal/src/main/java/com/ms/dal/entity/Logistics.java create mode 100644 ms-dal/src/main/java/com/ms/dal/entity/LogisticsMatchRule.java create mode 100644 ms-dal/src/main/java/com/ms/dal/mapper/LogisticsMapper.java create mode 100644 ms-dal/src/main/java/com/ms/dal/mapper/LogisticsMatchRuleMapper.java create mode 100644 ms-dal/src/main/resources/mapper/LogisticsMapper.xml create mode 100644 ms-dal/src/main/resources/mapper/LogisticsMatchRuleMapper.xml diff --git a/ms-biz/src/main/java/com/ms/biz/consts/LogisticsConst.java b/ms-biz/src/main/java/com/ms/biz/consts/LogisticsConst.java index 089f768..cdc6f29 100644 --- a/ms-biz/src/main/java/com/ms/biz/consts/LogisticsConst.java +++ b/ms-biz/src/main/java/com/ms/biz/consts/LogisticsConst.java @@ -1,8 +1,6 @@ package com.ms.biz.consts; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -106,4 +104,13 @@ public class LogisticsConst { }; return Arrays.stream(logisticsNames).collect(Collectors.toList()); } + + public static String getDDLogisticsName(String aliLogisticsName) { + Map logisticsNameMap = new HashMap<>(); + logisticsNameMap.put("顺丰速运", "顺丰速运(常用)"); + if (logisticsNameMap.containsKey(aliLogisticsName)) { + return logisticsNameMap.get(aliLogisticsName); + } + return aliLogisticsName; + } } diff --git a/ms-biz/src/main/java/com/ms/biz/service/LogisticsMatchRuleService.java b/ms-biz/src/main/java/com/ms/biz/service/LogisticsMatchRuleService.java new file mode 100644 index 0000000..3c888ac --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/service/LogisticsMatchRuleService.java @@ -0,0 +1,21 @@ +package com.ms.biz.service; + +import com.ms.dal.entity.LogisticsMatchRule; + +/** + * + */ +public interface LogisticsMatchRuleService { + + int deleteByPrimaryKey(Long id); + + int insert(LogisticsMatchRule record); + + int insertSelective(LogisticsMatchRule record); + + LogisticsMatchRule selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(LogisticsMatchRule record); + + int updateByPrimaryKey(LogisticsMatchRule record); +} diff --git a/ms-biz/src/main/java/com/ms/biz/service/LogisticsService.java b/ms-biz/src/main/java/com/ms/biz/service/LogisticsService.java new file mode 100644 index 0000000..ed32517 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/service/LogisticsService.java @@ -0,0 +1,25 @@ +package com.ms.biz.service; + +import com.ms.dal.entity.Logistics; + +import java.util.Map; + +/** + * + */ +public interface LogisticsService { + + int deleteByPrimaryKey(Long id); + + int insert(Logistics record); + + int insertSelective(Logistics record); + + Logistics selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(Logistics record); + + int updateByPrimaryKey(Logistics record); + + Map matchLogisticsInfo(String platform, String originLogisticsName, String originWaybillCode, Map logisticsNameAndLogisticsInfoMap); +} diff --git a/ms-biz/src/main/java/com/ms/biz/service/impl/DsMessageServiceImpl.java b/ms-biz/src/main/java/com/ms/biz/service/impl/DsMessageServiceImpl.java index 8f63ebe..968de55 100644 --- a/ms-biz/src/main/java/com/ms/biz/service/impl/DsMessageServiceImpl.java +++ b/ms-biz/src/main/java/com/ms/biz/service/impl/DsMessageServiceImpl.java @@ -1,6 +1,11 @@ package com.ms.biz.service.impl; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollectionUtil; import com.alibaba.fastjson.JSONObject; +import com.doudian.open.api.order_logisticsAddMultiPack.param.OrderLogisticsAddMultiPackParam; +import com.doudian.open.api.order_logisticsAddMultiPack.param.PackListItem; +import com.doudian.open.api.order_logisticsAddMultiPack.param.ShippedOrderInfoItem; import com.doudian.open.api.supplyCenter_order_cancel.param.SupplyCenterOrderCancelParam; import com.doudian.open.api.supplyCenter_order_confirm.param.SupplyCenterOrderConfirmParam; import com.doudian.open.api.supplyCenter_order_logistics.param.SupplyCenterOrderLogisticsParam; @@ -13,10 +18,7 @@ import com.doudian.open.api.supplyCenter_refund_operate.param.Address; import com.doudian.open.api.supplyCenter_refund_operate.param.SkuRefundInfosItem; import com.doudian.open.api.supplyCenter_refund_operate.param.SupplyCenterRefundOperateParam; import com.jinritemai.cloud.base.core.util.AuthThreadLocalUtil; -import com.ms.biz.consts.DsMessageConst; -import com.ms.biz.consts.PurchaseOrderConst; -import com.ms.biz.consts.Refund1688Const; -import com.ms.biz.consts.StatusConst; +import com.ms.biz.consts.*; import com.ms.biz.quque.Group; import com.ms.biz.quque.Producer; import com.ms.biz.quque.Topic; @@ -56,6 +58,7 @@ public class DsMessageServiceImpl implements DsMessageService { private PlatformPurchaseOrderSkuMapper platformPurchaseOrderSkuMapper; private PurchaseOrderMapper purchaseOrderMapper; private PurchaseOrderItemMapper purchaseOrderItemMapper; + private LogisticsMapper logisticsMapper; @Override public int deleteByPrimaryKey(Long id) { @@ -212,7 +215,7 @@ public class DsMessageServiceImpl implements DsMessageService { switch (dsMessage.getBizType()) { case DsMessageConst.BIZ_TYPE_RELATE_PURCHASE_ORDER: - handlePurchaseOrderRelate((PurchaseOrderRelateMessageDTO)messageDTO); +// handlePurchaseOrderRelate((PurchaseOrderRelateMessageDTO)messageDTO); break; case DsMessageConst.BIZ_TYPE_PURCHASE_ORDER_CHANGE: handlePurchaseOrderChange((PurchaseOrderChangeMessageDTO)messageDTO); @@ -263,7 +266,7 @@ public class DsMessageServiceImpl implements DsMessageService { handlePurchaseOrderAfterPay(purchaseOrderDTO, purchaseOrder, skuIdAndPlatformPurchaseOrderSkuMap); break; case PurchaseOrderConst.PURCHASE_ORDER_STATUS_HAS_SEND: - handlePurchaseOrderAfterSend(purchaseOrderDTO, purchaseOrder); + handlePurchaseOrderAfterSend(purchaseOrderDTO, purchaseOrder, skuIdAndPlatformPurchaseOrderSkuMap); break; case PurchaseOrderConst.PURCHASE_ORDER_STATUS_FINISHED: handlePurchaseOrderAfterFinish(purchaseOrderDTO, purchaseOrder); @@ -309,7 +312,7 @@ public class DsMessageServiceImpl implements DsMessageService { DDApi.supplyCenterOrderPay(param); } - private void handlePurchaseOrderAfterSend(PurchaseOrderDTO purchaseOrderDTO, PurchaseOrder purchaseOrder) { + private void handlePurchaseOrderAfterSend(PurchaseOrderDTO purchaseOrderDTO, PurchaseOrder purchaseOrder, Map skuIdAndPlatformPurchaseOrderSkuMap) { Date purchaseOrderSendTime = CommonTool.parseDate(purchaseOrderDTO.getPurchaseOrderUpdateTime()); purchaseOrder.setPurchaseOrderSendTime(purchaseOrderSendTime); purchaseOrder.setPurchaseOrderLogisticsName(purchaseOrder.getPurchaseOrderLogisticsName()); @@ -322,6 +325,39 @@ public class DsMessageServiceImpl implements DsMessageService { } param.setExpressType(1); DDApi.supplyCenterOrderLogistics(param); + + logisticsAddMultiPack(purchaseOrderDTO, skuIdAndPlatformPurchaseOrderSkuMap); + } + + private void logisticsAddMultiPack(PurchaseOrderDTO purchaseOrderDTO, Map skuIdAndPlatformPurchaseOrderSkuMap) { + OrderLogisticsAddMultiPackParam param = new OrderLogisticsAddMultiPackParam(); + param.setOrderId(purchaseOrderDTO.getPlatformOrderId()); + + List packageList = new ArrayList<>(); + PackListItem packListItem = new PackListItem(); + packListItem.setLogisticsCode(purchaseOrderDTO.getPurchaseOrderWaybillCode()); + + String logisticsName = LogisticsConst.getDDLogisticsName(purchaseOrderDTO.getPurchaseOrderLogisticsName()); + Logistics logistics = logisticsMapper.getByLogisticsName(logisticsName); + if (logistics == null) { + log.info("物流不存在: 1688[{}] 抖店[{}]", purchaseOrderDTO.getPurchaseOrderLogisticsName(), logisticsName); + throw new RuntimeException("物流不存在"); + } + packListItem.setCompanyCode(logistics.getLogisticsCode()); + packListItem.setCompanyCode(logisticsName); + List shippedOrderInfo = new ArrayList<>(); + for (PurchaseOrderItemDTO item: purchaseOrderDTO.getItems()) { + PlatformPurchaseOrderSku platformPurchaseOrderSku = skuIdAndPlatformPurchaseOrderSkuMap.get(item.getSkuId()); + ShippedOrderInfoItem shippedOrderInfoItem = new ShippedOrderInfoItem(); + shippedOrderInfoItem.setShippedNum(Long.valueOf(item.getPurchaseNum())); + shippedOrderInfoItem.setShippedOrderId(platformPurchaseOrderSku.getSkuOrderId()); + shippedOrderInfo.add(shippedOrderInfoItem); + } + packListItem.setShippedOrderInfo(shippedOrderInfo); + packageList.add(packListItem); + param.setPackList(packageList); + param.setRequestId(UUID.randomUUID().toString()); + DDApi.logisticsAddMultiPack(param); } private void handlePurchaseOrderAfterFinish(PurchaseOrderDTO purchaseOrderDTO, PurchaseOrder purchaseOrder) { diff --git a/ms-biz/src/main/java/com/ms/biz/service/impl/LogisticsMatchRuleServiceImpl.java b/ms-biz/src/main/java/com/ms/biz/service/impl/LogisticsMatchRuleServiceImpl.java new file mode 100644 index 0000000..5ef1234 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/service/impl/LogisticsMatchRuleServiceImpl.java @@ -0,0 +1,53 @@ +package com.ms.biz.service.impl; + +import com.ms.dal.entity.LogisticsMatchRule; +import com.ms.biz.service.LogisticsMatchRuleService; +import com.ms.dal.mapper.LogisticsMatchRuleMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +/** + * + */ +@Service +public class LogisticsMatchRuleServiceImpl implements LogisticsMatchRuleService { + + @Autowired + private LogisticsMatchRuleMapper logisticsMatchRuleMapper; + + @Override + public int deleteByPrimaryKey(Long id) { + return logisticsMatchRuleMapper.deleteByPrimaryKey(id); + } + + @Override + public int insert(LogisticsMatchRule record) { + return logisticsMatchRuleMapper.insert(record); + } + + @Override + public int insertSelective(LogisticsMatchRule record) { + return logisticsMatchRuleMapper.insertSelective(record); + } + + @Override + public LogisticsMatchRule selectByPrimaryKey(Long id) { + return logisticsMatchRuleMapper.selectByPrimaryKey(id); + } + + @Override + public int updateByPrimaryKeySelective(LogisticsMatchRule record) { + return logisticsMatchRuleMapper.updateByPrimaryKeySelective(record); + } + + @Override + public int updateByPrimaryKey(LogisticsMatchRule record) { + return logisticsMatchRuleMapper.updateByPrimaryKey(record); + } + +} + + + + diff --git a/ms-biz/src/main/java/com/ms/biz/service/impl/LogisticsServiceImpl.java b/ms-biz/src/main/java/com/ms/biz/service/impl/LogisticsServiceImpl.java new file mode 100644 index 0000000..43faf93 --- /dev/null +++ b/ms-biz/src/main/java/com/ms/biz/service/impl/LogisticsServiceImpl.java @@ -0,0 +1,276 @@ +package com.ms.biz.service.impl; + +import com.ms.biz.consts.LogisticsConst; +import com.ms.biz.tool.CommonTool; +import com.ms.dal.entity.Logistics; +import com.ms.biz.service.LogisticsService; +import com.ms.dal.entity.LogisticsMatchRule; +import com.ms.dal.mapper.LogisticsMapper; +import com.ms.dal.mapper.LogisticsMatchRuleMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + + +/** + * + */ +@Slf4j +@Service +public class LogisticsServiceImpl implements LogisticsService{ + + @Autowired + private LogisticsMapper logisticsMapper; + + @Autowired + private LogisticsMatchRuleMapper logisticsMatchRuleMapper; + + @Override + public int deleteByPrimaryKey(Long id) { + return logisticsMapper.deleteByPrimaryKey(id); + } + + @Override + public int insert(Logistics record) { + return logisticsMapper.insert(record); + } + + @Override + public int insertSelective(Logistics record) { + return logisticsMapper.insertSelective(record); + } + + @Override + public Logistics selectByPrimaryKey(Long id) { + return logisticsMapper.selectByPrimaryKey(id); + } + + @Override + public int updateByPrimaryKeySelective(Logistics record) { + return logisticsMapper.updateByPrimaryKeySelective(record); + } + + @Override + public int updateByPrimaryKey(Logistics record) { + return logisticsMapper.updateByPrimaryKey(record); + } + + @Override + public Map matchLogisticsInfo(String platform, String originLogisticsName, String originWaybillCode, Map logisticsNameAndLogisticsInfoMap) { + if (logisticsNameAndLogisticsInfoMap == null) { + List logisticsList = logisticsMapper.getList(); + logisticsNameAndLogisticsInfoMap = logisticsList.stream().collect(Collectors.toMap(Logistics::getLogisticsName, x -> x)); + } + String logisticsName = correctLogisticsNameByLogisticsMatchRule(originLogisticsName, originWaybillCode, platform); + 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 result = new HashMap<>(); + result.put("logisticsName", logisticsName); + result.put("waybillCode", originWaybillCode); + return result; + } + + private String correctLogisticsNameByLogisticsMatchRule(String logisticsName, String purchaseOrderWaybillCode, String platform) { + List rules = logisticsMatchRuleMapper.getListByPlatform(platform); + if (rules.isEmpty()) { + return logisticsName; + } + + for (LogisticsMatchRule rule: rules) { + String realLogisticsName = rule.getLogisticsName(); + if (!"all".equals(rule.getPlatform()) && !rule.getPlatform().equals(platform)) { + break; + } + String purchaseLogisticsName = rule.getPlatformLogisticsName().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 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()) { + waybillCode = m.group(2); + } + if ("极兔快递".equals(logisticsName) && Pattern.compile("^\\d+$").matcher(waybillCode).find()) { + return "JT" + waybillCode; + } + String[] others = {"其他", "其它", "其它快递"}; + List 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()) { + return m.group(2); + } else if (m3.find()) { + return m.group(2); + } + } + 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) && CommonTool.isMatch("^78299\\d+$", waybillCode))) { + 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; + } + if (Pattern.compile("^(LE)?\\d+$").matcher(logisticsName).find()) { + return true; + } + if (Objects.equals(waybillCode, "-") || !Pattern.compile("^[\\da-zA-Z]+$").matcher(waybillCode).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; + } +} + + + + diff --git a/ms-biz/src/main/java/com/ms/biz/util/DDApi.java b/ms-biz/src/main/java/com/ms/biz/util/DDApi.java index 8fd37e0..f3c6591 100644 --- a/ms-biz/src/main/java/com/ms/biz/util/DDApi.java +++ b/ms-biz/src/main/java/com/ms/biz/util/DDApi.java @@ -2,6 +2,10 @@ package com.ms.biz.util; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONObject; +import com.doudian.open.api.order_logisticsAddMultiPack.OrderLogisticsAddMultiPackRequest; +import com.doudian.open.api.order_logisticsAddMultiPack.OrderLogisticsAddMultiPackResponse; +import com.doudian.open.api.order_logisticsAddMultiPack.data.OrderLogisticsAddMultiPackData; +import com.doudian.open.api.order_logisticsAddMultiPack.param.OrderLogisticsAddMultiPackParam; import com.doudian.open.api.supplyCenter_cargo_detail.SupplyCenterCargoDetailRequest; import com.doudian.open.api.supplyCenter_cargo_detail.SupplyCenterCargoDetailResponse; import com.doudian.open.api.supplyCenter_cargo_detail.data.SupplyCenterCargoDetailData; @@ -53,7 +57,7 @@ public class DDApi { if (response.isSuccess()) { return response.getData(); } - throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } public static SupplyCenterOrderSyncSupplierInfoData supplyCenterOrderSyncSupplierInfo(SupplyCenterOrderSyncSupplierInfoParam param) { @@ -64,7 +68,7 @@ public class DDApi { if (response.isSuccess()) { return response.getData(); } - throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } public static SupplyCenterOrderLogisticsData supplyCenterOrderLogistics(SupplyCenterOrderLogisticsParam param) { @@ -75,7 +79,7 @@ public class DDApi { if (response.isSuccess()) { return response.getData(); } - throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } public static SupplyCenterOrderCancelData supplyCenterOrderCancel(SupplyCenterOrderCancelParam param) { @@ -86,7 +90,7 @@ public class DDApi { if (response.isSuccess()) { return response.getData(); } - throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } public static SupplyCenterOrderPayData supplyCenterOrderPay(SupplyCenterOrderPayParam param) { @@ -97,7 +101,7 @@ public class DDApi { if (response.isSuccess()) { return response.getData(); } - throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } public static SupplyCenterRefundOperateData supplyCenterRefundOperate(SupplyCenterRefundOperateParam param) { @@ -108,7 +112,7 @@ public class DDApi { if (response.isSuccess()) { return response.getData(); } - throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } public static SupplyCenterCargoDetailData supplyCenterCargoDetail(SupplyCenterCargoDetailParam param) { @@ -119,7 +123,7 @@ public class DDApi { if (response.isSuccess()) { return response.getData(); } - throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } public static SupplyCenterOrderQueryData supplyCenterOrderQuery(SupplyCenterOrderQueryParam param) { @@ -130,7 +134,17 @@ public class DDApi { if (response.isSuccess()) { return response.getData(); } - throw new RuntimeException(String.format("抖店请求错误:msg:%s,code:%s,subCode:%s,subMsg:%s,", response.getMsg(), response.getCode(), response.getSubCode(), response.getSubMsg())); + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); + } + + public static OrderLogisticsAddMultiPackData logisticsAddMultiPack(OrderLogisticsAddMultiPackParam param) { + OrderLogisticsAddMultiPackRequest request = new OrderLogisticsAddMultiPackRequest(); + request.setParam(param); + OrderLogisticsAddMultiPackResponse response = request.execute(); + if (response.isSuccess()) { + return response.getData(); + } + throw new RuntimeException(String.format("抖店请求错误:%s", response.getMsg())); } private static T execute(DoudianOpRequest request) { diff --git a/ms-dal/src/main/java/com/ms/dal/entity/Logistics.java b/ms-dal/src/main/java/com/ms/dal/entity/Logistics.java new file mode 100644 index 0000000..5452d4a --- /dev/null +++ b/ms-dal/src/main/java/com/ms/dal/entity/Logistics.java @@ -0,0 +1,51 @@ +package com.ms.dal.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * 软件内物流信息 + * @TableName logistics + */ + +@Data +public class Logistics implements Serializable { + /** + * 自增id + */ + private Long logisticsId; + + /** + * 物流公司名称 + */ + private String logisticsName; + + /** + * 软件内定义的物流公司编码 + */ + private String logisticsCode; + + /** + * 状态 + */ + private String status; + + /** + * 排序 + */ + private Integer sort; + + /** + * 创建时间 + */ + private Date gmtCreate; + + /** + * 修改时间 + */ + private Date gmtModified; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/ms-dal/src/main/java/com/ms/dal/entity/LogisticsMatchRule.java b/ms-dal/src/main/java/com/ms/dal/entity/LogisticsMatchRule.java new file mode 100644 index 0000000..4508748 --- /dev/null +++ b/ms-dal/src/main/java/com/ms/dal/entity/LogisticsMatchRule.java @@ -0,0 +1,51 @@ +package com.ms.dal.entity; + +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** + * + * @TableName logistics_match_rule + */ + +@Data +public class LogisticsMatchRule implements Serializable { + /** + * + */ + private Integer logisticsMatchRuleId; + + /** + * + */ + private String logisticsName; + + /** + * + */ + private String platform; + + /** + * + */ + private String platformLogisticsName; + + /** + * + */ + private String waybillCodeRule; + + /** + * + */ + private Date gmtCreate; + + /** + * + */ + private Date gmtModified; + + private static final long serialVersionUID = 1L; +} \ No newline at end of file diff --git a/ms-dal/src/main/java/com/ms/dal/mapper/LogisticsMapper.java b/ms-dal/src/main/java/com/ms/dal/mapper/LogisticsMapper.java new file mode 100644 index 0000000..c63d29d --- /dev/null +++ b/ms-dal/src/main/java/com/ms/dal/mapper/LogisticsMapper.java @@ -0,0 +1,32 @@ +package com.ms.dal.mapper; + +import com.ms.dal.entity.Logistics; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Entity com.ms.dal.entity.Logistics + */ +@Mapper +public interface LogisticsMapper { + + int deleteByPrimaryKey(Long id); + + int insert(Logistics record); + + int insertOrUpdate(Logistics record); + + int insertSelective(Logistics record); + + Logistics selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(Logistics record); + + int updateByPrimaryKey(Logistics record); + + List getList(); + + Logistics getByLogisticsName(@Param("logisticsName") String logisticsName); +} diff --git a/ms-dal/src/main/java/com/ms/dal/mapper/LogisticsMatchRuleMapper.java b/ms-dal/src/main/java/com/ms/dal/mapper/LogisticsMatchRuleMapper.java new file mode 100644 index 0000000..d782a64 --- /dev/null +++ b/ms-dal/src/main/java/com/ms/dal/mapper/LogisticsMatchRuleMapper.java @@ -0,0 +1,30 @@ +package com.ms.dal.mapper; + +import com.ms.dal.entity.LogisticsMatchRule; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Entity com.ms.dal.entity.LogisticsMatchRule + */ +@Mapper +public interface LogisticsMatchRuleMapper { + + int deleteByPrimaryKey(Long id); + + int insert(LogisticsMatchRule record); + + int insertOrUpdate(LogisticsMatchRule record); + + int insertSelective(LogisticsMatchRule record); + + LogisticsMatchRule selectByPrimaryKey(Long id); + + int updateByPrimaryKeySelective(LogisticsMatchRule record); + + int updateByPrimaryKey(LogisticsMatchRule record); + + List getListByPlatform(@Param("platform") String platform); +} diff --git a/ms-dal/src/main/resources/mapper/LogisticsMapper.xml b/ms-dal/src/main/resources/mapper/LogisticsMapper.xml new file mode 100644 index 0000000..2958b69 --- /dev/null +++ b/ms-dal/src/main/resources/mapper/LogisticsMapper.xml @@ -0,0 +1,153 @@ + + + + + + + + + + + + + + + + logistics_id,logistics_name,logistics_code, + status,sort,gmt_create, + gmt_modified + + + + + + + + delete from logistics + where logistics_id = #{logisticsId,jdbcType=BIGINT} + + + insert into logistics + ( logistics_id,logistics_name,logistics_code + ,status,sort,gmt_create + ,gmt_modified) + values (#{logisticsId,jdbcType=BIGINT},#{logisticsName,jdbcType=VARCHAR},#{logisticsCode,jdbcType=VARCHAR} + ,#{status,jdbcType=VARCHAR},#{sort,jdbcType=INTEGER},#{gmtCreate,jdbcType=TIMESTAMP} + ,#{gmtModified,jdbcType=TIMESTAMP}) + + + insert into logistics + + logistics_id, + logistics_name, + logistics_code, + status, + sort, + gmt_create, + gmt_modified, + + + #{logisticsId,jdbcType=BIGINT}, + #{logisticsName,jdbcType=VARCHAR}, + #{logisticsCode,jdbcType=VARCHAR}, + #{status,jdbcType=VARCHAR}, + #{sort,jdbcType=INTEGER}, + #{gmtCreate,jdbcType=TIMESTAMP}, + #{gmtModified,jdbcType=TIMESTAMP}, + + ON DUPLICATE KEY UPDATE + + + logistics_name = #{logisticsName,jdbcType=VARCHAR}, + + + logistics_code = #{logisticsCode,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=VARCHAR}, + + + sort = #{sort,jdbcType=INTEGER}, + + + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, + + + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, + + + + + insert into logistics + + logistics_id, + logistics_name, + logistics_code, + status, + sort, + gmt_create, + gmt_modified, + + + #{logisticsId,jdbcType=BIGINT}, + #{logisticsName,jdbcType=VARCHAR}, + #{logisticsCode,jdbcType=VARCHAR}, + #{status,jdbcType=VARCHAR}, + #{sort,jdbcType=INTEGER}, + #{gmtCreate,jdbcType=TIMESTAMP}, + #{gmtModified,jdbcType=TIMESTAMP}, + + + + update logistics + + + logistics_name = #{logisticsName,jdbcType=VARCHAR}, + + + logistics_code = #{logisticsCode,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=VARCHAR}, + + + sort = #{sort,jdbcType=INTEGER}, + + + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, + + + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, + + + where logistics_id = #{logisticsId,jdbcType=BIGINT} + + + update logistics + set + logistics_name = #{logisticsName,jdbcType=VARCHAR}, + logistics_code = #{logisticsCode,jdbcType=VARCHAR}, + status = #{status,jdbcType=VARCHAR}, + sort = #{sort,jdbcType=INTEGER}, + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} + where logistics_id = #{logisticsId,jdbcType=BIGINT} + + diff --git a/ms-dal/src/main/resources/mapper/LogisticsMatchRuleMapper.xml b/ms-dal/src/main/resources/mapper/LogisticsMatchRuleMapper.xml new file mode 100644 index 0000000..f7115a8 --- /dev/null +++ b/ms-dal/src/main/resources/mapper/LogisticsMatchRuleMapper.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + logistics_match_rule_id,logistics_name,platform, + platform_logistics_name,waybill_code_rule,gmt_create, + gmt_modified + + + + + + + delete from logistics_match_rule + where logistics_match_rule_id = #{logisticsMatchRuleId,jdbcType=INTEGER} + + + insert into logistics_match_rule + ( logistics_match_rule_id,logistics_name,platform + ,platform_logistics_name,waybill_code_rule,gmt_create + ,gmt_modified) + values (#{logisticsMatchRuleId,jdbcType=INTEGER},#{logisticsName,jdbcType=VARCHAR},#{platform,jdbcType=VARCHAR} + ,#{platformLogisticsName,jdbcType=VARCHAR},#{waybillCodeRule,jdbcType=VARCHAR},#{gmtCreate,jdbcType=TIMESTAMP} + ,#{gmtModified,jdbcType=TIMESTAMP}) + + + insert into logistics_match_rule + + logistics_match_rule_id, + logistics_name, + platform, + platform_logistics_name, + waybill_code_rule, + gmt_create, + gmt_modified, + + + #{logisticsMatchRuleId,jdbcType=INTEGER}, + #{logisticsName,jdbcType=VARCHAR}, + #{platform,jdbcType=VARCHAR}, + #{platformLogisticsName,jdbcType=VARCHAR}, + #{waybillCodeRule,jdbcType=VARCHAR}, + #{gmtCreate,jdbcType=TIMESTAMP}, + #{gmtModified,jdbcType=TIMESTAMP}, + + ON DUPLICATE KEY UPDATE + + + logistics_name = #{logisticsName,jdbcType=VARCHAR}, + + + platform = #{platform,jdbcType=VARCHAR}, + + + platform_logistics_name = #{platformLogisticsName,jdbcType=VARCHAR}, + + + waybill_code_rule = #{waybillCodeRule,jdbcType=VARCHAR}, + + + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, + + + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, + + + + + insert into logistics_match_rule + + logistics_match_rule_id, + logistics_name, + platform, + platform_logistics_name, + waybill_code_rule, + gmt_create, + gmt_modified, + + + #{logisticsMatchRuleId,jdbcType=INTEGER}, + #{logisticsName,jdbcType=VARCHAR}, + #{platform,jdbcType=VARCHAR}, + #{platformLogisticsName,jdbcType=VARCHAR}, + #{waybillCodeRule,jdbcType=VARCHAR}, + #{gmtCreate,jdbcType=TIMESTAMP}, + #{gmtModified,jdbcType=TIMESTAMP}, + + + + update logistics_match_rule + + + logistics_name = #{logisticsName,jdbcType=VARCHAR}, + + + platform = #{platform,jdbcType=VARCHAR}, + + + platform_logistics_name = #{platformLogisticsName,jdbcType=VARCHAR}, + + + waybill_code_rule = #{waybillCodeRule,jdbcType=VARCHAR}, + + + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, + + + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, + + + where logistics_match_rule_id = #{logisticsMatchRuleId,jdbcType=INTEGER} + + + update logistics_match_rule + set + logistics_name = #{logisticsName,jdbcType=VARCHAR}, + platform = #{platform,jdbcType=VARCHAR}, + platform_logistics_name = #{platformLogisticsName,jdbcType=VARCHAR}, + waybill_code_rule = #{waybillCodeRule,jdbcType=VARCHAR}, + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} + where logistics_match_rule_id = #{logisticsMatchRuleId,jdbcType=INTEGER} + + diff --git a/ms-web/src/main/java/com/ms/web/controller/Test.java b/ms-web/src/main/java/com/ms/web/controller/Test.java index a2fcb16..209c410 100644 --- a/ms-web/src/main/java/com/ms/web/controller/Test.java +++ b/ms-web/src/main/java/com/ms/web/controller/Test.java @@ -59,6 +59,9 @@ public class Test { @Autowired private DsApiService dsApiService; + @Autowired + private LogisticsService logisticsService; + @Autowired private DistributionOrderService distributionOrderService; @@ -263,4 +266,10 @@ public class Test { return ""; } + @GetMapping("/match-rule") + public String matchRule() { + Map result = logisticsService.matchLogisticsInfo("1688DS", "顺丰速运", "SF1610042925672", null); + System.out.println(result); + return result.toString(); + } }