|
|
|
@ -13,6 +13,7 @@ import com.ruoyi.system.mapper.SysConfigMapper;
|
|
|
|
import com.ruoyi.system.service.ISysConfigService;
|
|
|
|
import com.ruoyi.system.service.ISysConfigService;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
@ -23,8 +24,7 @@ import java.util.List;
|
|
|
|
* @author ruoyi
|
|
|
|
* @author ruoyi
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
public class SysConfigServiceImpl implements ISysConfigService {
|
|
|
|
{
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private SysConfigMapper configMapper;
|
|
|
|
private SysConfigMapper configMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@ -35,8 +35,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* 项目启动时,初始化参数到缓存
|
|
|
|
* 项目启动时,初始化参数到缓存
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
|
public void init()
|
|
|
|
public void init() {
|
|
|
|
{
|
|
|
|
|
|
|
|
loadingConfigCache();
|
|
|
|
loadingConfigCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -48,8 +47,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@DataSource(DataSourceType.MASTER)
|
|
|
|
@DataSource(DataSourceType.MASTER)
|
|
|
|
public SysConfig selectConfigById(Long configId)
|
|
|
|
public SysConfig selectConfigById(Long configId) {
|
|
|
|
{
|
|
|
|
|
|
|
|
SysConfig config = new SysConfig();
|
|
|
|
SysConfig config = new SysConfig();
|
|
|
|
config.setConfigId(configId);
|
|
|
|
config.setConfigId(configId);
|
|
|
|
return configMapper.selectConfig(config);
|
|
|
|
return configMapper.selectConfig(config);
|
|
|
|
@ -62,35 +60,46 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* @return 参数键值
|
|
|
|
* @return 参数键值
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String selectConfigByKey(String configKey)
|
|
|
|
public String selectConfigByKey(String configKey) {
|
|
|
|
{
|
|
|
|
|
|
|
|
String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
|
|
|
|
String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
|
|
|
|
if (StringUtils.isNotEmpty(configValue))
|
|
|
|
if (StringUtils.isNotEmpty(configValue)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return configValue;
|
|
|
|
return configValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SysConfig config = new SysConfig();
|
|
|
|
SysConfig config = new SysConfig();
|
|
|
|
config.setConfigKey(configKey);
|
|
|
|
config.setConfigKey(configKey);
|
|
|
|
SysConfig retConfig = configMapper.selectConfig(config);
|
|
|
|
SysConfig retConfig = configMapper.selectConfig(config);
|
|
|
|
if (StringUtils.isNotNull(retConfig))
|
|
|
|
if (StringUtils.isNotNull(retConfig)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
|
|
|
|
redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
|
|
|
|
return retConfig.getConfigValue();
|
|
|
|
return retConfig.getConfigValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public SysConfig selectConfigByKey2(String configKey) {
|
|
|
|
|
|
|
|
SysConfig config = redisCache.getCacheObject(getCacheKey2(configKey));
|
|
|
|
|
|
|
|
if (config != null) {
|
|
|
|
|
|
|
|
return config;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SysConfig configQuery = new SysConfig();
|
|
|
|
|
|
|
|
configQuery.setConfigKey(configKey);
|
|
|
|
|
|
|
|
SysConfig retConfig = configMapper.selectConfig(configQuery);
|
|
|
|
|
|
|
|
if (StringUtils.isNotNull(retConfig)) {
|
|
|
|
|
|
|
|
redisCache.setCacheObject(getCacheKey2(configKey), retConfig);
|
|
|
|
|
|
|
|
return retConfig;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 获取验证码开关
|
|
|
|
* 获取验证码开关
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return true开启,false关闭
|
|
|
|
* @return true开启,false关闭
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean selectCaptchaOnOff()
|
|
|
|
public boolean selectCaptchaOnOff() {
|
|
|
|
{
|
|
|
|
|
|
|
|
String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff");
|
|
|
|
String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff");
|
|
|
|
if (StringUtils.isEmpty(captchaOnOff))
|
|
|
|
if (StringUtils.isEmpty(captchaOnOff)) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Convert.toBool(captchaOnOff);
|
|
|
|
return Convert.toBool(captchaOnOff);
|
|
|
|
@ -103,8 +112,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* @return 参数配置集合
|
|
|
|
* @return 参数配置集合
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<SysConfig> selectConfigList(SysConfig config)
|
|
|
|
public List<SysConfig> selectConfigList(SysConfig config) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return configMapper.selectConfigList(config);
|
|
|
|
return configMapper.selectConfigList(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -115,12 +123,14 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int insertConfig(SysConfig config)
|
|
|
|
public int insertConfig(SysConfig config) {
|
|
|
|
{
|
|
|
|
|
|
|
|
int row = configMapper.insertConfig(config);
|
|
|
|
int row = configMapper.insertConfig(config);
|
|
|
|
if (row > 0)
|
|
|
|
if (row > 0) {
|
|
|
|
{
|
|
|
|
if ("N".equals(config.getConfigType())){
|
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
redisCache.setCacheObject(getCacheKey2(config.getConfigKey()), config);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return row;
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -132,12 +142,14 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int updateConfig(SysConfig config)
|
|
|
|
public int updateConfig(SysConfig config) {
|
|
|
|
{
|
|
|
|
|
|
|
|
int row = configMapper.updateConfig(config);
|
|
|
|
int row = configMapper.updateConfig(config);
|
|
|
|
if (row > 0)
|
|
|
|
if (row > 0) {
|
|
|
|
{
|
|
|
|
if ("N".equals(config.getConfigType())){
|
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
redisCache.setCacheObject(getCacheKey2(config.getConfigKey()), config);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return row;
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -149,13 +161,10 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteConfigByIds(Long[] configIds)
|
|
|
|
public void deleteConfigByIds(Long[] configIds) {
|
|
|
|
{
|
|
|
|
for (Long configId : configIds) {
|
|
|
|
for (Long configId : configIds)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SysConfig config = selectConfigById(configId);
|
|
|
|
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()));
|
|
|
|
throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
configMapper.deleteConfigById(configId);
|
|
|
|
configMapper.deleteConfigById(configId);
|
|
|
|
@ -167,11 +176,9 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* 加载参数缓存数据
|
|
|
|
* 加载参数缓存数据
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void loadingConfigCache()
|
|
|
|
public void loadingConfigCache() {
|
|
|
|
{
|
|
|
|
|
|
|
|
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
|
|
|
|
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
|
|
|
|
for (SysConfig config : configsList)
|
|
|
|
for (SysConfig config : configsList) {
|
|
|
|
{
|
|
|
|
|
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -180,8 +187,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* 清空参数缓存数据
|
|
|
|
* 清空参数缓存数据
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void clearConfigCache()
|
|
|
|
public void clearConfigCache() {
|
|
|
|
{
|
|
|
|
|
|
|
|
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
|
|
|
|
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
|
|
|
|
redisCache.deleteObject(keys);
|
|
|
|
redisCache.deleteObject(keys);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -190,8 +196,7 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* 重置参数缓存数据
|
|
|
|
* 重置参数缓存数据
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void resetConfigCache()
|
|
|
|
public void resetConfigCache() {
|
|
|
|
{
|
|
|
|
|
|
|
|
clearConfigCache();
|
|
|
|
clearConfigCache();
|
|
|
|
loadingConfigCache();
|
|
|
|
loadingConfigCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -203,12 +208,10 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* @return 结果
|
|
|
|
* @return 结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String checkConfigKeyUnique(SysConfig config)
|
|
|
|
public String checkConfigKeyUnique(SysConfig config) {
|
|
|
|
{
|
|
|
|
|
|
|
|
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
|
|
|
|
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
|
|
|
|
SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
|
|
|
|
SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
|
|
|
|
if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue())
|
|
|
|
if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
return UserConstants.NOT_UNIQUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
|
return UserConstants.UNIQUE;
|
|
|
|
@ -220,8 +223,11 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
* @param configKey 参数键
|
|
|
|
* @param configKey 参数键
|
|
|
|
* @return 缓存键key
|
|
|
|
* @return 缓存键key
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private String getCacheKey(String configKey)
|
|
|
|
private String getCacheKey(String configKey) {
|
|
|
|
{
|
|
|
|
|
|
|
|
return Constants.SYS_CONFIG_KEY + configKey;
|
|
|
|
return Constants.SYS_CONFIG_KEY + configKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getCacheKey2(String configKey) {
|
|
|
|
|
|
|
|
return Constants.SYS_CONFIG_KEY + configKey + "_all";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|