From 9a4eaddc50bbf1bfab9bbf98bcef09c0b84425e6 Mon Sep 17 00:00:00 2001 From: caiyuchao Date: Wed, 23 Apr 2025 17:41:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E4=BB=98=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/constant/CacheConstants.java | 20 +++++++ .../controller/SysConfigController.java | 23 +++++++- .../wfc/system/domain/bo/SysPayConfigBo.java | 18 +++++++ .../wfc/system/service/ISysConfigService.java | 9 +++- .../service/impl/SysConfigServiceImpl.java | 54 +++++++++++++++++-- .../user/controller/UConfigController.java | 21 ++++++-- .../org/wfc/user/domain/bo/UPayConfigBo.java | 18 +++++++ .../org/wfc/user/service/IUConfigService.java | 4 ++ .../user/service/impl/UConfigServiceImpl.java | 30 +++++++++++ 9 files changed, 187 insertions(+), 10 deletions(-) create mode 100644 wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/bo/SysPayConfigBo.java create mode 100644 wfc-modules/wfc-user/src/main/java/org/wfc/user/domain/bo/UPayConfigBo.java diff --git a/wfc-common/wfc-common-core/src/main/java/org/wfc/common/core/constant/CacheConstants.java b/wfc-common/wfc-common-core/src/main/java/org/wfc/common/core/constant/CacheConstants.java index 9cf18f1..18403c5 100644 --- a/wfc-common/wfc-common-core/src/main/java/org/wfc/common/core/constant/CacheConstants.java +++ b/wfc-common/wfc-common-core/src/main/java/org/wfc/common/core/constant/CacheConstants.java @@ -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 */ diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysConfigController.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysConfigController.java index 93528cc..2246773 100644 --- a/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysConfigController.java +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/controller/SysConfigController.java @@ -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 getPayConfig() + { + SysPayConfigBo result = configService.getPayConfig(); + return R.ok(result); + } + + @PutMapping("/pay") + public R setPayConfig(@RequestBody SysPayConfigBo config) + { + boolean result = configService.setPayConfig(config); + return R.ok(result); + } + + /** * 获取参数配置列表 */ diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/bo/SysPayConfigBo.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/bo/SysPayConfigBo.java new file mode 100644 index 0000000..4fd4700 --- /dev/null +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/domain/bo/SysPayConfigBo.java @@ -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 paymentMethods; +} diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/ISysConfigService.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/ISysConfigService.java index b67e8cf..9a6317e 100644 --- a/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/ISysConfigService.java +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/ISysConfigService.java @@ -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); + /** * 查询参数配置信息 * diff --git a/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/impl/SysConfigServiceImpl.java b/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/impl/SysConfigServiceImpl.java index e771a4c..4b906b2 100644 --- a/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/impl/SysConfigServiceImpl.java +++ b/wfc-modules/wfc-system/src/main/java/org/wfc/system/service/impl/SysConfigServiceImpl.java @@ -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 cacheMap = redisService.getCacheMap(CacheConstants.SYS_PAY_CONFIG_KEY); + cacheMap = initPayConfig(cacheMap); + SysPayConfigBo sysPayConfigBo = new SysPayConfigBo(); + BeanUtil.copyProperties(cacheMap, sysPayConfigBo, true); + return sysPayConfigBo; + } + + private Map initPayConfig(Map 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; + } + /** * 查询参数配置信息 * diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UConfigController.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UConfigController.java index 9eaf9de..c6035b9 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UConfigController.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/controller/UConfigController.java @@ -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 getPayConfig() + { + UPayConfigBo result = configService.getPayConfig(); + return R.ok(result); + } + + /** * 获取参数配置列表 */ diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/domain/bo/UPayConfigBo.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/domain/bo/UPayConfigBo.java new file mode 100644 index 0000000..9faeff1 --- /dev/null +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/domain/bo/UPayConfigBo.java @@ -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 paymentMethods; +} diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/IUConfigService.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/IUConfigService.java index f04ccbc..bfe6463 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/IUConfigService.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/IUConfigService.java @@ -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(); + /** * 查询参数配置信息 * diff --git a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UConfigServiceImpl.java b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UConfigServiceImpl.java index 39be59f..68962fd 100644 --- a/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UConfigServiceImpl.java +++ b/wfc-modules/wfc-user/src/main/java/org/wfc/user/service/impl/UConfigServiceImpl.java @@ -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 cacheMap = redisService.getCacheMap(CacheConstants.SYS_PAY_CONFIG_KEY); + cacheMap = initPayConfig(cacheMap); + UPayConfigBo configBo = new UPayConfigBo(); + BeanUtil.copyProperties(cacheMap, configBo, true); + return configBo; + } + + private Map initPayConfig(Map 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; + } + /** * 查询参数配置信息 *