2
0

feat: 支付全局配置

This commit is contained in:
caiyuchao
2025-04-23 17:41:51 +08:00
parent 45d78ed7d3
commit 9a4eaddc50
9 changed files with 187 additions and 10 deletions

View File

@@ -42,6 +42,26 @@ public class CacheConstants
*/
public static final String SYS_CONFIG_KEY = "sys_config:";
/**
* 支付参数管理 cache key
*/
public static final String SYS_PAY_CONFIG_KEY = "sys_pay_config";
/**
* 支付参数管理 currency cache key
*/
public static final String SYS_PAY_CURRENCY_KEY = "currency";
/**
* 支付参数管理 currency_symbol cache key
*/
public static final String SYS_PAY_CURRENCY_SYMBOL_KEY = "currency_symbol";
/**
* 支付参数管理 currency_symbol cache key
*/
public static final String SYS_PAY_PAYMENT_METHOD_KEY = "payment_methods";
/**
* 字典管理 cache key
*/

View File

@@ -1,7 +1,5 @@
package org.wfc.system.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
@@ -12,6 +10,7 @@ import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wfc.common.core.domain.R;
import org.wfc.common.core.utils.MessageUtils;
import org.wfc.common.core.utils.poi.ExcelUtil;
import org.wfc.common.core.web.controller.BaseController;
@@ -22,8 +21,12 @@ import org.wfc.common.log.enums.BusinessType;
import org.wfc.common.security.annotation.RequiresPermissions;
import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.system.domain.SysConfig;
import org.wfc.system.domain.bo.SysPayConfigBo;
import org.wfc.system.service.ISysConfigService;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* 参数配置 信息操作处理
*
@@ -36,6 +39,22 @@ public class SysConfigController extends BaseController
@Autowired
private ISysConfigService configService;
@GetMapping("/pay")
public R<SysPayConfigBo> getPayConfig()
{
SysPayConfigBo result = configService.getPayConfig();
return R.ok(result);
}
@PutMapping("/pay")
public R<Boolean> setPayConfig(@RequestBody SysPayConfigBo config)
{
boolean result = configService.setPayConfig(config);
return R.ok(result);
}
/**
* 获取参数配置列表
*/

View File

@@ -0,0 +1,18 @@
package org.wfc.system.domain.bo;
import lombok.Data;
import java.util.List;
/**
* @description: 支付配置bo
* @author: cyc
* @since: 2025-04-23
*/
@Data
public class SysPayConfigBo {
private String currency;
private String currencySymbol;
private List<String> paymentMethods;
}

View File

@@ -1,7 +1,9 @@
package org.wfc.system.service;
import java.util.List;
import org.wfc.system.domain.SysConfig;
import org.wfc.system.domain.bo.SysPayConfigBo;
import java.util.List;
/**
* 参数配置 服务层
@@ -10,6 +12,11 @@ import org.wfc.system.domain.SysConfig;
*/
public interface ISysConfigService
{
SysPayConfigBo getPayConfig();
boolean setPayConfig(SysPayConfigBo configBo);
/**
* 查询参数配置信息
*

View File

@@ -1,20 +1,27 @@
package org.wfc.system.service.impl;
import java.util.Collection;
import java.util.List;
import javax.annotation.PostConstruct;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wfc.common.core.constant.CacheConstants;
import org.wfc.common.core.constant.UserConstants;
import org.wfc.common.core.exception.ServiceException;
import org.wfc.common.core.text.Convert;
import org.wfc.common.core.utils.MessageUtils;
import org.wfc.common.core.utils.StringUtils;
import org.wfc.common.redis.service.RedisService;
import org.wfc.system.domain.SysConfig;
import org.wfc.system.domain.bo.SysPayConfigBo;
import org.wfc.system.mapper.SysConfigMapper;
import org.wfc.system.service.ISysConfigService;
import org.wfc.common.core.utils.MessageUtils;
import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 参数配置 服务层实现
@@ -30,6 +37,10 @@ public class SysConfigServiceImpl implements ISysConfigService
@Autowired
private RedisService redisService;
private static final String DEFAULT_SYS_PAY_CURRENCY_VALUE = "USD";
private static final String DEFAULT_SYS_PAY_CURRENCY_SYMBOL_VALUE = "$";
private static final String[] DEFAULT_SYS_PAY_PAYMENT_METHOD_VALUE = {"paypal"};
/**
* 项目启动时,初始化参数到缓存
*/
@@ -39,6 +50,41 @@ public class SysConfigServiceImpl implements ISysConfigService
loadingConfigCache();
}
@Override
public SysPayConfigBo getPayConfig() {
// 查看支付配置参数
Map<String, Object> cacheMap = redisService.getCacheMap(CacheConstants.SYS_PAY_CONFIG_KEY);
cacheMap = initPayConfig(cacheMap);
SysPayConfigBo sysPayConfigBo = new SysPayConfigBo();
BeanUtil.copyProperties(cacheMap, sysPayConfigBo, true);
return sysPayConfigBo;
}
private Map<String, Object> initPayConfig(Map<String, Object> cacheMap) {
if (CollUtil.isEmpty(cacheMap)) {
cacheMap = new HashMap<>();
cacheMap.put(CacheConstants.SYS_PAY_CURRENCY_KEY, DEFAULT_SYS_PAY_CURRENCY_VALUE);
cacheMap.put(CacheConstants.SYS_PAY_CURRENCY_SYMBOL_KEY, DEFAULT_SYS_PAY_CURRENCY_SYMBOL_VALUE);
cacheMap.put(CacheConstants.SYS_PAY_PAYMENT_METHOD_KEY, DEFAULT_SYS_PAY_PAYMENT_METHOD_VALUE);
redisService.setCacheMap(CacheConstants.SYS_PAY_CONFIG_KEY, cacheMap);
}
return cacheMap;
}
@Override
public boolean setPayConfig(SysPayConfigBo configBo) {
if (StrUtil.isNotBlank(configBo.getCurrency())) {
redisService.setCacheMapValue(CacheConstants.SYS_PAY_CONFIG_KEY, CacheConstants.SYS_PAY_CURRENCY_KEY, configBo.getCurrency());
}
if (StrUtil.isNotBlank(configBo.getCurrencySymbol())) {
redisService.setCacheMapValue(CacheConstants.SYS_PAY_CONFIG_KEY, CacheConstants.SYS_PAY_CURRENCY_SYMBOL_KEY, configBo.getCurrencySymbol());
}
if (CollUtil.isNotEmpty(configBo.getPaymentMethods())) {
redisService.setCacheMapValue(CacheConstants.SYS_PAY_CONFIG_KEY, CacheConstants.SYS_PAY_PAYMENT_METHOD_KEY, configBo.getPaymentMethods());
}
return true;
}
/**
* 查询参数配置信息
*

View File

@@ -2,16 +2,23 @@ package org.wfc.user.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wfc.common.core.domain.R;
import org.wfc.common.core.utils.poi.ExcelUtil;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.common.log.annotation.Log;
import org.wfc.common.log.enums.BusinessType;
import org.wfc.common.security.annotation.RequiresPermissions;
import org.wfc.common.security.utils.SecurityUtils;
import org.wfc.user.domain.UConfig;
import org.wfc.user.domain.bo.UPayConfigBo;
import org.wfc.user.service.IUConfigService;
import javax.servlet.http.HttpServletResponse;
@@ -29,6 +36,14 @@ public class UConfigController extends BaseController
@Autowired
private IUConfigService configService;
@GetMapping("/pay")
public R<UPayConfigBo> getPayConfig()
{
UPayConfigBo result = configService.getPayConfig();
return R.ok(result);
}
/**
* 获取参数配置列表
*/

View File

@@ -0,0 +1,18 @@
package org.wfc.user.domain.bo;
import lombok.Data;
import java.util.List;
/**
* @description: 支付配置bo
* @author: cyc
* @since: 2025-04-23
*/
@Data
public class UPayConfigBo {
private String currency;
private String currencySymbol;
private List<String> paymentMethods;
}

View File

@@ -1,6 +1,7 @@
package org.wfc.user.service;
import org.wfc.user.domain.UConfig;
import org.wfc.user.domain.bo.UPayConfigBo;
import java.util.List;
@@ -11,6 +12,9 @@ import java.util.List;
*/
public interface IUConfigService
{
UPayConfigBo getPayConfig();
/**
* 查询参数配置信息
*

View File

@@ -1,5 +1,7 @@
package org.wfc.user.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.wfc.common.core.constant.CacheConstants;
@@ -9,12 +11,15 @@ import org.wfc.common.core.text.Convert;
import org.wfc.common.core.utils.StringUtils;
import org.wfc.common.redis.service.RedisService;
import org.wfc.user.domain.UConfig;
import org.wfc.user.domain.bo.UPayConfigBo;
import org.wfc.user.mapper.UConfigMapper;
import org.wfc.user.service.IUConfigService;
import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 参数配置 服务层实现
@@ -30,6 +35,10 @@ public class UConfigServiceImpl implements IUConfigService
@Autowired
private RedisService redisService;
private static final String DEFAULT_SYS_PAY_CURRENCY_VALUE = "USD";
private static final String DEFAULT_SYS_PAY_CURRENCY_SYMBOL_VALUE = "$";
private static final String[] DEFAULT_SYS_PAY_PAYMENT_METHOD_VALUE = {"paypal"};
/**
* 项目启动时,初始化参数到缓存
*/
@@ -39,6 +48,27 @@ public class UConfigServiceImpl implements IUConfigService
loadingConfigCache();
}
@Override
public UPayConfigBo getPayConfig() {
// 查看支付配置参数
Map<String, Object> cacheMap = redisService.getCacheMap(CacheConstants.SYS_PAY_CONFIG_KEY);
cacheMap = initPayConfig(cacheMap);
UPayConfigBo configBo = new UPayConfigBo();
BeanUtil.copyProperties(cacheMap, configBo, true);
return configBo;
}
private Map<String, Object> initPayConfig(Map<String, Object> cacheMap) {
if (CollUtil.isEmpty(cacheMap)) {
cacheMap = new HashMap<>();
cacheMap.put(CacheConstants.SYS_PAY_CURRENCY_KEY, DEFAULT_SYS_PAY_CURRENCY_VALUE);
cacheMap.put(CacheConstants.SYS_PAY_CURRENCY_SYMBOL_KEY, DEFAULT_SYS_PAY_CURRENCY_SYMBOL_VALUE);
cacheMap.put(CacheConstants.SYS_PAY_PAYMENT_METHOD_KEY, DEFAULT_SYS_PAY_PAYMENT_METHOD_VALUE);
redisService.setCacheMap(CacheConstants.SYS_PAY_CONFIG_KEY, cacheMap);
}
return cacheMap;
}
/**
* 查询参数配置信息
*