Commit 0d47d6cead6ad1c56c4bbfdaaab5f54e71c965d3

Authored by YunaiV
1 parent 59d5fef5

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

Showing 16 changed files with 74 additions and 65 deletions
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 {
53 53 // ========== 物流 Express 模块 1011004000 ==========
54 54 ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在");
55 55 ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011004001, "已经存在该编码的快递公司");
56   - ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004002, "快递查询接口异常");
57   - ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004003, "快递查询返回失败,原因:{}");
58   - ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004004, "需要接入快递服务商,比如【快递100】");
  56 + ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004002, "需要接入快递服务商,比如【快递100】");
  57 +
  58 + ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004101, "快递查询接口异常");
  59 + ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004102, "快递查询返回失败,原因:{}");
59 60  
60 61 // ========== 物流 Template 模块 1011005000 ==========
61 62 ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011005000, "已经存在该运费模板名");
... ...
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;
8 8 import org.springframework.web.client.RestTemplate;
9 9  
10 10 /**
11   - * 快递客户端端配置类, 提供快递客户端工厂,默认的快递客户端实现
  11 + * 快递客户端端配置类:
  12 + *
  13 + * 1. 快递客户端工厂 {@link ExpressClientFactory}
  14 + * 2. 默认的快递客户端实现 {@link ExpressClient}
12 15 *
13 16 * @author jason
14 17 */
15   -@Configuration(
16   - proxyBeanMethods = false
17   -)
  18 +@Configuration(proxyBeanMethods = false)
18 19 public class ExpressClientConfig {
19 20  
20 21 @Bean
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/config/TradeExpressProperties.java
1 1 package cn.iocoder.yudao.module.trade.framework.delivery.config;
2 2  
3   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientEnum;
  3 +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum;
4 4 import lombok.Data;
5 5 import org.springframework.boot.context.properties.ConfigurationProperties;
6 6 import org.springframework.stereotype.Component;
... ... @@ -27,6 +27,7 @@ public class TradeExpressProperties {
27 27 * 默认不提供,需要提醒用户配置一个快递服务商。
28 28 */
29 29 private ExpressClientEnum client = ExpressClientEnum.NOT_PROVIDE;
  30 +
30 31 /**
31 32 * 快递鸟配置
32 33 */
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClient.java
1 1 package cn.iocoder.yudao.module.trade.framework.delivery.core.client;
2 2  
3   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO;
4   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO;
  3 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
  4 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
5 5  
6 6 import java.util.List;
7 7  
... ... @@ -18,6 +18,6 @@ public interface ExpressClient {
18 18 * @param reqDTO 查询请求参数
19 19 */
20 20 // TODO @jason:返回字段可以参考 https://doc.youzanyun.com/detail/API/0/5 响应的 data
21   - List<ExpressQueryRespDTO> getExpressTrackList(ExpressQueryReqDTO reqDTO);
  21 + List<ExpressTrackRespDTO> getExpressTrackList(ExpressTrackQueryReqDTO reqDTO);
22 22  
23 23 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientFactory.java
1 1 package cn.iocoder.yudao.module.trade.framework.delivery.core.client;
2 2  
  3 +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum;
  4 +
3 5 /**
4   - * 快递客户端工厂接口,快递客户端工厂:用于创建和缓存快递客户端
  6 + * 快递客户端工厂接口:用于创建和缓存快递客户端
5 7 *
6 8 * @author jason
7 9 */
... ... @@ -19,5 +21,4 @@ public interface ExpressClientFactory {
19 21 */
20 22 ExpressClient getOrCreateExpressClient(ExpressClientEnum clientEnum);
21 23  
22   -
23 24 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/convert/ExpressQueryConvert.java
1 1 package cn.iocoder.yudao.module.trade.framework.delivery.core.client.convert;
2 2  
3   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO;
4   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO;
  3 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
  4 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
5 5 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO;
6 6 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO;
7 7 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryReqDTO;
... ... @@ -16,12 +16,12 @@ public interface ExpressQueryConvert {
16 16  
17 17 ExpressQueryConvert INSTANCE = Mappers.getMapper(ExpressQueryConvert.class);
18 18  
19   - List<ExpressQueryRespDTO> convertList(List<KdNiaoExpressQueryRespDTO.ExpressTrack> expressTrackList);
  19 + List<ExpressTrackRespDTO> convertList(List<KdNiaoExpressQueryRespDTO.ExpressTrack> expressTrackList);
20 20  
21   - List<ExpressQueryRespDTO> convertList2(List<Kd100ExpressQueryRespDTO.ExpressTrack> expressTrackList);
  21 + List<ExpressTrackRespDTO> convertList2(List<Kd100ExpressQueryRespDTO.ExpressTrack> expressTrackList);
22 22  
23   - KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto);
  23 + KdNiaoExpressQueryReqDTO convert(ExpressTrackQueryReqDTO dto);
24 24  
25   - Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto);
  25 + Kd100ExpressQueryReqDTO convert2(ExpressTrackQueryReqDTO dto);
26 26  
27 27 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryReqDTO.java renamed to 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;
4 4 import lombok.Data;
5 5  
6 6 /**
7   - * 快递查询 Req DTO
  7 + * 快递轨迹的查询 Req DTO
8 8 *
9 9 * @author jason
10 10 */
11 11 @Data
12   -public class ExpressQueryReqDTO {
  12 +public class ExpressTrackQueryReqDTO {
13 13  
14 14 /**
15 15 * 快递公司编码
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/ExpressQueryRespDTO.java renamed to 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;
8 8 * @author jason
9 9 */
10 10 @Data
11   -public class ExpressQueryRespDTO {
  11 +public class ExpressTrackRespDTO {
12 12  
13 13 // TODO @jason:LocalDateTime
14 14 /**
... ...
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;
2 2  
3 3 import cn.hutool.core.lang.Assert;
4 4 import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties;
5   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientEnum;
6 5 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient;
  6 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100.Kd100ExpressClient;
  7 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao.KdNiaoExpressClient;
  8 +import cn.iocoder.yudao.module.trade.framework.delivery.core.enums.ExpressClientEnum;
7 9 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClientFactory;
  10 +import lombok.AllArgsConstructor;
8 11 import org.springframework.web.client.RestTemplate;
9 12  
10 13 import java.util.Map;
... ... @@ -15,6 +18,7 @@ import java.util.concurrent.ConcurrentHashMap;
15 18 *
16 19 * @author jason
17 20 */
  21 +@AllArgsConstructor
18 22 public class ExpressClientFactoryImpl implements ExpressClientFactory {
19 23  
20 24 private final Map<ExpressClientEnum, ExpressClient> clientMap = new ConcurrentHashMap<>(8);
... ... @@ -22,12 +26,6 @@ public class ExpressClientFactoryImpl implements ExpressClientFactory {
22 26 private final TradeExpressProperties tradeExpressProperties;
23 27 private final RestTemplate restTemplate;
24 28  
25   - public ExpressClientFactoryImpl(TradeExpressProperties tradeExpressProperties,
26   - RestTemplate restTemplate) {
27   - this.tradeExpressProperties = tradeExpressProperties;
28   - this.restTemplate = restTemplate;
29   - }
30   -
31 29 @Override
32 30 public ExpressClient getDefaultExpressClient() {
33 31 ExpressClient defaultClient = getOrCreateExpressClient(tradeExpressProperties.getClient());
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/NoProvideExpressClient.java
1 1 package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl;
2 2  
3 3 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient;
4   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO;
5   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO;
  4 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
  5 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
6 6  
7 7 import java.util.List;
8 8  
... ... @@ -15,8 +15,10 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.EXPRESS_CLI
15 15 * @author jason
16 16 */
17 17 public class NoProvideExpressClient implements ExpressClient {
  18 +
18 19 @Override
19   - public List<ExpressQueryRespDTO> getExpressTrackList(ExpressQueryReqDTO reqDTO) {
  20 + public List<ExpressTrackRespDTO> getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) {
20 21 throw exception(EXPRESS_CLIENT_NOT_PROVIDE);
21 22 }
  23 +
22 24 }
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClient.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kd100/Kd100ExpressClient.java
1   -package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl;
  1 +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100;
2 2  
3 3 import cn.hutool.core.collection.CollUtil;
4 4 import cn.hutool.core.util.HexUtil;
... ... @@ -6,8 +6,8 @@ import cn.hutool.crypto.digest.DigestUtil;
6 6 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
7 7 import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties;
8 8 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient;
9   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO;
10   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO;
  9 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
  10 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
11 11 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryReqDTO;
12 12 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100.Kd100ExpressQueryRespDTO;
13 13 import lombok.AllArgsConstructor;
... ... @@ -36,29 +36,28 @@ import static cn.iocoder.yudao.module.trade.framework.delivery.core.client.conve
36 36 public class Kd100ExpressClient implements ExpressClient {
37 37  
38 38 private static final String REAL_TIME_QUERY_URL = "https://poll.kuaidi100.com/poll/query.do";
  39 +
39 40 private final RestTemplate restTemplate;
40 41 private final TradeExpressProperties.Kd100Config config;
41 42  
42 43 @Override
43   - public List<ExpressQueryRespDTO> getExpressTrackList(ExpressQueryReqDTO reqDTO) {
  44 + public List<ExpressTrackRespDTO> getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) {
44 45 // 发起查询
45 46 Kd100ExpressQueryReqDTO kd100ReqParam = INSTANCE.convert2(reqDTO);
46 47 kd100ReqParam.setExpressCode(kd100ReqParam.getExpressCode().toLowerCase()); // 快递公司编码需要转成小写
47 48 Kd100ExpressQueryRespDTO respDTO = requestExpressQuery(REAL_TIME_QUERY_URL, kd100ReqParam,
48 49 Kd100ExpressQueryRespDTO.class);
49 50 log.debug("[getExpressTrackList][快递 100 接口 查询接口返回 {}]", respDTO);
  51 +
50 52 // 处理结果
51 53 if (Objects.equals("false", respDTO.getResult())) {
52 54 log.error("[getExpressTrackList][快递 100 接口 返回失败 {}]", respDTO.getMessage());
53 55 throw exception(EXPRESS_API_QUERY_FAILED, respDTO.getMessage());
54 56 }
55   - // TODO @jason:convertList2 如果空,应该返回 list 了; @芋艿 为了避免返回 null
56   - if (CollUtil.isNotEmpty(respDTO.getTracks())) {
57   - return INSTANCE.convertList2(respDTO.getTracks());
58   - } else {
  57 + if (CollUtil.isEmpty(respDTO.getTracks())) {
59 58 return Collections.emptyList();
60 59 }
61   -
  60 + return INSTANCE.convertList2(respDTO.getTracks());
62 61 }
63 62  
64 63 /**
... ... @@ -85,7 +84,6 @@ public class Kd100ExpressClient implements ExpressClient {
85 84 log.debug("[sendExpressQueryReq][快递 100 接口的请求参数: {}]", requestBody);
86 85 // 发送请求
87 86 HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(requestBody, headers);
88   - // TODO @jason:可以使用 restTemplate 的 post 方法哇 @芋艿 为了获取接口的原始返回。用exchange 便于查问题。
89 87 ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
90 88 log.debug("[sendExpressQueryReq][快递 100 接口响应结果 {}]", responseEntity);
91 89  
... ... @@ -98,7 +96,6 @@ public class Kd100ExpressClient implements ExpressClient {
98 96  
99 97 private String generateReqSign(String param, String key, String customer) {
100 98 String plainText = String.format("%s%s%s", param, key, customer);
101   - // TODO @芋艿。 这里需要转换成大写, 没有对应方法
102 99 return HexUtil.encodeHexStr(DigestUtil.md5(plainText), false);
103 100 }
104 101  
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClient.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/kdniao/KdNiaoExpressClient.java
1   -package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl;
  1 +package cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao;
2 2  
3 3 import cn.hutool.core.codec.Base64;
4 4 import cn.hutool.core.collection.CollUtil;
... ... @@ -7,8 +7,8 @@ import cn.hutool.crypto.digest.DigestUtil;
7 7 import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
8 8 import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties;
9 9 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient;
10   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO;
11   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryRespDTO;
  10 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
  11 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
12 12 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryReqDTO;
13 13 import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryRespDTO;
14 14 import lombok.AllArgsConstructor;
... ... @@ -51,25 +51,27 @@ public class KdNiaoExpressClient implements ExpressClient {
51 51 * @param reqDTO 查询请求参数
52 52 */
53 53 @Override
54   - public List<ExpressQueryRespDTO> getExpressTrackList(ExpressQueryReqDTO reqDTO) {
  54 + public List<ExpressTrackRespDTO> getExpressTrackList(ExpressTrackQueryReqDTO reqDTO) {
55 55 KdNiaoExpressQueryReqDTO kdNiaoReqData = INSTANCE.convert(reqDTO);
56 56 // 快递公司编码需要转成大写
57 57 kdNiaoReqData.setExpressCode(reqDTO.getExpressCode().toUpperCase());
58 58 KdNiaoExpressQueryRespDTO respDTO = requestKdNiaoApi(REAL_TIME_QUERY_URL, REAL_TIME_FREE_REQ_TYPE,
59 59 kdNiaoReqData, KdNiaoExpressQueryRespDTO.class);
60 60 log.debug("[getExpressTrackList][快递鸟即时查询接口返回 {}]", respDTO);
  61 +
  62 + // 处理结果
61 63 if (respDTO == null || !respDTO.getSuccess()) {
62 64 throw exception(EXPRESS_API_QUERY_FAILED, respDTO == null ? "" : respDTO.getReason());
63 65 }
64 66 if (CollUtil.isNotEmpty(respDTO.getTracks())) {
65   - return INSTANCE.convertList(respDTO.getTracks());
66   - } else {
67 67 return Collections.emptyList();
68 68 }
  69 + return INSTANCE.convertList(respDTO.getTracks());
69 70 }
70 71  
71 72 /**
72   - * 快递鸟 通用的 API 请求, 暂时没有其他应用场景, 暂时放这里
  73 + * 快递鸟 通用的 API 请求,暂时没有其他应用场景, 暂时放这里
  74 + *
73 75 * @param url 请求 url
74 76 * @param requestType 对应的请求指令 (快递鸟的RequestType)
75 77 * @param req 对应请求的请求参数
... ... @@ -77,8 +79,8 @@ public class KdNiaoExpressClient implements ExpressClient {
77 79 * @param <Req> 每个请求的请求结构 Req DTO
78 80 * @param <Resp> 每个请求的响应结构 Resp DTO
79 81 */
80   - private <Req, Resp> Resp requestKdNiaoApi(String url, String requestType, Req req,
81   - Class<Resp> respClass){
  82 + private <Req, Resp> Resp requestKdNiaoApi(String url, String requestType, Req req,
  83 + Class<Resp> respClass){
82 84 // 请求头
83 85 HttpHeaders headers = new HttpHeaders();
84 86 headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
... ...
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/ExpressClientEnum.java renamed to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/enums/ExpressClientEnum.java
1   -package cn.iocoder.yudao.module.trade.framework.delivery.core.client;
  1 +package cn.iocoder.yudao.module.trade.framework.delivery.core.enums;
2 2  
  3 +import lombok.AllArgsConstructor;
3 4 import lombok.Getter;
4 5  
5 6 /**
... ... @@ -8,7 +9,9 @@ import lombok.Getter;
8 9 * @author jason
9 10 */
10 11 @Getter
  12 +@AllArgsConstructor
11 13 public enum ExpressClientEnum {
  14 +
12 15 NOT_PROVIDE("not-provide","未提供"),
13 16 KD_NIAO("kd-niao", "快递鸟"),
14 17 KD_100("kd-100", "快递100");
... ... @@ -17,14 +20,9 @@ public enum ExpressClientEnum {
17 20 * 快递服务商唯一编码
18 21 */
19 22 private final String code;
20   -
21 23 /**
22 24 * 快递服务商名称
23 25 */
24 26 private final String name;
25 27  
26   - ExpressClientEnum(String code, String name) {
27   - this.code = code;
28   - this.name = name;
29   - }
30 28 }
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.exception.ServiceException;
4 4 import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties;
5   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO;
  5 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
  6 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kd100.Kd100ExpressClient;
6 7 import org.junit.jupiter.api.BeforeEach;
7 8 import org.junit.jupiter.api.Disabled;
8 9 import org.junit.jupiter.api.Test;
... ... @@ -18,12 +19,14 @@ import javax.annotation.Resource;
18 19 import static org.junit.jupiter.api.Assertions.assertEquals;
19 20 import static org.junit.jupiter.api.Assertions.assertThrows;
20 21  
  22 +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器
21 23 /**
22 24 * @author jason
23 25 */
24 26 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = Kd100ExpressClientTest.Application.class)
25 27 @ActiveProfiles("unit-test") // 设置使用 trade-delivery-query 配置文件
26 28 public class Kd100ExpressClientTest {
  29 +
27 30 @Resource
28 31 private RestTemplateBuilder builder;
29 32 @Resource
... ... @@ -39,7 +42,7 @@ public class Kd100ExpressClientTest {
39 42 @Disabled("需要 授权 key. 暂时忽略")
40 43 void testRealTimeQueryExpressFailed() {
41 44 ServiceException t = assertThrows(ServiceException.class, () -> {
42   - ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO();
  45 + ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO();
43 46 reqDTO.setExpressCode("yto");
44 47 reqDTO.setLogisticsNo("YT9383342193097");
45 48 kd100ExpressClient.getExpressTrackList(reqDTO);
... ... @@ -53,4 +56,4 @@ public class Kd100ExpressClientTest {
53 56 @EnableConfigurationProperties(TradeExpressProperties.class)
54 57 public static class Application {
55 58 }
56   -}
57 59 \ No newline at end of file
  60 +}
... ...
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;
2 2  
3 3 import cn.iocoder.yudao.framework.common.exception.ServiceException;
4 4 import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties;
5   -import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressQueryReqDTO;
  5 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackQueryReqDTO;
  6 +import cn.iocoder.yudao.module.trade.framework.delivery.core.client.impl.kdniao.KdNiaoExpressClient;
6 7 import org.junit.jupiter.api.BeforeEach;
7 8 import org.junit.jupiter.api.Disabled;
8 9 import org.junit.jupiter.api.Test;
... ... @@ -17,13 +18,16 @@ import javax.annotation.Resource;
17 18  
18 19 import static org.junit.jupiter.api.Assertions.assertThrows;
19 20  
20   -// TODO @芋艿:单测最后 review
  21 +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器
21 22 /**
  23 + * {@link KdNiaoExpressClient} 的单元测试
  24 + *
22 25 * @author jason
23 26 */
24 27 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = KdNiaoExpressClientTest.Application.class)
25 28 @ActiveProfiles("unit-test")
26 29 public class KdNiaoExpressClientTest {
  30 +
27 31 @Resource
28 32 private RestTemplateBuilder builder;
29 33 @Resource
... ... @@ -39,7 +43,7 @@ public class KdNiaoExpressClientTest {
39 43 @Disabled("需要 授权 key. 暂时忽略")
40 44 void testRealTimeQueryExpressFailed() {
41 45 assertThrows(ServiceException.class,() ->{
42   - ExpressQueryReqDTO reqDTO = new ExpressQueryReqDTO();
  46 + ExpressTrackQueryReqDTO reqDTO = new ExpressTrackQueryReqDTO();
43 47 reqDTO.setExpressCode("yy");
44 48 reqDTO.setLogisticsNo("YT9383342193097");
45 49 kdNiaoExpressClient.getExpressTrackList(reqDTO);
... ...
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;
19 19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 20 import static org.junit.jupiter.api.Assertions.assertThrows;
21 21  
  22 +// TODO @jason:可以参考 AliyunSmsClientTest 写,纯 mockito,无需启动 spring 容器
22 23 /**
23 24 * @author jason
24 25 */
... ... @@ -49,4 +50,4 @@ public class NoProvideExpressClientTest {
49 50 return builder.build();
50 51 }
51 52 }
52   -}
53 53 \ No newline at end of file
  54 +}
... ...