fix:支付通用模块功能逻辑完善,订单模块动态引入逻辑调整
This commit is contained in:
-58
@@ -5,12 +5,7 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||
import com.central.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.feign.WechatConfigService;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||
@@ -22,10 +17,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.cloud.openfeign.FeignAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@@ -74,36 +65,6 @@ public class WechatAutoConfiguration {
|
||||
return new WxPayConfigFactory(configService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(WxPayConfigFactory.class)
|
||||
public Config wxPayConfig(WxPayConfigFactory factory) {
|
||||
return factory.createConfig(getCurrentTenantId());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(WxPayConfigFactory.class)
|
||||
public JsapiServiceExtension jsapiService(WxPayConfigFactory factory) {
|
||||
return factory.createJsapiService(getCurrentTenantId());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(WxPayConfigFactory.class)
|
||||
public NotificationParser notificationParser(WxPayConfigFactory factory) {
|
||||
return factory.createNotificationParser(getCurrentTenantId());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(WxPayConfigFactory.class)
|
||||
public RefundService refundService(WxPayConfigFactory factory) {
|
||||
return factory.createRefundService(getCurrentTenantId());
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(Config.class)
|
||||
public ProfitsharingService profitsharingService(Config config) {
|
||||
return new ProfitsharingService.Builder().config(config).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(WechatConfigService.class)
|
||||
public SettleInfo settleInfo(WechatConfigService configService) {
|
||||
@@ -113,25 +74,6 @@ public class WechatAutoConfiguration {
|
||||
return settleInfo;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(WechatConfigService.class)
|
||||
public Executor profitSharingExecutor(WechatConfigService configService) {
|
||||
log.info("profitSharingExecutor被加载,tenantId:{}", getCurrentTenantId());
|
||||
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
|
||||
if (!config.getAsyncEnabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(config.getAsyncPoolSize());
|
||||
executor.setMaxPoolSize(config.getAsyncPoolSize());
|
||||
executor.setQueueCapacity(100);
|
||||
executor.setThreadNamePrefix("profit-sharing-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
private String getCurrentTenantId() {
|
||||
return "webApp";
|
||||
}
|
||||
|
||||
+41
@@ -8,12 +8,16 @@ import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@@ -25,6 +29,8 @@ public class WxPayConfigFactory {
|
||||
private final Map<String, JsapiServiceExtension> jsapiServiceCache = new ConcurrentHashMap<>();
|
||||
private final Map<String, NotificationParser> notificationParserCache = new ConcurrentHashMap<>();
|
||||
private final Map<String, RefundService> refundServiceCache = new ConcurrentHashMap<>();
|
||||
private final Map<String, ProfitsharingService> profitsharingServiceCache = new ConcurrentHashMap<>();
|
||||
private final Map<String, Executor> executorCache = new ConcurrentHashMap<>();
|
||||
|
||||
public WxPayConfigFactory(WechatConfigService configService) {
|
||||
this.configService = configService;
|
||||
@@ -85,6 +91,37 @@ public class WxPayConfigFactory {
|
||||
return new RefundService.Builder().config(config).build();
|
||||
}
|
||||
|
||||
public ProfitsharingService createProfitsharingService(String tenantId) {
|
||||
return profitsharingServiceCache.computeIfAbsent(tenantId, this::buildProfitsharingService);
|
||||
}
|
||||
|
||||
private ProfitsharingService buildProfitsharingService(String tenantId) {
|
||||
log.info("创建微信分账服务,tenantId:{}", tenantId);
|
||||
Config config = createConfig(tenantId);
|
||||
return new ProfitsharingService.Builder().config(config).build();
|
||||
}
|
||||
|
||||
public Executor createExecutor(String tenantId) {
|
||||
return executorCache.computeIfAbsent(tenantId, this::buildExecutor);
|
||||
}
|
||||
|
||||
private Executor buildExecutor(String tenantId) {
|
||||
log.info("创建分账异步执行器,tenantId:{}", tenantId);
|
||||
WechatConfig config = configService.getConfig("PAY", tenantId);
|
||||
if (!config.getAsyncEnabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(config.getAsyncPoolSize());
|
||||
executor.setMaxPoolSize(config.getAsyncPoolSize());
|
||||
executor.setQueueCapacity(100);
|
||||
executor.setThreadNamePrefix("profit-sharing-" + tenantId + "-");
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除指定租户的缓存
|
||||
*/
|
||||
@@ -93,6 +130,8 @@ public class WxPayConfigFactory {
|
||||
jsapiServiceCache.remove(tenantId);
|
||||
notificationParserCache.remove(tenantId);
|
||||
refundServiceCache.remove(tenantId);
|
||||
profitsharingServiceCache.remove(tenantId);
|
||||
executorCache.remove(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,5 +142,7 @@ public class WxPayConfigFactory {
|
||||
jsapiServiceCache.clear();
|
||||
notificationParserCache.clear();
|
||||
refundServiceCache.clear();
|
||||
profitsharingServiceCache.clear();
|
||||
executorCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user