参数管理支持缓存操作
parent
567ab47ae9
commit
06751acbf9
|
@ -132,6 +132,19 @@ public class SysConfigController extends BaseController
|
||||||
return toAjax(configService.deleteConfigByIds(ids));
|
return toAjax(configService.deleteConfigByIds(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空缓存
|
||||||
|
*/
|
||||||
|
@RequiresPermissions("system:config:remove")
|
||||||
|
@Log(title = "参数管理", businessType = BusinessType.CLEAN)
|
||||||
|
@GetMapping("/clearCache")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult clearCache()
|
||||||
|
{
|
||||||
|
configService.clearCache();
|
||||||
|
return success();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验参数键名
|
* 校验参数键名
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,6 +10,7 @@ import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.framework.util.ShiroUtils;
|
import com.ruoyi.framework.util.ShiroUtils;
|
||||||
import com.ruoyi.system.domain.SysMenu;
|
import com.ruoyi.system.domain.SysMenu;
|
||||||
import com.ruoyi.system.domain.SysUser;
|
import com.ruoyi.system.domain.SysUser;
|
||||||
|
import com.ruoyi.system.service.ISysConfigService;
|
||||||
import com.ruoyi.system.service.ISysMenuService;
|
import com.ruoyi.system.service.ISysMenuService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +24,9 @@ public class SysIndexController extends BaseController
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISysMenuService menuService;
|
private ISysMenuService menuService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ISysConfigService configService;
|
||||||
|
|
||||||
// 系统首页
|
// 系统首页
|
||||||
@GetMapping("/index")
|
@GetMapping("/index")
|
||||||
public String index(ModelMap mmap)
|
public String index(ModelMap mmap)
|
||||||
|
@ -33,6 +37,8 @@ public class SysIndexController extends BaseController
|
||||||
List<SysMenu> menus = menuService.selectMenusByUser(user);
|
List<SysMenu> menus = menuService.selectMenusByUser(user);
|
||||||
mmap.put("menus", menus);
|
mmap.put("menus", menus);
|
||||||
mmap.put("user", user);
|
mmap.put("user", user);
|
||||||
|
mmap.put("sideTheme", configService.selectConfigByKey("sys.index.sideTheme"));
|
||||||
|
mmap.put("skinName", configService.selectConfigByKey("sys.index.skinName"));
|
||||||
mmap.put("copyrightYear", Global.getCopyrightYear());
|
mmap.put("copyrightYear", Global.getCopyrightYear());
|
||||||
mmap.put("demoEnabled", Global.isDemoEnabled());
|
mmap.put("demoEnabled", Global.isDemoEnabled());
|
||||||
return "index";
|
return "index";
|
||||||
|
|
|
@ -42,6 +42,14 @@
|
||||||
statistics="true">
|
statistics="true">
|
||||||
</cache>
|
</cache>
|
||||||
|
|
||||||
|
<!-- 系统参数缓存 -->
|
||||||
|
<cache name="sys-config"
|
||||||
|
maxEntriesLocalHeap="1000"
|
||||||
|
eternal="true"
|
||||||
|
overflowToDisk="true"
|
||||||
|
statistics="true">
|
||||||
|
</cache>
|
||||||
|
|
||||||
<!-- 系统会话缓存 -->
|
<!-- 系统会话缓存 -->
|
||||||
<cache name="shiro-activeSessionCache"
|
<cache name="shiro-activeSessionCache"
|
||||||
maxElementsInMemory="10000"
|
maxElementsInMemory="10000"
|
||||||
|
|
|
@ -1105,7 +1105,9 @@ var table = {
|
||||||
} else if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTreeTable) {
|
} else if (result.code == web_status.SUCCESS && table.options.type == table_type.bootstrapTreeTable) {
|
||||||
$.modal.msgSuccess(result.msg);
|
$.modal.msgSuccess(result.msg);
|
||||||
$.treeTable.refresh();
|
$.treeTable.refresh();
|
||||||
} else if (result.code == web_status.WARNING) {
|
} else if (result.code == web_status.SUCCESS && table.option.type == undefined) {
|
||||||
|
$.modal.msgSuccess(result.msg)
|
||||||
|
} else if (result.code == web_status.WARNING) {
|
||||||
$.modal.alertWarning(result.msg)
|
$.modal.alertWarning(result.msg)
|
||||||
} else {
|
} else {
|
||||||
$.modal.alertError(result.msg);
|
$.modal.alertError(result.msg);
|
||||||
|
|
|
@ -74,7 +74,7 @@
|
||||||
<link th:href="@{/ajax/libs/datapicker/bootstrap-datetimepicker.min.css}" rel="stylesheet"/>
|
<link th:href="@{/ajax/libs/datapicker/bootstrap-datetimepicker.min.css}" rel="stylesheet"/>
|
||||||
</div>
|
</div>
|
||||||
<div th:fragment="datetimepicker-js">
|
<div th:fragment="datetimepicker-js">
|
||||||
<script th:src="@{/ajax/libs//datapicker/bootstrap-datetimepicker.min.js}"></script>
|
<script th:src="@{/ajax/libs/datapicker/bootstrap-datetimepicker.min.js}"></script>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ui布局插件 -->
|
<!-- ui布局插件 -->
|
||||||
|
|
|
@ -267,10 +267,8 @@ if($.common.isNotEmpty(skin)){
|
||||||
$("body").addClass(skin.split('|')[0]);
|
$("body").addClass(skin.split('|')[0]);
|
||||||
$("body").addClass(skin.split('|')[1]);
|
$("body").addClass(skin.split('|')[1]);
|
||||||
} else {
|
} else {
|
||||||
var sideTheme = [[${@config.getKey('sys.index.sideTheme')}]];
|
$("body").addClass([[${sideTheme}]]);
|
||||||
var skinName = [[${@config.getKey('sys.index.skinName')}]];
|
$("body").addClass([[${skinName}]]);
|
||||||
$("body").addClass(sideTheme);
|
|
||||||
$("body").addClass(skinName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 用户管理-重置密码 */
|
/* 用户管理-重置密码 */
|
||||||
|
|
|
@ -50,6 +50,9 @@
|
||||||
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:config:export">
|
<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:config:export">
|
||||||
<i class="fa fa-download"></i> 导出
|
<i class="fa fa-download"></i> 导出
|
||||||
</a>
|
</a>
|
||||||
|
<a class="btn btn-danger" onclick="clearCache()" shiro:hasPermission="system:config:remove">
|
||||||
|
<i class="fa fa-refresh"></i> 清理缓存
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-12 select-table table-striped">
|
<div class="col-sm-12 select-table table-striped">
|
||||||
<table id="bootstrap-table"></table>
|
<table id="bootstrap-table"></table>
|
||||||
|
@ -131,6 +134,10 @@
|
||||||
};
|
};
|
||||||
$.table.init(options);
|
$.table.init(options);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function clearCache() {
|
||||||
|
$.operate.get(prefix + "/clearCache");
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -57,6 +57,16 @@ public class Constants
|
||||||
*/
|
*/
|
||||||
public static final String IS_ASC = "isAsc";
|
public static final String IS_ASC = "isAsc";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数管理 cache name
|
||||||
|
*/
|
||||||
|
public static final String SYS_CONFIG_CACHE = "sys-config";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 参数管理 cache key
|
||||||
|
*/
|
||||||
|
public static final String SYS_CONFIG_KEY = "sys_config:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 资源映射路径 前缀
|
* 资源映射路径 前缀
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,187 @@
|
||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.apache.shiro.cache.Cache;
|
||||||
|
import org.apache.shiro.cache.CacheManager;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache工具类
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class CacheUtils
|
||||||
|
{
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(CacheUtils.class);
|
||||||
|
|
||||||
|
private static CacheManager cacheManager = SpringUtils.getBean(CacheManager.class);
|
||||||
|
|
||||||
|
private static final String SYS_CACHE = "sys-cache";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SYS_CACHE缓存
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Object get(String key)
|
||||||
|
{
|
||||||
|
return get(SYS_CACHE, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取SYS_CACHE缓存
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @param defaultValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Object get(String key, Object defaultValue)
|
||||||
|
{
|
||||||
|
Object value = get(key);
|
||||||
|
return value != null ? value : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入SYS_CACHE缓存
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static void put(String key, Object value)
|
||||||
|
{
|
||||||
|
put(SYS_CACHE, key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从SYS_CACHE缓存中移除
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static void remove(String key)
|
||||||
|
{
|
||||||
|
remove(SYS_CACHE, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存
|
||||||
|
*
|
||||||
|
* @param cacheName
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Object get(String cacheName, String key)
|
||||||
|
{
|
||||||
|
return getCache(cacheName).get(getKey(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存
|
||||||
|
*
|
||||||
|
* @param cacheName
|
||||||
|
* @param key
|
||||||
|
* @param defaultValue
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Object get(String cacheName, String key, Object defaultValue)
|
||||||
|
{
|
||||||
|
Object value = get(cacheName, getKey(key));
|
||||||
|
return value != null ? value : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 写入缓存
|
||||||
|
*
|
||||||
|
* @param cacheName
|
||||||
|
* @param key
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public static void put(String cacheName, String key, Object value)
|
||||||
|
{
|
||||||
|
getCache(cacheName).put(getKey(key), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从缓存中移除
|
||||||
|
*
|
||||||
|
* @param cacheName
|
||||||
|
* @param key
|
||||||
|
*/
|
||||||
|
public static void remove(String cacheName, String key)
|
||||||
|
{
|
||||||
|
getCache(cacheName).remove(getKey(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从缓存中移除所有
|
||||||
|
*
|
||||||
|
* @param cacheName
|
||||||
|
*/
|
||||||
|
public static void removeAll(String cacheName)
|
||||||
|
{
|
||||||
|
Cache<String, Object> cache = getCache(cacheName);
|
||||||
|
Set<String> keys = cache.keys();
|
||||||
|
for (Iterator<String> it = keys.iterator(); it.hasNext();)
|
||||||
|
{
|
||||||
|
cache.remove(it.next());
|
||||||
|
}
|
||||||
|
logger.info("清理缓存: {} => {}", cacheName, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从缓存中移除指定key
|
||||||
|
*
|
||||||
|
* @param keys
|
||||||
|
*/
|
||||||
|
public static void removeByKeys(Set<String> keys)
|
||||||
|
{
|
||||||
|
removeByKeys(SYS_CACHE, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从缓存中移除指定key
|
||||||
|
*
|
||||||
|
* @param cacheName
|
||||||
|
* @param keys
|
||||||
|
*/
|
||||||
|
public static void removeByKeys(String cacheName, Set<String> keys)
|
||||||
|
{
|
||||||
|
for (Iterator<String> it = keys.iterator(); it.hasNext();)
|
||||||
|
{
|
||||||
|
remove(it.next());
|
||||||
|
}
|
||||||
|
logger.info("清理缓存: {} => {}", cacheName, keys);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取缓存键名
|
||||||
|
*
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static String getKey(String key)
|
||||||
|
{
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得一个Cache,没有则显示日志。
|
||||||
|
*
|
||||||
|
* @param cacheName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private static Cache<String, Object> getCache(String cacheName)
|
||||||
|
{
|
||||||
|
Cache<String, Object> cache = cacheManager.getCache(cacheName);
|
||||||
|
if (cache == null)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("当前系统中没有定义“" + cacheName + "”这个缓存。");
|
||||||
|
}
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -58,6 +58,11 @@ public interface ISysConfigService
|
||||||
*/
|
*/
|
||||||
public int deleteConfigByIds(String ids);
|
public int deleteConfigByIds(String ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清空缓存数据
|
||||||
|
*/
|
||||||
|
public void clearCache();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验参数键名是否唯一
|
* 校验参数键名是否唯一
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package com.ruoyi.system.service.impl;
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
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 com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.text.Convert;
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
import com.ruoyi.common.utils.CacheUtils;
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.system.domain.SysConfig;
|
import com.ruoyi.system.domain.SysConfig;
|
||||||
import com.ruoyi.system.mapper.SysConfigMapper;
|
import com.ruoyi.system.mapper.SysConfigMapper;
|
||||||
|
@ -21,6 +24,19 @@ public class SysConfigServiceImpl implements ISysConfigService
|
||||||
@Autowired
|
@Autowired
|
||||||
private SysConfigMapper configMapper;
|
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
|
@Override
|
||||||
public String selectConfigByKey(String configKey)
|
public String selectConfigByKey(String configKey)
|
||||||
{
|
{
|
||||||
|
String configValue = Convert.toStr(CacheUtils.get(getCacheName(), getCacheKey(configKey)));
|
||||||
|
if (StringUtils.isNotEmpty(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);
|
||||||
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
|
@Override
|
||||||
public int insertConfig(SysConfig config)
|
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
|
@Override
|
||||||
public int updateConfig(SysConfig config)
|
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
|
@Override
|
||||||
public int deleteConfigByIds(String ids)
|
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;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue