快递客户端 review 修改
parent
e69e6d880b
commit
1662d17fc9
@ -1,22 +0,0 @@
|
||||
package cn.iocoder.yudao.module.trade.framework.delivery.core;
|
||||
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 快递查询服务商
|
||||
*
|
||||
* @author jason
|
||||
*/
|
||||
public interface ExpressQueryProvider {
|
||||
|
||||
/**
|
||||
* 快递实时查询
|
||||
*
|
||||
* @param reqDTO 查询请求参数
|
||||
*/
|
||||
List<ExpressQueryRespDTO> realTimeQueryExpress(ExpressQueryReqDTO reqDTO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
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.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;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao.KdNiaoExpressQueryRespDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ExpressQueryConvert {
|
||||
|
||||
ExpressQueryConvert INSTANCE = Mappers.getMapper(ExpressQueryConvert.class);
|
||||
|
||||
List<ExpressQueryRespDTO> convertList(List<KdNiaoExpressQueryRespDTO.ExpressTrack> expressTrackList);
|
||||
|
||||
List<ExpressQueryRespDTO> convertList2(List<Kd100ExpressQueryRespDTO.ExpressTrack> expressTrackList);
|
||||
|
||||
KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto);
|
||||
|
||||
Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto);
|
||||
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.trade.framework.delivery.core.dto;
|
||||
package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
5
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java → yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryReqDTO.java
5
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryReqDTO.java → yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryReqDTO.java
2
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java → yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryRespDTO.java
2
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kd100/Kd100ExpressQueryRespDTO.java → yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kd100/Kd100ExpressQueryRespDTO.java
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100;
|
||||
package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kd100;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
5
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java → yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryReqDTO.java
5
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryReqDTO.java → yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryReqDTO.java
2
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java → yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryRespDTO.java
2
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/dto/provider/kdniao/KdNiaoExpressQueryRespDTO.java → yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/dto/kdniao/KdNiaoExpressQueryRespDTO.java
@ -1,4 +1,4 @@
|
||||
package cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao;
|
||||
package cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.kdniao;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
@ -0,0 +1,56 @@
|
||||
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.ExpressClientFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 快递客户端工厂实现类
|
||||
*
|
||||
* @author jason
|
||||
*/
|
||||
public class ExpressClientFactoryImpl implements ExpressClientFactory {
|
||||
|
||||
private final Map<ExpressClientEnum, ExpressClient> clientMap = new ConcurrentHashMap<>(8);
|
||||
|
||||
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());
|
||||
Assert.notNull("默认的快递客户端不能为空");
|
||||
return defaultClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExpressClient getOrCreateExpressClient(ExpressClientEnum clientEnum) {
|
||||
return clientMap.computeIfAbsent(clientEnum,
|
||||
client -> createExpressClient(client, tradeExpressProperties));
|
||||
}
|
||||
|
||||
private ExpressClient createExpressClient(ExpressClientEnum queryProviderEnum,
|
||||
TradeExpressProperties tradeExpressProperties) {
|
||||
switch (queryProviderEnum) {
|
||||
case NOT_PROVIDE:
|
||||
return new NoProvideExpressClient();
|
||||
case KD_NIAO:
|
||||
return new KdNiaoExpressClient(restTemplate, tradeExpressProperties.getKdNiao());
|
||||
case KD_100:
|
||||
return new Kd100ExpressClient(restTemplate, tradeExpressProperties.getKd100());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
package cn.iocoder.yudao.module.trade.framework.delivery.core.convert;
|
||||
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.ExpressQueryRespDTO;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kd100.Kd100ExpressQueryRespDTO;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryReqDTO;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.dto.provider.kdniao.KdNiaoExpressQueryRespDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ExpressQueryConvert {
|
||||
|
||||
ExpressQueryConvert INSTANCE = Mappers.getMapper(ExpressQueryConvert.class);
|
||||
|
||||
List<ExpressQueryRespDTO> convertList(List<KdNiaoExpressQueryRespDTO.ExpressTrack> expressTrackList);
|
||||
|
||||
List<ExpressQueryRespDTO> convertList2(List<Kd100ExpressQueryRespDTO.ExpressTrack> expressTrackList);
|
||||
|
||||
KdNiaoExpressQueryReqDTO convert(ExpressQueryReqDTO dto);
|
||||
|
||||
Kd100ExpressQueryReqDTO convert2(ExpressQueryReqDTO dto);
|
||||
|
||||
}
|
||||
26
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java → yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java
26
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/Kd100ExpressQueryProviderTest.java → yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/Kd100ExpressClientTest.java
24
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java → yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java
24
yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/impl/KdNiaoExpressQueryProviderTest.java → yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/framework/delivery/core/client/impl/KdNiaoExpressClientTest.java
@ -0,0 +1,52 @@
|
||||
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.ExpressClientConfig;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.config.TradeExpressProperties;
|
||||
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.ExpressClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.web.client.RestTemplateBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author jason
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = NoProvideExpressClientTest.Application.class)
|
||||
@ActiveProfiles("unit-test") // 设置使用 trade-delivery-query 配置文件
|
||||
@Import({ExpressClientConfig.class})
|
||||
public class NoProvideExpressClientTest {
|
||||
|
||||
@Resource
|
||||
private ExpressClient expressClient;
|
||||
|
||||
@Test
|
||||
void getExpressTrackList() {
|
||||
ServiceException t = assertThrows(ServiceException.class, () -> {
|
||||
expressClient.getExpressTrackList(null);
|
||||
});
|
||||
assertEquals(1011003006, t.getCode());
|
||||
}
|
||||
|
||||
@Import({
|
||||
RestTemplateAutoConfiguration.class,
|
||||
})
|
||||
@EnableConfigurationProperties(TradeExpressProperties.class)
|
||||
public static class Application {
|
||||
|
||||
@Bean
|
||||
private RestTemplate restTemplate(RestTemplateBuilder builder) {
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
spring:
|
||||
main:
|
||||
lazy-initialization: true # 开启懒加载,加快速度
|
||||
banner-mode: off # 单元测试,禁用 Banner
|
||||
|
||||
--- #################### 交易快递查询相关配置 ####################
|
||||
|
||||
yudao:
|
||||
trade:
|
||||
express:
|
||||
query:
|
||||
express-query-provider: kd_niao
|
||||
kd-niao:
|
||||
api-key: xxx
|
||||
business-id: xxxxxxxx
|
||||
kd100:
|
||||
customer: xxxx
|
||||
key: xxxxx
|
||||
Loading…
Reference in New Issue