From 0d47d6cead6ad1c56c4bbfdaaab5f54e71c965d3 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 17 Jun 2023 11:59:38 +0800 Subject: [PATCH] =?UTF-8?q?mall=20+=20trade=EF=BC=9Acode=20review=20?= =?UTF-8?q?=E5=BF=AB=E9=80=92=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=EF=BC=8C=E6=B2=A1=E5=95=A5=E9=97=AE=E9=A2=98=E5=92=A7?= =?UTF-8?q?=EF=BC=8C=E6=90=9E=E4=B8=8B=E5=8D=95=E6=B5=8B=E5=B0=B1=20ok=20?= =?UTF-8?q?=E6=8B=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trade/enums/ErrorCodeConstants.java | 7 ++++--- .../delivery/config/ExpressClientConfig.java | 9 +++++---- .../config/TradeExpressProperties.java | 3 ++- .../delivery/core/client/ExpressClient.java | 6 +++--- .../core/client/ExpressClientFactory.java | 5 +++-- .../client/convert/ExpressQueryConvert.java | 12 +++++------ ...qDTO.java => ExpressTrackQueryReqDTO.java} | 4 ++-- ...yRespDTO.java => ExpressTrackRespDTO.java} | 2 +- .../client/impl/ExpressClientFactoryImpl.java | 12 +++++------ .../client/impl/NoProvideExpressClient.java | 8 +++++--- .../impl/{ => kd100}/Kd100ExpressClient.java | 19 ++++++++---------- .../{ => kdniao}/KdNiaoExpressClient.java | 20 ++++++++++--------- .../{client => enums}/ExpressClientEnum.java | 10 ++++------ .../client/impl/Kd100ExpressClientTest.java | 9 ++++++--- .../client/impl/KdNiaoExpressClientTest.java | 10 +++++++--- .../impl/NoProvideExpressClientTest.java | 3 ++- 16 files changed, 74 insertions(+), 65 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/{ExpressQueryReqDTO.java => ExpressTrackQueryReqDTO.java} (87%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/{ExpressQueryRespDTO.java => ExpressTrackRespDTO.java} (91%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/{ => kd100}/Kd100ExpressClient.java (88%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/{ => kdniao}/KdNiaoExpressClient.java (90%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/{client => enums}/ExpressClientEnum.java (68%) diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index ae7a0a501..1b3c73c30 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -53,9 +53,10 @@ public interface ErrorCodeConstants { // ========== 物流 Express 模块 1011004000 ========== ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在"); ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011004001, "已经存在该编码的快递公司"); - ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004002, "快递查询接口异常"); - ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004003, "快递查询返回失败,原因:{}"); - ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004004, "需要接入快递服务商,比如【快递100】"); + ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004002, "需要接入快递服务商,比如【快递100】"); + + ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004101, "快递查询接口异常"); + ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004102, "快递查询返回失败,原因:{}"); // ========== 物流 Template 模块 1011005000 ========== ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011005000, "已经存在该运费模板名"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java index e93c0a70b..2799c3f1c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java @@ -8,13 +8,14 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; /** - * 快递客户端端配置类, 提供快递客户端工厂,默认的快递客户端实现 + * 快递客户端端配置类: + * + * 1. 快递客户端工厂 {@link ExpressClientFactory} + * 2. 默认的快递客户端实现 {@link ExpressClient} * * @author jason */ -@Configuration( - proxyBeanMethods = false -) +@Configuration(proxyBeanMethods = false) public class ExpressClientConfig { @Bean diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java index 5f593df8b..795af0dee 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.trade.framework.delivery.config; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientEnum; +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @@ -27,6 +27,7 @@ public class TradeExpressProperties { * 默认不提供,需要提醒用户配置一个快递服务商。 */ private ExpressClientEnum client = ExpressClientEnum.NOT_PROVIDE; + /** * 快递鸟配置 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java index b670313c5..76b361c3f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import java.util.List; @@ -18,6 +18,6 @@ public interface ExpressClient { * @param reqDTO 查询请求参数 */ // TODO @jason:返回字段可以参考 https://doc.youzanyun.com/detail/API/0/5 响应的 data - List getExpressTrackList(ExpressQueryReqDTO reqDTO); + List getExpressTrackList(ExpressTrackQueryReqDTO reqDTO); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java index f6a54dd8f..5e457092f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client; +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum; + /** - * 快递客户端工厂接口,快递客户端工厂:用于创建和缓存快递客户端 + * 快递客户端工厂接口:用于创建和缓存快递客户端 * * @author jason */ @@ -19,5 +21,4 @@ public interface ExpressClientFactory { */ ExpressClient getOrCreateExpressClient(ExpressClientEnum clientEnum); - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java index 14a2c1c98..1c8f76d73 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.convert; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryReqDTO; @@ -16,12 +16,12 @@ public interface ExpressQueryConvert { ExpressQueryConvert INSTANCE = Mappers.getMapper(ExpressQueryConvert.class); - List convertList(List expressTrackList); + List convertList(List expressTrackList); - List convertList2(List expressTrackList); + List convertList2(List expressTrackList); - KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto); + KdNiaoExpressQueryReqDTO convert(ExpressTrackQueryReqDTO dto); - Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto); + Kd100ExpressQueryReqDTO convert2(ExpressTrackQueryReqDTO dto); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackQueryReqDTO.java similarity index 87% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackQueryReqDTO.java index ea579a170..34ad0128d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackQueryReqDTO.java @@ -4,12 +4,12 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import lombok.Data; /** - * 快递查询 Req DTO + * 快递轨迹的查询 Req DTO * * @author jason */ @Data -public class ExpressQueryReqDTO { +public class ExpressTrackQueryReqDTO { /** * 快递公司编码 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackRespDTO.java similarity index 91% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackRespDTO.java index a2aad9025..b6463ef1d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackRespDTO.java @@ -8,7 +8,7 @@ import lombok.Data; * @author jason */ @Data -public class ExpressQueryRespDTO { +public class ExpressTrackRespDTO { // TODO @jason:LocalDateTime /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java index 96666bfef..d4432b264 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java @@ -2,9 +2,12 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientEnum; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100.Kd100ExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao.KdNiaoExpressClient; +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory; +import lombok.AllArgsConstructor; import org.springframework.web.client.RestTemplate; import java.util.Map; @@ -15,6 +18,7 @@ import java.util.concurrent.ConcurrentHashMap; * * @author jason */ +@AllArgsConstructor public class ExpressClientFactoryImpl implements ExpressClientFactory { private final Map clientMap = new ConcurrentHashMap<>(8); @@ -22,12 +26,6 @@ public class ExpressClientFactoryImpl implements ExpressClientFactory { private final TradeExpressProperties tradeExpressProperties; private final RestTemplate restTemplate; - public ExpressClientFactoryImpl(TradeExpressProperties tradeExpressProperties, - RestTemplate restTemplate) { - this.tradeExpressProperties = tradeExpressProperties; - this.restTemplate = restTemplate; - } - @Override public ExpressClient getDefaultExpressClient() { ExpressClient defaultClient = getOrCreateExpressClient(tradeExpressProperties.getClient()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java index b4b9403a7..7289710f6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import java.util.List; @@ -15,8 +15,10 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_CLI * @author jason */ public class NoProvideExpressClient implements ExpressClient { + @Override - public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { + public List getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) { throw exception(EXPRESS_CLIENT_NOT_PROVIDE); } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java similarity index 88% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java index 930d5d8d9..0b7e1dcbd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.HexUtil; @@ -6,8 +6,8 @@ import cn.hutool.crypto.digest.DigestUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO; import lombok.AllArgsConstructor; @@ -36,29 +36,28 @@ import static cn.iocoder.yudao.module.trade.framework.delivery.core.client.conve public class Kd100ExpressClient implements ExpressClient { private static final String REAL_TIME_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do"; + private final RestTemplate restTemplate; private final TradeExpressProperties.Kd100Config config; @Override - public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { + public List getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) { // 发起查询 Kd100ExpressQueryReqDTO kd100ReqParam = INSTANCE.convert2(reqDTO); kd100ReqParam.setExpressCode(kd100ReqParam.getExpressCode().toLowerCase()); // 快递公司编码需要转成小写 Kd100ExpressQueryRespDTO respDTO = requestExpressQuery(REAL_TIME_QUERY_URL, kd100ReqParam, Kd100ExpressQueryRespDTO.class); log.debug("[getExpressTrackList][快递 100 接口 查询接口返回 {}]", respDTO); + // 处理结果 if (Objects.equals("false", respDTO.getResult())) { log.error("[getExpressTrackList][快递 100 接口 返回失败 {}]", respDTO.getMessage()); throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getMessage()); } - // TODO @jason:convertList2 如果空,应该返回 list 了; @芋艿 为了避免返回 null - if (CollUtil.isNotEmpty(respDTO.getTracks())) { - return INSTANCE.convertList2(respDTO.getTracks()); - } else { + if (CollUtil.isEmpty(respDTO.getTracks())) { return Collections.emptyList(); } - + return INSTANCE.convertList2(respDTO.getTracks()); } /** @@ -85,7 +84,6 @@ public class Kd100ExpressClient implements ExpressClient { log.debug("[sendExpressQueryReq][快递 100 接口的请求参数: {}]", requestBody); // 发送请求 HttpEntity> requestEntity = new HttpEntity<>(requestBody, headers); - // TODO @jason:可以使用 restTemplate 的 post 方法哇 @芋艿 为了获取接口的原始返回。用exchange 便于查问题。 ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class); log.debug("[sendExpressQueryReq][快递 100 接口响应结果 {}]", responseEntity); @@ -98,7 +96,6 @@ public class Kd100ExpressClient implements ExpressClient { private String generateReqSign(String param, String key, String customer) { String plainText = String.format("%s%s%s", param, key, customer); - // TODO @芋艿。 这里需要转换成大写, 没有对应方法 return HexUtil.encodeHexStr(DigestUtil.md5(plainText), false); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kdniao/KdNiaoExpressClient.java similarity index 90% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kdniao/KdNiaoExpressClient.java index 1e5e5f535..52ebf72da 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kdniao/KdNiaoExpressClient.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao; import cn.hutool.core.codec.Base64; import cn.hutool.core.collection.CollUtil; @@ -7,8 +7,8 @@ import cn.hutool.crypto.digest.DigestUtil; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryReqDTO; import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryRespDTO; import lombok.AllArgsConstructor; @@ -51,25 +51,27 @@ public class KdNiaoExpressClient implements ExpressClient { * @param reqDTO 查询请求参数 */ @Override - public List getExpressTrackList(ExpressQueryReqDTO reqDTO) { + public List getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) { KdNiaoExpressQueryReqDTO kdNiaoReqData = INSTANCE.convert(reqDTO); // 快递公司编码需要转成大写 kdNiaoReqData.setExpressCode(reqDTO.getExpressCode().toUpperCase()); KdNiaoExpressQueryRespDTO respDTO = requestKdNiaoApi(REAL_TIME_QUERY_URL, REAL_TIME_FREE_REQ_TYPE, kdNiaoReqData, KdNiaoExpressQueryRespDTO.class); log.debug("[getExpressTrackList][快递鸟即时查询接口返回 {}]", respDTO); + + // 处理结果 if (respDTO == null || !respDTO.getSuccess()) { throw exception(EXPRESS_API_QUERY_FAILED, respDTO == null ? "" : respDTO.getReason()); } if (CollUtil.isNotEmpty(respDTO.getTracks())) { - return INSTANCE.convertList(respDTO.getTracks()); - } else { return Collections.emptyList(); } + return INSTANCE.convertList(respDTO.getTracks()); } /** - * 快递鸟 通用的 API 请求, 暂时没有其他应用场景, 暂时放这里 + * 快递鸟 通用的 API 请求,暂时没有其他应用场景, 暂时放这里 + * * @param url 请求 url * @param requestType 对应的请求指令 (快递鸟的RequestType) * @param req 对应请求的请求参数 @@ -77,8 +79,8 @@ public class KdNiaoExpressClient implements ExpressClient { * @param 每个请求的请求结构 Req DTO * @param 每个请求的响应结构 Resp DTO */ - private Resp requestKdNiaoApi(String url, String requestType, Req req, - Class respClass){ + private Resp requestKdNiaoApi(String url, String requestType, Req req, + Class respClass){ // 请求头 HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/enums/ExpressClientEnum.java similarity index 68% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/enums/ExpressClientEnum.java index 756252e61..81b96184c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/enums/ExpressClientEnum.java @@ -1,5 +1,6 @@ -package cn.iocoder.yudao.module.trade.framework.delivery.core.client; +package cn.iocoder.yudao.module.trade.framework.delivery.core.enums; +import lombok.AllArgsConstructor; import lombok.Getter; /** @@ -8,7 +9,9 @@ import lombok.Getter; * @author jason */ @Getter +@AllArgsConstructor public enum ExpressClientEnum { + NOT_PROVIDE("not-provide","未提供"), KD_NIAO("kd-niao", "快递鸟"), KD_100("kd-100", "快递100"); @@ -17,14 +20,9 @@ public enum ExpressClientEnum { * 快递服务商唯一编码 */ private final String code; - /** * 快递服务商名称 */ private final String name; - ExpressClientEnum(String code, String name) { - this.code = code; - this.name = name; - } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java index 6fa41e314..21b615dd0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java @@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100.Kd100ExpressClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -18,12 +19,14 @@ import javax.annotation.Resource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器 /** * @author jason */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = Kd100ExpressClientTest.Application.class) @ActiveProfiles("unit-test") // 设置使用 trade-delivery-query 配置文件 public class Kd100ExpressClientTest { + @Resource private RestTemplateBuilder builder; @Resource @@ -39,7 +42,7 @@ public class Kd100ExpressClientTest { @Disabled("需要 授权 key. 暂时忽略") void testRealTimeQueryExpressFailed() { ServiceException t = assertThrows(ServiceException.class, () -> { - ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); + ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO(); reqDTO.setExpressCode("yto"); reqDTO.setLogisticsNo("YT9383342193097"); kd100ExpressClient.getExpressTrackList(reqDTO); @@ -53,4 +56,4 @@ public class Kd100ExpressClientTest { @EnableConfigurationProperties(TradeExpressProperties.class) public static class Application { } -} \ No newline at end of file +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java index ebf38d0b7..fc7c6a953 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java @@ -2,7 +2,8 @@ package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl; import cn.iocoder.yudao.framework.common.exception.ServiceException; import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties; -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO; +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao.KdNiaoExpressClient; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -17,13 +18,16 @@ import javax.annotation.Resource; import static org.junit.jupiter.api.Assertions.assertThrows; -// TODO @芋艿:单测最后 review +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器 /** + * {@link KdNiaoExpressClient} 的单元测试 + * * @author jason */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = KdNiaoExpressClientTest.Application.class) @ActiveProfiles("unit-test") public class KdNiaoExpressClientTest { + @Resource private RestTemplateBuilder builder; @Resource @@ -39,7 +43,7 @@ public class KdNiaoExpressClientTest { @Disabled("需要 授权 key. 暂时忽略") void testRealTimeQueryExpressFailed() { assertThrows(ServiceException.class,() ->{ - ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO(); + ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO(); reqDTO.setExpressCode("yy"); reqDTO.setLogisticsNo("YT9383342193097"); kdNiaoExpressClient.getExpressTrackList(reqDTO); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java index 76b8cd6b4..3b60f3645 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器 /** * @author jason */ @@ -49,4 +50,4 @@ public class NoProvideExpressClientTest { return builder.build(); } } -} \ No newline at end of file +}