|
|
|
@ -1,10 +1,13 @@
|
|
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import com.ruoyi.common.constant.Constants;
|
|
|
|
|
import com.ruoyi.common.constant.UserConstants;
|
|
|
|
|
import com.ruoyi.common.core.text.Convert;
|
|
|
|
|
import com.ruoyi.common.utils.CacheUtils;
|
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
|
import com.ruoyi.system.domain.SysConfig;
|
|
|
|
|
import com.ruoyi.system.mapper.SysConfigMapper;
|
|
|
|
@ -21,6 +24,19 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
@Autowired
|
|
|
|
|
private SysConfigMapper configMapper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 项目启动时,初始化参数到缓存
|
|
|
|
|
*/
|
|
|
|
|
@PostConstruct
|
|
|
|
|
public void init()
|
|
|
|
|
{
|
|
|
|
|
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
|
|
|
|
|
for (SysConfig config : configsList)
|
|
|
|
|
{
|
|
|
|
|
CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询参数配置信息
|
|
|
|
|
*
|
|
|
|
@ -44,10 +60,20 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
@Override
|
|
|
|
|
public String selectConfigByKey(String configKey)
|
|
|
|
|
{
|
|
|
|
|
String configValue = Convert.toStr(CacheUtils.get(getCacheName(), getCacheKey(configKey)));
|
|
|
|
|
if (StringUtils.isNotEmpty(configValue))
|
|
|
|
|
{
|
|
|
|
|
return configValue;
|
|
|
|
|
}
|
|
|
|
|
SysConfig config = new SysConfig();
|
|
|
|
|
config.setConfigKey(configKey);
|
|
|
|
|
SysConfig retConfig = configMapper.selectConfig(config);
|
|
|
|
|
return StringUtils.isNotNull(retConfig) ? retConfig.getConfigValue() : "";
|
|
|
|
|
if (StringUtils.isNotNull(retConfig))
|
|
|
|
|
{
|
|
|
|
|
CacheUtils.put(getCacheName(), getCacheKey(configKey), retConfig.getConfigValue());
|
|
|
|
|
return retConfig.getConfigValue();
|
|
|
|
|
}
|
|
|
|
|
return StringUtils.EMPTY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -71,7 +97,12 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
@Override
|
|
|
|
|
public int insertConfig(SysConfig config)
|
|
|
|
|
{
|
|
|
|
|
return configMapper.insertConfig(config);
|
|
|
|
|
int row = configMapper.insertConfig(config);
|
|
|
|
|
if (row > 0)
|
|
|
|
|
{
|
|
|
|
|
CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
|
}
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -83,7 +114,12 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
@Override
|
|
|
|
|
public int updateConfig(SysConfig config)
|
|
|
|
|
{
|
|
|
|
|
return configMapper.updateConfig(config);
|
|
|
|
|
int row = configMapper.updateConfig(config);
|
|
|
|
|
if (row > 0)
|
|
|
|
|
{
|
|
|
|
|
CacheUtils.put(getCacheName(), getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
|
|
}
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -95,7 +131,21 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
@Override
|
|
|
|
|
public int deleteConfigByIds(String ids)
|
|
|
|
|
{
|
|
|
|
|
return configMapper.deleteConfigByIds(Convert.toStrArray(ids));
|
|
|
|
|
int count = configMapper.deleteConfigByIds(Convert.toStrArray(ids));
|
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
CacheUtils.removeAll(getCacheName());
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 清空缓存数据
|
|
|
|
|
*/
|
|
|
|
|
public void clearCache()
|
|
|
|
|
{
|
|
|
|
|
CacheUtils.removeAll(getCacheName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -115,4 +165,25 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
|
|
|
}
|
|
|
|
|
return UserConstants.CONFIG_KEY_UNIQUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取cache name
|
|
|
|
|
*
|
|
|
|
|
* @return 缓存名
|
|
|
|
|
*/
|
|
|
|
|
private String getCacheName()
|
|
|
|
|
{
|
|
|
|
|
return Constants.SYS_CONFIG_CACHE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置cache key
|
|
|
|
|
*
|
|
|
|
|
* @param configKey 参数键
|
|
|
|
|
* @return 缓存键key
|
|
|
|
|
*/
|
|
|
|
|
private String getCacheKey(String configKey)
|
|
|
|
|
{
|
|
|
|
|
return Constants.SYS_CONFIG_KEY + configKey;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|