|
@@ -1,9 +1,5 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.List;
|
|
|
-import javax.annotation.PostConstruct;
|
|
|
-
|
|
|
import com.huashe.common.annotation.DataSource;
|
|
|
import com.huashe.common.constant.CacheConstants;
|
|
|
import com.huashe.common.constant.UserConstants;
|
|
@@ -11,21 +7,25 @@ import com.huashe.common.enums.DataSourceType;
|
|
|
import com.huashe.common.exception.ServiceException;
|
|
|
import com.huashe.common.text.Convert;
|
|
|
import com.huashe.common.utils.StringUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
import com.ruoyi.common.core.redis.RedisCache;
|
|
|
import com.ruoyi.system.domain.SysConfig;
|
|
|
import com.ruoyi.system.mapper.SysConfigMapper;
|
|
|
import com.ruoyi.system.service.ISysConfigService;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 参数配置 服务层实现
|
|
|
- *
|
|
|
+ *
|
|
|
* @author ruoyi
|
|
|
*/
|
|
|
@Service
|
|
|
-public class SysConfigServiceImpl implements ISysConfigService
|
|
|
-{
|
|
|
+public class SysConfigServiceImpl implements ISysConfigService {
|
|
|
@Autowired
|
|
|
private SysConfigMapper configMapper;
|
|
|
|
|
@@ -36,45 +36,40 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* 项目启动时,初始化参数到缓存
|
|
|
*/
|
|
|
@PostConstruct
|
|
|
- public void init()
|
|
|
- {
|
|
|
+ public void init() {
|
|
|
loadingConfigCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询参数配置信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param configId 参数配置ID
|
|
|
* @return 参数配置信息
|
|
|
*/
|
|
|
@Override
|
|
|
@DataSource(DataSourceType.MASTER)
|
|
|
- public SysConfig selectConfigById(Long configId)
|
|
|
- {
|
|
|
+ public SysConfig selectConfigById(Long configId) {
|
|
|
SysConfig config = new SysConfig();
|
|
|
config.setConfigId(configId);
|
|
|
return configMapper.selectConfig(config);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据键名查询参数配置信息
|
|
|
- *
|
|
|
+ * 根据键名查询参数配置信息,如果是租户的配置,需要在key上追加租户ID 【key:[tenantId]】
|
|
|
+ *
|
|
|
* @param configKey 参数key
|
|
|
* @return 参数键值
|
|
|
*/
|
|
|
@Override
|
|
|
- public String selectConfigByKey(String configKey)
|
|
|
- {
|
|
|
+ public String selectConfigByKey(String configKey) {
|
|
|
String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
|
|
|
- if (StringUtils.isNotEmpty(configValue))
|
|
|
- {
|
|
|
+ if (StringUtils.isNotEmpty(configValue)) {
|
|
|
return configValue;
|
|
|
}
|
|
|
SysConfig config = new SysConfig();
|
|
|
config.setConfigKey(configKey);
|
|
|
SysConfig retConfig = configMapper.selectConfig(config);
|
|
|
- if (StringUtils.isNotNull(retConfig))
|
|
|
- {
|
|
|
+ if (StringUtils.isNotNull(retConfig)) {
|
|
|
redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
|
|
|
return retConfig.getConfigValue();
|
|
|
}
|
|
@@ -83,15 +78,13 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
|
/**
|
|
|
* 获取验证码开关
|
|
|
- *
|
|
|
+ *
|
|
|
* @return true开启,false关闭
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean selectCaptchaEnabled()
|
|
|
- {
|
|
|
+ public boolean selectCaptchaEnabled() {
|
|
|
String captchaEnabled = selectConfigByKey("sys.account.captchaEnabled");
|
|
|
- if (StringUtils.isEmpty(captchaEnabled))
|
|
|
- {
|
|
|
+ if (StringUtils.isEmpty(captchaEnabled)) {
|
|
|
return true;
|
|
|
}
|
|
|
return Convert.toBool(captchaEnabled);
|
|
@@ -99,69 +92,60 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
|
/**
|
|
|
* 查询参数配置列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param config 参数配置信息
|
|
|
* @return 参数配置集合
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<SysConfig> selectConfigList(SysConfig config)
|
|
|
- {
|
|
|
+ public List<SysConfig> selectConfigList(SysConfig config) {
|
|
|
return configMapper.selectConfigList(config);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增参数配置
|
|
|
- *
|
|
|
+ *
|
|
|
* @param config 参数配置信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int insertConfig(SysConfig config)
|
|
|
- {
|
|
|
+ public int insertConfig(SysConfig config) {
|
|
|
int row = configMapper.insertConfig(config);
|
|
|
- if (row > 0)
|
|
|
- {
|
|
|
- redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
+ if (row > 0) {
|
|
|
+ redisCache.setCacheObject(getCacheKey(config), config.getConfigValue());
|
|
|
}
|
|
|
return row;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改参数配置
|
|
|
- *
|
|
|
+ *
|
|
|
* @param config 参数配置信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateConfig(SysConfig config)
|
|
|
- {
|
|
|
+ public int updateConfig(SysConfig config) {
|
|
|
SysConfig temp = configMapper.selectConfigById(config.getConfigId());
|
|
|
- if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey()))
|
|
|
- {
|
|
|
- redisCache.deleteObject(getCacheKey(temp.getConfigKey()));
|
|
|
+ if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) {
|
|
|
+ redisCache.deleteObject(getCacheKey(temp));
|
|
|
}
|
|
|
|
|
|
int row = configMapper.updateConfig(config);
|
|
|
- if (row > 0)
|
|
|
- {
|
|
|
- redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
+ if (row > 0) {
|
|
|
+ redisCache.setCacheObject(getCacheKey(config), config.getConfigValue());
|
|
|
}
|
|
|
return row;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除参数信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param configIds 需要删除的参数ID
|
|
|
*/
|
|
|
@Override
|
|
|
- public void deleteConfigByIds(Long[] configIds)
|
|
|
- {
|
|
|
- for (Long configId : configIds)
|
|
|
- {
|
|
|
+ public void deleteConfigByIds(Long[] configIds) {
|
|
|
+ for (Long configId : configIds) {
|
|
|
SysConfig config = selectConfigById(configId);
|
|
|
- if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
|
|
|
- {
|
|
|
+ if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
|
|
|
throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
|
|
|
}
|
|
|
configMapper.deleteConfigById(configId);
|
|
@@ -173,12 +157,10 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* 加载参数缓存数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public void loadingConfigCache()
|
|
|
- {
|
|
|
+ public void loadingConfigCache() {
|
|
|
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
|
|
|
- for (SysConfig config : configsList)
|
|
|
- {
|
|
|
- redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
+ for (SysConfig config : configsList) {
|
|
|
+ redisCache.setCacheObject(getCacheKey(config), config.getConfigValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -186,8 +168,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* 清空参数缓存数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public void clearConfigCache()
|
|
|
- {
|
|
|
+ public void clearConfigCache() {
|
|
|
Collection<String> keys = redisCache.keys(CacheConstants.SYS_CONFIG_KEY + "*");
|
|
|
redisCache.deleteObject(keys);
|
|
|
}
|
|
@@ -196,25 +177,22 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
* 重置参数缓存数据
|
|
|
*/
|
|
|
@Override
|
|
|
- public void resetConfigCache()
|
|
|
- {
|
|
|
+ public void resetConfigCache() {
|
|
|
clearConfigCache();
|
|
|
loadingConfigCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 校验参数键名是否唯一
|
|
|
- *
|
|
|
+ *
|
|
|
* @param config 参数配置信息
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean checkConfigKeyUnique(SysConfig config)
|
|
|
- {
|
|
|
+ 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())
|
|
|
- {
|
|
|
+ SysConfig info = configMapper.checkConfigKeyUnique(config);
|
|
|
+ if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
}
|
|
|
return UserConstants.UNIQUE;
|
|
@@ -222,12 +200,18 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
|
/**
|
|
|
* 设置cache key
|
|
|
- *
|
|
|
+ *
|
|
|
* @param configKey 参数键
|
|
|
* @return 缓存键key
|
|
|
*/
|
|
|
- private String getCacheKey(String configKey)
|
|
|
- {
|
|
|
+ private String getCacheKey(String configKey) {
|
|
|
return CacheConstants.SYS_CONFIG_KEY + configKey;
|
|
|
}
|
|
|
+
|
|
|
+ private String getCacheKey(SysConfig configKey) {
|
|
|
+ if (!ObjectUtils.isEmpty(configKey.getTenantId())) {
|
|
|
+ return CacheConstants.SYS_CONFIG_KEY + configKey.getConfigKey() + ":" + configKey.getTenantId();
|
|
|
+ }
|
|
|
+ return CacheConstants.SYS_CONFIG_KEY + configKey.getConfigKey();
|
|
|
+ }
|
|
|
}
|