From 3e9bc147f05ab3ce8db0afcf6272b95b543eb89a Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期五, 16 八月 2024 13:40:26 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/java/mx_charging_pile
---
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java | 358 ++++++++++++++++++++++++++++-------------------------------
1 files changed, 169 insertions(+), 189 deletions(-)
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
index d48cbfe..626ae5c 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
@@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.List;
import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
@@ -18,197 +19,176 @@
/**
* 参数配置 服务层实现
- *
+ *
* @author ruoyi
*/
@Service
-public class SysConfigServiceImpl implements ISysConfigService
-{
- @Autowired
- private SysConfigMapper configMapper;
-
- @Autowired
- private RedisService redisService;
-
- /**
- * 项目启动时,初始化参数到缓存
- */
- @PostConstruct
- public void init()
- {
- // TODO
+public class SysConfigServiceImpl implements ISysConfigService {
+ @Resource
+ private SysConfigMapper configMapper;
+
+ @Resource
+ private RedisService redisService;
+
+ /**
+ * 项目启动时,初始化参数到缓存
+ */
+ @PostConstruct
+ public void init() {
+ // TODO
// loadingConfigCache();
- }
-
- /**
- * 查询参数配置信息
- *
- * @param configId 参数配置ID
- * @return 参数配置信息
- */
- @Override
- public SysConfig selectConfigById(Long configId)
- {
- SysConfig config = new SysConfig();
- config.setConfigId(configId);
- return configMapper.selectConfig(config);
- }
-
- /**
- * 根据键名查询参数配置信息
- *
- * @param configKey 参数key
- * @return 参数键值
- */
- @Override
- public String selectConfigByKey(String configKey)
- {
- String configValue = Convert.toStr(redisService.getCacheObject(getCacheKey(configKey)));
- if (StringUtils.isNotEmpty(configValue))
- {
- return configValue;
- }
- SysConfig config = new SysConfig();
- config.setConfigKey(configKey);
- SysConfig retConfig = configMapper.selectConfig(config);
- if (StringUtils.isNotNull(retConfig))
- {
- redisService.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
- return retConfig.getConfigValue();
- }
- return StringUtils.EMPTY;
- }
-
- /**
- * 查询参数配置列表
- *
- * @param config 参数配置信息
- * @return 参数配置集合
- */
- @Override
- public List<SysConfig> selectConfigList(SysConfig config)
- {
- return configMapper.selectConfigList(config);
- }
-
- /**
- * 新增参数配置
- *
- * @param config 参数配置信息
- * @return 结果
- */
- @Override
- public int insertConfig(SysConfig config)
- {
- int row = configMapper.insertConfig(config);
- if (row > 0)
- {
- redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
- }
- return row;
- }
-
- /**
- * 修改参数配置
- *
- * @param config 参数配置信息
- * @return 结果
- */
- @Override
- public int updateConfig(SysConfig config)
- {
- SysConfig temp = configMapper.selectConfigById(config.getConfigId());
- if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey()))
- {
- redisService.deleteObject(getCacheKey(temp.getConfigKey()));
- }
-
- int row = configMapper.updateConfig(config);
- if (row > 0)
- {
- redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
- }
- return row;
- }
-
- /**
- * 批量删除参数信息
- *
- * @param configIds 需要删除的参数ID
- */
- @Override
- public void deleteConfigByIds(Long[] configIds)
- {
- for (Long configId : configIds)
- {
- SysConfig config = selectConfigById(configId);
- if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
- {
- throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
- }
- configMapper.deleteConfigById(configId);
- redisService.deleteObject(getCacheKey(config.getConfigKey()));
- }
- }
-
- /**
- * 加载参数缓存数据
- */
- @Override
- public void loadingConfigCache(){
- List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
- for (SysConfig config : configsList)
- {
- redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
- }
- }
-
- /**
- * 清空参数缓存数据
- */
- @Override
- public void clearConfigCache()
- {
- Collection<String> keys = redisService.keys(CacheConstants.SYS_CONFIG_KEY + "*");
- redisService.deleteObject(keys);
- }
-
- /**
- * 重置参数缓存数据
- */
- @Override
- public void resetConfigCache()
- {
- clearConfigCache();
- loadingConfigCache();
- }
-
- /**
- * 校验参数键名是否唯一
- *
- * @param config 参数配置信息
- * @return 结果
- */
- @Override
- public boolean checkConfigKeyUnique(SysConfig config)
- {
- Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
- SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
- if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue())
- {
- return UserConstants.NOT_UNIQUE;
- }
- return UserConstants.UNIQUE;
- }
-
- /**
- * 设置cache key
- *
- * @param configKey 参数键
- * @return 缓存键key
- */
- private String getCacheKey(String configKey)
- {
- return CacheConstants.SYS_CONFIG_KEY + configKey;
- }
+ }
+
+ /**
+ * 查询参数配置信息
+ *
+ * @param configId 参数配置ID
+ * @return 参数配置信息
+ */
+ @Override
+ public SysConfig selectConfigById(Long configId) {
+ SysConfig config = new SysConfig();
+ config.setConfigId(configId);
+ return configMapper.selectConfig(config);
+ }
+
+ /**
+ * 根据键名查询参数配置信息
+ *
+ * @param configKey 参数key
+ * @return 参数键值
+ */
+ @Override
+ public String selectConfigByKey(String configKey) {
+ String configValue = Convert.toStr(redisService.getCacheObject(getCacheKey(configKey)));
+ if (StringUtils.isNotEmpty(configValue)) {
+ return configValue;
+ }
+ SysConfig config = new SysConfig();
+ config.setConfigKey(configKey);
+ SysConfig retConfig = configMapper.selectConfig(config);
+ if (StringUtils.isNotNull(retConfig)) {
+ redisService.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
+ return retConfig.getConfigValue();
+ }
+ return StringUtils.EMPTY;
+ }
+
+ /**
+ * 查询参数配置列表
+ *
+ * @param config 参数配置信息
+ * @return 参数配置集合
+ */
+ @Override
+ public List<SysConfig> selectConfigList(SysConfig config) {
+ return configMapper.selectConfigList(config);
+ }
+
+ /**
+ * 新增参数配置
+ *
+ * @param config 参数配置信息
+ * @return 结果
+ */
+ @Override
+ public int insertConfig(SysConfig config) {
+ int row = configMapper.insertConfig(config);
+ if (row > 0) {
+ redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
+ }
+ return row;
+ }
+
+ /**
+ * 修改参数配置
+ *
+ * @param config 参数配置信息
+ * @return 结果
+ */
+ @Override
+ public int updateConfig(SysConfig config) {
+ SysConfig temp = configMapper.selectConfigById(config.getConfigId());
+ if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) {
+ redisService.deleteObject(getCacheKey(temp.getConfigKey()));
+ }
+
+ int row = configMapper.updateConfig(config);
+ if (row > 0) {
+ redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
+ }
+ return row;
+ }
+
+ /**
+ * 批量删除参数信息
+ *
+ * @param configIds 需要删除的参数ID
+ */
+ @Override
+ public void deleteConfigByIds(Long[] configIds) {
+ for (Long configId : configIds) {
+ SysConfig config = selectConfigById(configId);
+ if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
+ throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
+ }
+ configMapper.deleteConfigById(configId);
+ redisService.deleteObject(getCacheKey(config.getConfigKey()));
+ }
+ }
+
+ /**
+ * 加载参数缓存数据
+ */
+ @Override
+ public void loadingConfigCache() {
+ List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
+ for (SysConfig config : configsList) {
+ redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
+ }
+ }
+
+ /**
+ * 清空参数缓存数据
+ */
+ @Override
+ public void clearConfigCache() {
+ Collection<String> keys = redisService.keys(CacheConstants.SYS_CONFIG_KEY + "*");
+ redisService.deleteObject(keys);
+ }
+
+ /**
+ * 重置参数缓存数据
+ */
+ @Override
+ public void resetConfigCache() {
+ clearConfigCache();
+ loadingConfigCache();
+ }
+
+ /**
+ * 校验参数键名是否唯一
+ *
+ * @param config 参数配置信息
+ * @return 结果
+ */
+ @Override
+ public boolean checkConfigKeyUnique(SysConfig config) {
+ Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
+ SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
+ if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
+ return UserConstants.NOT_UNIQUE;
+ }
+ return UserConstants.UNIQUE;
+ }
+
+ /**
+ * 设置cache key
+ *
+ * @param configKey 参数键
+ * @return 缓存键key
+ */
+ private String getCacheKey(String configKey) {
+ return CacheConstants.SYS_CONFIG_KEY + configKey;
+ }
}
--
Gitblit v1.7.1