YunaiV 1 год назад
Родитель
Сommit
ba444c9538

+ 4 - 3
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java

@@ -28,10 +28,11 @@ public interface PayClientFactory {
                                                                   Config config);
 
     /**
-     * 注册支付客户端 Class, 用于模块中实现的 PayClient
+     * 注册支付客户端 Class用于模块中实现的 PayClient
      *
-     * @param payChannelEnum 支付渠道的编码的枚举
+     * @param channel 支付渠道的编码的枚举
      * @param payClientClass 支付客户端 class
      */
-    void registerPayClientClass(PayChannelEnum payChannelEnum, Class<?> payClientClass);
+    void registerPayClientClass(PayChannelEnum channel, Class<?> payClientClass);
+
 }

+ 7 - 7
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java

@@ -27,15 +27,15 @@ public class PayClientFactoryImpl implements PayClientFactory {
 
     /**
      * 支付客户端 Map
+     *
      * key:渠道编号
      */
     private final ConcurrentMap<Long, AbstractPayClient<?>> clients = new ConcurrentHashMap<>();
 
     /**
      * 支付客户端 Class Map
-     * key: 支付渠道的编码的枚举
      */
-    private final Map<PayChannelEnum, Class<?>>clientClass = new ConcurrentHashMap<>(16);
+    private final Map<PayChannelEnum, Class<?>> clientClass = new ConcurrentHashMap<>();
 
     public PayClientFactoryImpl() {
         // 微信支付客户端
@@ -55,6 +55,11 @@ public class PayClientFactoryImpl implements PayClientFactory {
     }
 
     @Override
+    public void registerPayClientClass(PayChannelEnum channel, Class<?> payClientClass) {
+        clientClass.put(channel, payClientClass);
+    }
+
+    @Override
     public PayClient getPayClient(Long channelId) {
         AbstractPayClient<?> client = clients.get(channelId);
         if (client == null) {
@@ -77,11 +82,6 @@ public class PayClientFactoryImpl implements PayClientFactory {
         }
     }
 
-    @Override
-    public void registerPayClientClass(PayChannelEnum payChannelEnum, Class<?> payClientClass) {
-        clientClass.put(payChannelEnum, payClientClass);
-    }
-
     @SuppressWarnings("unchecked")
     private <Config extends PayClientConfig> AbstractPayClient<Config> createPayClient(Long channelId, String channelCode,
                                                                                        Config config) {

+ 5 - 5
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java

@@ -25,7 +25,7 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC
 @Slf4j
 public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
 
-    private PayWalletService client;
+    private PayWalletService wallService;
 
     public WalletPayClient(Long channelId,  NonePayClientConfig config) {
         super(channelId, PayChannelEnum.WALLET.getCode(), config);
@@ -33,15 +33,15 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
 
     @Override
     protected void doInit() {
-        if (client == null) {
-            client = SpringUtil.getBean(PayWalletService.class);
+        if (wallService == null) {
+            wallService = SpringUtil.getBean(PayWalletService.class);
         }
     }
 
     @Override
     protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) {
         try {
-            PayWalletTransactionDO transaction = client.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice());
+            PayWalletTransactionDO transaction = wallService.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice());
             return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(),
                     transaction.getTransactionTime(),
                     reqDTO.getOutTradeNo(), transaction);
@@ -72,7 +72,7 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> {
     @Override
     protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) {
         try {
-            PayWalletTransactionDO payWalletTransaction = client.refund(reqDTO.getOutRefundNo(),
+            PayWalletTransactionDO payWalletTransaction = wallService.refund(reqDTO.getOutRefundNo(),
                     reqDTO.getRefundPrice(), reqDTO.getReason());
             return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getTransactionTime(),
                     reqDTO.getOutRefundNo(), payWalletTransaction);

+ 2 - 0
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java

@@ -65,6 +65,7 @@ public class PayChannelServiceImpl implements PayChannelService {
     public void initLocalCache() {
         // 注册钱包支付 Class
         payClientFactory.registerPayClientClass(PayChannelEnum.WALLET, WalletPayClient.class);
+
         // 注意:忽略自动多租户,因为要全局初始化缓存
         TenantUtils.executeIgnore(() -> {
             // 第一步:查询数据
@@ -78,6 +79,7 @@ public class PayChannelServiceImpl implements PayChannelService {
                 log.error("[支付模块 yudao-module-pay - 表结构未导入][参考 https://doc.iocoder.cn/pay/build/ 开启]");
             }
             log.info("[initLocalCache][缓存支付渠道,数量为:{}]", channels.size());
+
             // 第二步:构建缓存:创建或更新支付 Client
             channels.forEach(payChannel -> payClientFactory.createOrUpdatePayClient(payChannel.getId(),
                     payChannel.getCode(), payChannel.getConfig()));

+ 1 - 0
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java

@@ -45,6 +45,7 @@ public class PayWalletServiceImpl implements  PayWalletService {
     private PayWalletMapper payWalletMapper;
     @Resource
     private PayNoRedisDAO noRedisDAO;
+
     @Resource
     private PayWalletTransactionService payWalletTransactionService;
     @Resource