123
This commit is contained in:
@@ -79,6 +79,16 @@ public class PayConfigController extends BaseController {
|
|||||||
return toAjax(payConfigService.updatePayConfig(bo));
|
return toAjax(payConfigService.updatePayConfig(bo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SaCheckPermission("cai:payConfig:edit")
|
||||||
|
@Log(title = "开启和关闭支付配置", businessType = BusinessType.UPDATE)
|
||||||
|
@RepeatSubmit()
|
||||||
|
@PutMapping("/status")
|
||||||
|
public R<Void> status(@Validated(EditGroup.class) @RequestBody PayConfig bo) {
|
||||||
|
payConfigService.updateStatus(bo.getId(),bo.getEnableStatus());
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@SaCheckPermission("cai:payConfig:remove")
|
@SaCheckPermission("cai:payConfig:remove")
|
||||||
@Log(title = "支付配置", businessType = BusinessType.DELETE)
|
@Log(title = "支付配置", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class PayController {
|
|||||||
PayConfig payConfig = payConfigManager.getWxConfig();
|
PayConfig payConfig = payConfigManager.getWxConfig();
|
||||||
if(payConfig == null){
|
if(payConfig == null){
|
||||||
log.error("支付失败,未找到可用的微信支付配置");
|
log.error("支付失败,未找到可用的微信支付配置");
|
||||||
return R.fail(600,"支付失败,未找到可用的微信支付");
|
return R.fail(600,"支付失败,未开通微信支付");
|
||||||
}
|
}
|
||||||
String ip = ServletUtils.getClientIP();
|
String ip = ServletUtils.getClientIP();
|
||||||
Map<String, String> params = UnifiedOrderModel
|
Map<String, String> params = UnifiedOrderModel
|
||||||
@@ -113,7 +113,7 @@ public class PayController {
|
|||||||
boolean b = payConfigManager.initAliPay();
|
boolean b = payConfigManager.initAliPay();
|
||||||
if(!b){
|
if(!b){
|
||||||
log.error("支付失败,未找到可用的支付宝配置");
|
log.error("支付失败,未找到可用的支付宝配置");
|
||||||
return R.fail(600,"支付宝支付失败!请联系管理员");
|
return R.fail(600,"支付失败!未开通支付宝支付!");
|
||||||
}
|
}
|
||||||
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
|
||||||
model.setBody(payOrderInfo.getBody());
|
model.setBody(payOrderInfo.getBody());
|
||||||
|
|||||||
@@ -20,56 +20,23 @@ import java.util.stream.Collectors;
|
|||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class PayConfigManager {
|
public class PayConfigManager {
|
||||||
private static final Map<Long,PayConfig> PAY_CONFIGS_MAP = new ConcurrentHashMap<>();
|
|
||||||
@Autowired
|
|
||||||
private PayConfigService payConfigService;
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private PayTotalService payTotalService;
|
private PayTotalService payTotalService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CaiProperties caiProperties;
|
private PayConfigService payConfigService;
|
||||||
|
|
||||||
@PostConstruct
|
public void deletePayConfigAli(PayConfig payConfig) {
|
||||||
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());
|
|
||||||
if(PayTypeEnum.ALI.getCode().equals(payConfig.getPayType())){
|
if(PayTypeEnum.ALI.getCode().equals(payConfig.getPayType())){
|
||||||
AliPayApiConfigKit.removeApiConfig(payConfig.getAppid());
|
AliPayApiConfigKit.removeApiConfig(payConfig.getAppid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PayConfig getWxConfig(){
|
public PayConfig getWxConfig(){
|
||||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
List<PayConfig> values = payConfigService.listOkByPayType(PayTypeEnum.WX);
|
||||||
Map<String,PayConfig> using = new HashMap<>();
|
Map<String,PayConfig> using = new HashMap<>();
|
||||||
for (PayConfig value : values) {
|
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()){
|
if(using.isEmpty()){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -87,13 +54,11 @@ public class PayConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PayConfig getAliConfig(){
|
public PayConfig getAliConfig(){
|
||||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
List<PayConfig> values = payConfigService.listOkByPayType(PayTypeEnum.ALI);
|
||||||
Map<String,PayConfig> using = new HashMap<>();
|
Map<String,PayConfig> using = new HashMap<>();
|
||||||
for (PayConfig value : values) {
|
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()){
|
if(using.isEmpty()){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -136,22 +101,12 @@ public class PayConfigManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PayConfig getAliConfigByAppId(String appId) {
|
public PayConfig getAliConfigByAppId(String appId) {
|
||||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
return payConfigService.getOne(Wrappers.lambdaQuery(PayConfig.class).eq(PayConfig::getAppid, appId)
|
||||||
for (PayConfig value : values) {
|
.last("limit 1"));
|
||||||
if(value.getAppid() != null && value.getAppid().equals(appId)){
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public PayConfig getWxConfigByMchId(String mchId) {
|
public PayConfig getWxConfigByMchId(String mchId) {
|
||||||
Collection<PayConfig> values = PAY_CONFIGS_MAP.values();
|
return payConfigService.getOne(Wrappers.lambdaQuery(PayConfig.class).eq(PayConfig::getWxMcid, mchId)
|
||||||
for (PayConfig value : values) {
|
.last("limit 1"));
|
||||||
if(value.getWxMcid() != null && value.getWxMcid().equals(mchId)){
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package com.ruoyi.cai.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.ruoyi.cai.domain.PayConfig;
|
import com.ruoyi.cai.domain.PayConfig;
|
||||||
|
import com.ruoyi.cai.pay.PayTypeEnum;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付配置Service接口
|
* 支付配置Service接口
|
||||||
@@ -11,9 +14,13 @@ import com.ruoyi.cai.domain.PayConfig;
|
|||||||
*/
|
*/
|
||||||
public interface PayConfigService extends IService<PayConfig> {
|
public interface PayConfigService extends IService<PayConfig> {
|
||||||
|
|
||||||
|
List<PayConfig> listOkByPayType(PayTypeEnum payType);
|
||||||
|
|
||||||
boolean addPayConfig(PayConfig payConfig);
|
boolean addPayConfig(PayConfig payConfig);
|
||||||
|
|
||||||
boolean updatePayConfig(PayConfig payConfig);
|
boolean updatePayConfig(PayConfig payConfig);
|
||||||
|
|
||||||
boolean deletePayConfig(Long id);
|
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.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支付配置Service业务层处理
|
* 支付配置Service业务层处理
|
||||||
*
|
*
|
||||||
@@ -24,6 +26,13 @@ public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper,PayConfig>
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PayConfigManager payConfigManager;
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean addPayConfig(PayConfig payConfig){
|
public boolean addPayConfig(PayConfig payConfig){
|
||||||
@@ -41,11 +50,7 @@ public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper,PayConfig>
|
|||||||
throw new ServiceException("检测到已经存在的微信商户ID,无法重复添加");
|
throw new ServiceException("检测到已经存在的微信商户ID,无法重复添加");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean save = this.save(payConfig);
|
return this.save(payConfig);
|
||||||
if(save){
|
|
||||||
payConfigManager.addPayConfig(payConfig);
|
|
||||||
}
|
|
||||||
return save;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -70,7 +75,7 @@ public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper,PayConfig>
|
|||||||
boolean update = this.updateById(payConfig);
|
boolean update = this.updateById(payConfig);
|
||||||
if(update){
|
if(update){
|
||||||
payConfig = this.getById(payConfig.getId());
|
payConfig = this.getById(payConfig.getId());
|
||||||
payConfigManager.updatePayConfig(payConfig);
|
payConfigManager.deletePayConfigAli(payConfig);
|
||||||
}
|
}
|
||||||
return update;
|
return update;
|
||||||
}
|
}
|
||||||
@@ -84,10 +89,24 @@ public class PayConfigServiceImpl extends ServiceImpl<PayConfigMapper,PayConfig>
|
|||||||
}
|
}
|
||||||
boolean b = this.removeById(id);
|
boolean b = this.removeById(id);
|
||||||
if(b){
|
if(b){
|
||||||
payConfigManager.deletePayConfig(payConfig);
|
payConfigManager.deletePayConfigAli(payConfig);
|
||||||
}
|
}
|
||||||
return b;
|
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