123
This commit is contained in:
@@ -20,55 +20,22 @@ import java.util.stream.Collectors;
|
||||
@Component
|
||||
@Slf4j
|
||||
public class PayConfigManager {
|
||||
private static final Map<Long,PayConfig> PAY_CONFIGS_MAP = new ConcurrentHashMap<>();
|
||||
@Autowired
|
||||
private PayConfigService payConfigService;
|
||||
@Autowired
|
||||
private PayTotalService payTotalService;
|
||||
@Autowired
|
||||
private CaiProperties caiProperties;
|
||||
private PayConfigService payConfigService;
|
||||
|
||||
@PostConstruct
|
||||
public void init(){
|
||||
if(caiProperties.isWebsocket()){
|
||||
return;
|
||||
}
|
||||
List<PayConfig> list = payConfigService.list(Wrappers.lambdaQuery(PayConfig.class));
|
||||
for (PayConfig payConfig : list) {
|
||||
PAY_CONFIGS_MAP.put(payConfig.getId(), payConfig);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<PayConfig> getAllPayConfig(){
|
||||
return PAY_CONFIGS_MAP.values();
|
||||
}
|
||||
|
||||
// 1支付宝2微信
|
||||
public void addPayConfig(PayConfig payConfig) {
|
||||
PAY_CONFIGS_MAP.put(payConfig.getId(),payConfig);
|
||||
}
|
||||
|
||||
public void updatePayConfig(PayConfig payConfig) {
|
||||
PAY_CONFIGS_MAP.put(payConfig.getId(),payConfig);
|
||||
if(PayTypeEnum.ALI.getCode().equals(payConfig.getPayType())){
|
||||
AliPayApiConfigKit.removeApiConfig(payConfig.getAppid());
|
||||
}
|
||||
}
|
||||
|
||||
public void deletePayConfig(PayConfig payConfig) {
|
||||
PAY_CONFIGS_MAP.remove(payConfig.getId());
|
||||
public void deletePayConfigAli(PayConfig payConfig) {
|
||||
if(PayTypeEnum.ALI.getCode().equals(payConfig.getPayType())){
|
||||
AliPayApiConfigKit.removeApiConfig(payConfig.getAppid());
|
||||
}
|
||||
}
|
||||
|
||||
public PayConfig getWxConfig(){
|
||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
||||
List<PayConfig> values = payConfigService.listOkByPayType(PayTypeEnum.WX);
|
||||
Map<String,PayConfig> using = new HashMap<>();
|
||||
for (PayConfig value : values) {
|
||||
if(value.getEnableStatus().equals(1) && PayTypeEnum.WX.getCode().equals(value.getPayType())){
|
||||
using.put(value.getWxMcid(),value);
|
||||
}
|
||||
using.put(value.getWxMcid(),value);
|
||||
}
|
||||
if(using.isEmpty()){
|
||||
return null;
|
||||
@@ -87,12 +54,10 @@ public class PayConfigManager {
|
||||
}
|
||||
|
||||
public PayConfig getAliConfig(){
|
||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
||||
List<PayConfig> values = payConfigService.listOkByPayType(PayTypeEnum.ALI);
|
||||
Map<String,PayConfig> using = new HashMap<>();
|
||||
for (PayConfig value : values) {
|
||||
if(value.getEnableStatus().equals(1) && PayTypeEnum.ALI.getCode().equals(value.getPayType())){
|
||||
using.put(value.getWxMcid(),value);
|
||||
}
|
||||
using.put(value.getWxMcid(),value);
|
||||
}
|
||||
if(using.isEmpty()){
|
||||
return null;
|
||||
@@ -136,22 +101,12 @@ public class PayConfigManager {
|
||||
}
|
||||
|
||||
public PayConfig getAliConfigByAppId(String appId) {
|
||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
||||
for (PayConfig value : values) {
|
||||
if(value.getAppid() != null && value.getAppid().equals(appId)){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return payConfigService.getOne(Wrappers.lambdaQuery(PayConfig.class).eq(PayConfig::getAppid, appId)
|
||||
.last("limit 1"));
|
||||
}
|
||||
|
||||
public PayConfig getWxConfigByMchId(String mchId) {
|
||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
||||
for (PayConfig value : values) {
|
||||
if(value.getWxMcid() != null && value.getWxMcid().equals(mchId)){
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return payConfigService.getOne(Wrappers.lambdaQuery(PayConfig.class).eq(PayConfig::getWxMcid, mchId)
|
||||
.last("limit 1"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.ruoyi.cai.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cai.domain.PayConfig;
|
||||
import com.ruoyi.cai.pay.PayTypeEnum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付配置Service接口
|
||||
@@ -11,9 +14,13 @@ import com.ruoyi.cai.domain.PayConfig;
|
||||
*/
|
||||
public interface PayConfigService extends IService<PayConfig> {
|
||||
|
||||
List<PayConfig> listOkByPayType(PayTypeEnum payType);
|
||||
|
||||
boolean addPayConfig(PayConfig payConfig);
|
||||
|
||||
boolean updatePayConfig(PayConfig payConfig);
|
||||
|
||||
boolean deletePayConfig(Long id);
|
||||
|
||||
void updateStatus(Long id, Integer enableStatus);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付配置Service业务层处理
|
||||
*
|
||||
@@ -24,6 +26,13 @@ public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper,PayConfig>
|
||||
@Autowired
|
||||
private PayConfigManager payConfigManager;
|
||||
|
||||
@Override
|
||||
public List<PayConfig> listOkByPayType(PayTypeEnum payType){
|
||||
return this.list(Wrappers.lambdaQuery(PayConfig.class)
|
||||
.eq(PayConfig::getPayType, payType)
|
||||
.eq(PayConfig::getEnableStatus,1));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean addPayConfig(PayConfig payConfig){
|
||||
@@ -41,11 +50,7 @@ public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper,PayConfig>
|
||||
throw new ServiceException("检测到已经存在的微信商户ID,无法重复添加");
|
||||
}
|
||||
}
|
||||
boolean save = this.save(payConfig);
|
||||
if(save){
|
||||
payConfigManager.addPayConfig(payConfig);
|
||||
}
|
||||
return save;
|
||||
return this.save(payConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,7 +75,7 @@ public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper,PayConfig>
|
||||
boolean update = this.updateById(payConfig);
|
||||
if(update){
|
||||
payConfig = this.getById(payConfig.getId());
|
||||
payConfigManager.updatePayConfig(payConfig);
|
||||
payConfigManager.deletePayConfigAli(payConfig);
|
||||
}
|
||||
return update;
|
||||
}
|
||||
@@ -84,10 +89,24 @@ public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper,PayConfig>
|
||||
}
|
||||
boolean b = this.removeById(id);
|
||||
if(b){
|
||||
payConfigManager.deletePayConfig(payConfig);
|
||||
payConfigManager.deletePayConfigAli(payConfig);
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Long id, Integer enableStatus) {
|
||||
if(enableStatus == null){
|
||||
return;
|
||||
}
|
||||
this.update(Wrappers.lambdaUpdate(PayConfig.class)
|
||||
.eq(PayConfig::getId,id)
|
||||
.set(PayConfig::getEnableStatus, enableStatus));
|
||||
PayConfig payConfig = this.getById(id);
|
||||
if(enableStatus == 0){
|
||||
payConfigManager.deletePayConfigAli(payConfig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user