Ver código fonte

mall + trade:code review 快递客户端的实现,没啥问题咧,搞下单测就 ok 拉

YunaiV 2 anos atrás
pai
commit
0d47d6cead
16 arquivos alterados com 74 adições e 65 exclusões
  1. 4 3
      yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java
  2. 5 4
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/ExpressClientConfig.java
  3. 2 1
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java
  4. 3 3
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java
  5. 3 2
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java
  6. 6 6
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java
  7. 2 2
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackQueryReqDTO.java
  8. 1 1
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressTrackRespDTO.java
  9. 5 7
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/ExpressClientFactoryImpl.java
  10. 5 3
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java
  11. 8 11
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java
  12. 11 9
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kdniao/KdNiaoExpressClient.java
  13. 4 6
      yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/enums/ExpressClientEnum.java
  14. 6 3
      yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java
  15. 7 3
      yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java
  16. 2 1
      yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClientTest.java

+ 4 - 3
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, "已经存在该运费模板名");

+ 5 - 4
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

+ 2 - 1
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;
+
     /**
      * 快递鸟配置
      */

+ 3 - 3
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<ExpressQueryRespDTO> getExpressTrackList(ExpressQueryReqDTO reqDTO);
+    List<ExpressTrackRespDTO> getExpressTrackList(ExpressTrackQueryReqDTO reqDTO);
 
 }

+ 3 - 2
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);
 
-
 }

+ 6 - 6
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<ExpressQueryRespDTO> convertList(List<KdNiaoExpressQueryRespDTO.ExpressTrack> expressTrackList);
+    List<ExpressTrackRespDTO> convertList(List<KdNiaoExpressQueryRespDTO.ExpressTrack> expressTrackList);
 
-    List<ExpressQueryRespDTO> convertList2(List<Kd100ExpressQueryRespDTO.ExpressTrack> expressTrackList);
+    List<ExpressTrackRespDTO> convertList2(List<Kd100ExpressQueryRespDTO.ExpressTrack> expressTrackList);
 
-    KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto);
+    KdNiaoExpressQueryReqDTO convert(ExpressTrackQueryReqDTO dto);
 
-    Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto);
+    Kd100ExpressQueryReqDTO convert2(ExpressTrackQueryReqDTO dto);
 
 }

+ 2 - 2
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java → 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 {
 
     /**
      * 快递公司编码

+ 1 - 1
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java → 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
     /**

+ 5 - 7
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<ExpressClientEnum, ExpressClient> 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());

+ 5 - 3
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<ExpressQueryRespDTO> getExpressTrackList(ExpressQueryReqDTO reqDTO) {
+    public List<ExpressTrackRespDTO> getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) {
         throw exception(EXPRESS_CLIENT_NOT_PROVIDE);
     }
+
 }

+ 8 - 11
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java → 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<ExpressQueryRespDTO> getExpressTrackList(ExpressQueryReqDTO reqDTO) {
+    public List<ExpressTrackRespDTO> 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<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(requestBody, headers);
-        // TODO @jason:可以使用 restTemplate 的 post 方法哇 @芋艿 为了获取接口的原始返回。用exchange 便于查问题。
         ResponseEntity<String> 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);
     }
 

+ 11 - 9
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java → 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<ExpressQueryRespDTO> getExpressTrackList(ExpressQueryReqDTO reqDTO) {
+    public List<ExpressTrackRespDTO> 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> 每个请求的请求结构 Req DTO
      * @param <Resp> 每个请求的响应结构 Resp DTO
      */
-    private  <Req, Resp> Resp requestKdNiaoApi(String url, String requestType, Req req,
-                                               Class<Resp> respClass){
+    private <Req, Resp> Resp requestKdNiaoApi(String url, String requestType, Req req,
+                                              Class<Resp> respClass){
         // 请求头
         HttpHeaders headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

+ 4 - 6
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java → 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;
-    }
 }

+ 6 - 3
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 {
     }
-}
+}

+ 7 - 3
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);

+ 2 - 1
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();
         }
     }
-}
+}