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

@@ -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;
}
/**
* 查询参数配置信息
*