code review:支付钱包
This commit is contained in:
parent
bca6fb4698
commit
ba444c9538
@ -28,10 +28,11 @@ public interface PayClientFactory {
|
|||||||
Config config);
|
Config config);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册支付客户端 Class, 用于模块中实现的 PayClient
|
* 注册支付客户端 Class,用于模块中实现的 PayClient
|
||||||
*
|
*
|
||||||
* @param payChannelEnum 支付渠道的编码的枚举
|
* @param channel 支付渠道的编码的枚举
|
||||||
* @param payClientClass 支付客户端 class
|
* @param payClientClass 支付客户端 class
|
||||||
*/
|
*/
|
||||||
void registerPayClientClass(PayChannelEnum payChannelEnum, Class<?> payClientClass);
|
void registerPayClientClass(PayChannelEnum channel, Class<?> payClientClass);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,15 +27,15 @@ public class PayClientFactoryImpl implements PayClientFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付客户端 Map
|
* 支付客户端 Map
|
||||||
|
*
|
||||||
* key:渠道编号
|
* key:渠道编号
|
||||||
*/
|
*/
|
||||||
private final ConcurrentMap<Long, AbstractPayClient<?>> clients = new ConcurrentHashMap<>();
|
private final ConcurrentMap<Long, AbstractPayClient<?>> clients = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付客户端 Class Map
|
* 支付客户端 Class Map
|
||||||
* key: 支付渠道的编码的枚举
|
|
||||||
*/
|
*/
|
||||||
private final Map<PayChannelEnum, Class<?>>clientClass = new ConcurrentHashMap<>(16);
|
private final Map<PayChannelEnum, Class<?>> clientClass = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public PayClientFactoryImpl() {
|
public PayClientFactoryImpl() {
|
||||||
// 微信支付客户端
|
// 微信支付客户端
|
||||||
@ -54,6 +54,11 @@ public class PayClientFactoryImpl implements PayClientFactory {
|
|||||||
clientClass.put(MOCK, MockPayClient.class);
|
clientClass.put(MOCK, MockPayClient.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void registerPayClientClass(PayChannelEnum channel, Class<?> payClientClass) {
|
||||||
|
clientClass.put(channel, payClientClass);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PayClient getPayClient(Long channelId) {
|
public PayClient getPayClient(Long channelId) {
|
||||||
AbstractPayClient<?> client = clients.get(channelId);
|
AbstractPayClient<?> client = clients.get(channelId);
|
||||||
@ -77,11 +82,6 @@ public class PayClientFactoryImpl implements PayClientFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void registerPayClientClass(PayChannelEnum payChannelEnum, Class<?> payClientClass) {
|
|
||||||
clientClass.put(payChannelEnum, payClientClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private <Config extends PayClientConfig> AbstractPayClient<Config> createPayClient(Long channelId, String channelCode,
|
private <Config extends PayClientConfig> AbstractPayClient<Config> createPayClient(Long channelId, String channelCode,
|
||||||
Config config) {
|
Config config) {
|
||||||
|
@ -25,7 +25,7 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
||||||
|
|
||||||
private PayWalletService client;
|
private PayWalletService wallService;
|
||||||
|
|
||||||
public WalletPayClient(Long channelId, NonePayClientConfig config) {
|
public WalletPayClient(Long channelId, NonePayClientConfig config) {
|
||||||
super(channelId, PayChannelEnum.WALLET.getCode(), config);
|
super(channelId, PayChannelEnum.WALLET.getCode(), config);
|
||||||
@ -33,15 +33,15 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInit() {
|
protected void doInit() {
|
||||||
if (client == null) {
|
if (wallService == null) {
|
||||||
client = SpringUtil.getBean(PayWalletService.class);
|
wallService = SpringUtil.getBean(PayWalletService.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) {
|
protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) {
|
||||||
try {
|
try {
|
||||||
PayWalletTransactionDO transaction = client.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice());
|
PayWalletTransactionDO transaction = wallService.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice());
|
||||||
return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(),
|
return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(),
|
||||||
transaction.getTransactionTime(),
|
transaction.getTransactionTime(),
|
||||||
reqDTO.getOutTradeNo(), transaction);
|
reqDTO.getOutTradeNo(), transaction);
|
||||||
@ -72,7 +72,7 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
|
|||||||
@Override
|
@Override
|
||||||
protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) {
|
protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) {
|
||||||
try {
|
try {
|
||||||
PayWalletTransactionDO payWalletTransaction = client.refund(reqDTO.getOutRefundNo(),
|
PayWalletTransactionDO payWalletTransaction = wallService.refund(reqDTO.getOutRefundNo(),
|
||||||
reqDTO.getRefundPrice(), reqDTO.getReason());
|
reqDTO.getRefundPrice(), reqDTO.getReason());
|
||||||
return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getTransactionTime(),
|
return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getTransactionTime(),
|
||||||
reqDTO.getOutRefundNo(), payWalletTransaction);
|
reqDTO.getOutRefundNo(), payWalletTransaction);
|
||||||
|
@ -65,6 +65,7 @@ public class PayChannelServiceImpl implements PayChannelService {
|
|||||||
public void initLocalCache() {
|
public void initLocalCache() {
|
||||||
// 注册钱包支付 Class
|
// 注册钱包支付 Class
|
||||||
payClientFactory.registerPayClientClass(PayChannelEnum.WALLET, WalletPayClient.class);
|
payClientFactory.registerPayClientClass(PayChannelEnum.WALLET, WalletPayClient.class);
|
||||||
|
|
||||||
// 注意:忽略自动多租户,因为要全局初始化缓存
|
// 注意:忽略自动多租户,因为要全局初始化缓存
|
||||||
TenantUtils.executeIgnore(() -> {
|
TenantUtils.executeIgnore(() -> {
|
||||||
// 第一步:查询数据
|
// 第一步:查询数据
|
||||||
@ -78,6 +79,7 @@ public class PayChannelServiceImpl implements PayChannelService {
|
|||||||
log.error("[支付模块 yudao-module-pay - 表结构未导入][参考 https://doc.iocoder.cn/pay/build/ 开启]");
|
log.error("[支付模块 yudao-module-pay - 表结构未导入][参考 https://doc.iocoder.cn/pay/build/ 开启]");
|
||||||
}
|
}
|
||||||
log.info("[initLocalCache][缓存支付渠道,数量为:{}]", channels.size());
|
log.info("[initLocalCache][缓存支付渠道,数量为:{}]", channels.size());
|
||||||
|
|
||||||
// 第二步:构建缓存:创建或更新支付 Client
|
// 第二步:构建缓存:创建或更新支付 Client
|
||||||
channels.forEach(payChannel -> payClientFactory.createOrUpdatePayClient(payChannel.getId(),
|
channels.forEach(payChannel -> payClientFactory.createOrUpdatePayClient(payChannel.getId(),
|
||||||
payChannel.getCode(), payChannel.getConfig()));
|
payChannel.getCode(), payChannel.getConfig()));
|
||||||
|
@ -45,6 +45,7 @@ public class PayWalletServiceImpl implements PayWalletService {
|
|||||||
private PayWalletMapper payWalletMapper;
|
private PayWalletMapper payWalletMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private PayNoRedisDAO noRedisDAO;
|
private PayNoRedisDAO noRedisDAO;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PayWalletTransactionService payWalletTransactionService;
|
private PayWalletTransactionService payWalletTransactionService;
|
||||||
@Resource
|
@Resource
|
||||||
|
Loading…
Reference in New Issue
Block a user