Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
05b5b314
Commit
05b5b314
authored
Mar 18, 2020
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
字典管理添加缓存读取
parent
f8491c36
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
235 additions
and
78 deletions
+235
-78
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
+14
-8
ruoyi-admin/src/main/resources/ehcache/ehcache-shiro.xml
+17
-1
ruoyi-admin/src/main/resources/templates/system/config/config.html
+1
-0
ruoyi-admin/src/main/resources/templates/system/dict/type/type.html
+9
-0
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
+10
-0
ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java
+7
-0
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/DictService.java
+5
-1
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
+0
-16
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
+15
-9
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
+19
-27
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
+66
-16
ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java
+72
-0
No files found.
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
View file @
05b5b314
...
...
@@ -125,14 +125,20 @@ public class SysDictTypeController extends BaseController
@ResponseBody
public
AjaxResult
remove
(
String
ids
)
{
try
{
return
toAjax
(
dictTypeService
.
deleteDictTypeByIds
(
ids
));
}
catch
(
Exception
e
)
{
return
error
(
e
.
getMessage
());
}
return
toAjax
(
dictTypeService
.
deleteDictTypeByIds
(
ids
));
}
/**
* 清空缓存
*/
@RequiresPermissions
(
"system:dict:remove"
)
@Log
(
title
=
"字典类型"
,
businessType
=
BusinessType
.
CLEAN
)
@GetMapping
(
"/clearCache"
)
@ResponseBody
public
AjaxResult
clearCache
()
{
dictTypeService
.
clearCache
();
return
success
();
}
/**
...
...
ruoyi-admin/src/main/resources/ehcache/ehcache-shiro.xml
View file @
05b5b314
...
...
@@ -41,7 +41,15 @@
timeToIdleSeconds=
"0"
statistics=
"true"
>
</cache>
<!-- 系统缓存 -->
<cache
name=
"sys-cache"
maxEntriesLocalHeap=
"1000"
eternal=
"true"
overflowToDisk=
"true"
statistics=
"true"
>
</cache>
<!-- 系统参数缓存 -->
<cache
name=
"sys-config"
maxEntriesLocalHeap=
"1000"
...
...
@@ -50,6 +58,14 @@
statistics=
"true"
>
</cache>
<!-- 系统字典缓存 -->
<cache
name=
"sys-dict"
maxEntriesLocalHeap=
"1000"
eternal=
"true"
overflowToDisk=
"true"
statistics=
"true"
>
</cache>
<!-- 系统会话缓存 -->
<cache
name=
"shiro-activeSessionCache"
maxElementsInMemory=
"10000"
...
...
ruoyi-admin/src/main/resources/templates/system/config/config.html
View file @
05b5b314
...
...
@@ -135,6 +135,7 @@
$
.
table
.
init
(
options
);
});
/** 清理参数缓存 */
function
clearCache
()
{
$
.
operate
.
get
(
prefix
+
"/clearCache"
);
}
...
...
ruoyi-admin/src/main/resources/templates/system/dict/type/type.html
View file @
05b5b314
...
...
@@ -50,6 +50,9 @@
<a
class=
"btn btn-warning"
onclick=
"$.table.exportExcel()"
shiro:hasPermission=
"system:dict:export"
>
<i
class=
"fa fa-download"
></i>
导出
</a>
<a
class=
"btn btn-danger"
onclick=
"clearCache()"
shiro:hasPermission=
"system:dict:remove"
>
<i
class=
"fa fa-refresh"
></i>
清理缓存
</a>
</div>
<div
class=
"col-sm-12 select-table table-striped"
>
...
...
@@ -132,6 +135,11 @@
var
url
=
prefix
+
'/detail/'
+
dictId
;
$
.
modal
.
openTab
(
"字典数据"
,
url
);
}
/** 清理字典缓存 */
function
clearCache
()
{
$
.
operate
.
get
(
prefix
+
"/clearCache"
);
}
</script>
</body>
</html>
\ No newline at end of file
ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java
View file @
05b5b314
...
...
@@ -68,6 +68,16 @@ public class Constants
public
static
final
String
SYS_CONFIG_KEY
=
"sys_config:"
;
/**
* 字典管理 cache name
*/
public
static
final
String
SYS_DICT_CACHE
=
"sys-dict"
;
/**
* 字典管理 cache key
*/
public
static
final
String
SYS_DICT_KEY
=
"sys_dict:"
;
/**
* 资源映射路径 前缀
*/
public
static
final
String
RESOURCE_PREFIX
=
"/profile"
;
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java
View file @
05b5b314
...
...
@@ -395,4 +395,10 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
}
return
sb
.
toString
();
}
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
T
cast
(
Object
obj
)
{
return
(
T
)
obj
;
}
}
\ No newline at end of file
ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/DictService.java
View file @
05b5b314
...
...
@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
com.ruoyi.system.domain.SysDictData
;
import
com.ruoyi.system.service.ISysDictDataService
;
import
com.ruoyi.system.service.ISysDictTypeService
;
/**
* RuoYi首创 html调用 thymeleaf 实现字典读取
...
...
@@ -15,6 +16,9 @@ import com.ruoyi.system.service.ISysDictDataService;
public
class
DictService
{
@Autowired
private
ISysDictTypeService
dictTypeService
;
@Autowired
private
ISysDictDataService
dictDataService
;
/**
...
...
@@ -25,7 +29,7 @@ public class DictService
*/
public
List
<
SysDictData
>
getType
(
String
dictType
)
{
return
dict
Data
Service
.
selectDictDataByType
(
dictType
);
return
dict
Type
Service
.
selectDictDataByType
(
dictType
);
}
/**
...
...
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
View file @
05b5b314
...
...
@@ -19,14 +19,6 @@ public interface ISysDictDataService
public
List
<
SysDictData
>
selectDictDataList
(
SysDictData
dictData
);
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
public
List
<
SysDictData
>
selectDictDataByType
(
String
dictType
);
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType 字典类型
...
...
@@ -44,14 +36,6 @@ public interface ISysDictDataService
public
SysDictData
selectDictDataById
(
Long
dictCode
);
/**
* 通过字典ID删除字典数据信息
*
* @param dictCode 字典数据ID
* @return 结果
*/
public
int
deleteDictDataById
(
Long
dictCode
);
/**
* 批量删除字典数据
*
* @param ids 需要删除的数据
...
...
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
View file @
05b5b314
...
...
@@ -2,6 +2,7 @@ package com.ruoyi.system.service;
import
java.util.List
;
import
com.ruoyi.common.core.domain.Ztree
;
import
com.ruoyi.system.domain.SysDictData
;
import
com.ruoyi.system.domain.SysDictType
;
/**
...
...
@@ -27,6 +28,14 @@ public interface ISysDictTypeService
public
List
<
SysDictType
>
selectDictTypeAll
();
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
public
List
<
SysDictData
>
selectDictDataByType
(
String
dictType
);
/**
* 根据字典类型ID查询信息
*
* @param dictId 字典类型ID
...
...
@@ -43,21 +52,18 @@ public interface ISysDictTypeService
public
SysDictType
selectDictTypeByType
(
String
dictType
);
/**
* 通过字典ID删除字典信息
*
* @param dictId 字典ID
* @return 结果
*/
public
int
deleteDictTypeById
(
Long
dictId
);
/**
* 批量删除字典类型
*
* @param ids 需要删除的数据
* @return 结果
* @throws Exception 异常
*/
public
int
deleteDictTypeByIds
(
String
ids
)
throws
Exception
;
public
int
deleteDictTypeByIds
(
String
ids
);
/**
* 清空缓存数据
*/
public
void
clearCache
();
/**
* 新增保存字典类型信息
...
...
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
View file @
05b5b314
...
...
@@ -7,6 +7,7 @@ import com.ruoyi.common.core.text.Convert;
import
com.ruoyi.system.domain.SysDictData
;
import
com.ruoyi.system.mapper.SysDictDataMapper
;
import
com.ruoyi.system.service.ISysDictDataService
;
import
com.ruoyi.system.utils.DictUtils
;
/**
* 字典 业务层处理
...
...
@@ -32,18 +33,6 @@ public class SysDictDataServiceImpl implements ISysDictDataService
}
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
@Override
public
List
<
SysDictData
>
selectDictDataByType
(
String
dictType
)
{
return
dictDataMapper
.
selectDictDataByType
(
dictType
);
}
/**
* 根据字典类型和字典键值查询字典数据信息
*
* @param dictType 字典类型
...
...
@@ -69,18 +58,6 @@ public class SysDictDataServiceImpl implements ISysDictDataService
}
/**
* 通过字典ID删除字典数据信息
*
* @param dictCode 字典数据ID
* @return 结果
*/
@Override
public
int
deleteDictDataById
(
Long
dictCode
)
{
return
dictDataMapper
.
deleteDictDataById
(
dictCode
);
}
/**
* 批量删除字典数据
*
* @param ids 需要删除的数据
...
...
@@ -89,7 +66,12 @@ public class SysDictDataServiceImpl implements ISysDictDataService
@Override
public
int
deleteDictDataByIds
(
String
ids
)
{
return
dictDataMapper
.
deleteDictDataByIds
(
Convert
.
toStrArray
(
ids
));
int
row
=
dictDataMapper
.
deleteDictDataByIds
(
Convert
.
toStrArray
(
ids
));
if
(
row
>
0
)
{
DictUtils
.
clearDictCache
();
}
return
row
;
}
/**
...
...
@@ -101,7 +83,12 @@ public class SysDictDataServiceImpl implements ISysDictDataService
@Override
public
int
insertDictData
(
SysDictData
dictData
)
{
return
dictDataMapper
.
insertDictData
(
dictData
);
int
row
=
dictDataMapper
.
insertDictData
(
dictData
);
if
(
row
>
0
)
{
DictUtils
.
clearDictCache
();
}
return
row
;
}
/**
...
...
@@ -113,6 +100,11 @@ public class SysDictDataServiceImpl implements ISysDictDataService
@Override
public
int
updateDictData
(
SysDictData
dictData
)
{
return
dictDataMapper
.
updateDictData
(
dictData
);
int
row
=
dictDataMapper
.
updateDictData
(
dictData
);
if
(
row
>
0
)
{
DictUtils
.
clearDictCache
();
}
return
row
;
}
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
View file @
05b5b314
...
...
@@ -2,6 +2,7 @@ package com.ruoyi.system.service.impl;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -10,10 +11,12 @@ import com.ruoyi.common.core.domain.Ztree;
import
com.ruoyi.common.core.text.Convert
;
import
com.ruoyi.common.exception.BusinessException
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.system.domain.SysDictData
;
import
com.ruoyi.system.domain.SysDictType
;
import
com.ruoyi.system.mapper.SysDictDataMapper
;
import
com.ruoyi.system.mapper.SysDictTypeMapper
;
import
com.ruoyi.system.service.ISysDictTypeService
;
import
com.ruoyi.system.utils.DictUtils
;
/**
* 字典 业务层处理
...
...
@@ -30,6 +33,20 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
private
SysDictDataMapper
dictDataMapper
;
/**
* 项目启动时,初始化字典到缓存
*/
@PostConstruct
public
void
init
()
{
List
<
SysDictType
>
dictTypeList
=
dictTypeMapper
.
selectDictTypeAll
();
for
(
SysDictType
dictType
:
dictTypeList
)
{
List
<
SysDictData
>
dictDatas
=
dictDataMapper
.
selectDictDataByType
(
dictType
.
getDictType
());
DictUtils
.
setDictCache
(
dictType
.
getDictType
(),
dictDatas
);
}
}
/**
* 根据条件分页查询字典类型
*
* @param dictType 字典类型信息
...
...
@@ -53,6 +70,29 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
}
/**
* 根据字典类型查询字典数据
*
* @param dictType 字典类型
* @return 字典数据集合信息
*/
@Override
public
List
<
SysDictData
>
selectDictDataByType
(
String
dictType
)
{
List
<
SysDictData
>
dictDatas
=
DictUtils
.
getDictCache
(
dictType
);
if
(
StringUtils
.
isNotNull
(
dictDatas
))
{
return
dictDatas
;
}
dictDatas
=
dictDataMapper
.
selectDictDataByType
(
dictType
);
if
(
StringUtils
.
isNotNull
(
dictDatas
))
{
DictUtils
.
setDictCache
(
dictType
,
dictDatas
);
return
dictDatas
;
}
return
null
;
}
/**
* 根据字典类型ID查询信息
*
* @param dictId 字典类型ID
...
...
@@ -76,25 +116,13 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
}
/**
* 通过字典ID删除字典信息
*
* @param dictId 字典ID
* @return 结果
*/
@Override
public
int
deleteDictTypeById
(
Long
dictId
)
{
return
dictTypeMapper
.
deleteDictTypeById
(
dictId
);
}
/**
* 批量删除字典类型
*
* @param ids 需要删除的数据
* @return 结果
*/
@Override
public
int
deleteDictTypeByIds
(
String
ids
)
throws
BusinessException
public
int
deleteDictTypeByIds
(
String
ids
)
{
Long
[]
dictIds
=
Convert
.
toLongArray
(
ids
);
for
(
Long
dictId
:
dictIds
)
...
...
@@ -105,8 +133,20 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
throw
new
BusinessException
(
String
.
format
(
"%1$s已分配,不能删除"
,
dictType
.
getDictName
()));
}
}
int
count
=
dictTypeMapper
.
deleteDictTypeByIds
(
dictIds
);
if
(
count
>
0
)
{
DictUtils
.
clearDictCache
();
}
return
count
;
}
return
dictTypeMapper
.
deleteDictTypeByIds
(
dictIds
);
/**
* 清空缓存数据
*/
public
void
clearCache
()
{
DictUtils
.
clearDictCache
();
}
/**
...
...
@@ -118,7 +158,12 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
@Override
public
int
insertDictType
(
SysDictType
dictType
)
{
return
dictTypeMapper
.
insertDictType
(
dictType
);
int
row
=
dictTypeMapper
.
insertDictType
(
dictType
);
if
(
row
>
0
)
{
DictUtils
.
clearDictCache
();
}
return
row
;
}
/**
...
...
@@ -133,7 +178,12 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
{
SysDictType
oldDict
=
dictTypeMapper
.
selectDictTypeById
(
dictType
.
getDictId
());
dictDataMapper
.
updateDictDataType
(
oldDict
.
getDictType
(),
dictType
.
getDictType
());
return
dictTypeMapper
.
updateDictType
(
dictType
);
int
row
=
dictTypeMapper
.
updateDictType
(
dictType
);
if
(
row
>
0
)
{
DictUtils
.
clearDictCache
();
}
return
row
;
}
/**
...
...
ruoyi-system/src/main/java/com/ruoyi/system/utils/DictUtils.java
0 → 100644
View file @
05b5b314
package
com
.
ruoyi
.
system
.
utils
;
import
java.util.List
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.utils.CacheUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.system.domain.SysDictData
;
/**
* 字典工具类
*
* @author ruoyi
*/
public
class
DictUtils
{
/**
* 设置字典缓存
*
* @param key 参数键
* @param dictDatas 字典数据列表
*/
public
static
void
setDictCache
(
String
key
,
List
<
SysDictData
>
dictDatas
)
{
CacheUtils
.
put
(
getCacheName
(),
getCacheKey
(
key
),
dictDatas
);
}
/**
* 获取字典缓存
*
* @param key 参数键
* @return dictDatas 字典数据列表
*/
public
static
List
<
SysDictData
>
getDictCache
(
String
key
)
{
Object
cacheObj
=
CacheUtils
.
get
(
getCacheName
(),
getCacheKey
(
key
));
if
(
StringUtils
.
isNotNull
(
cacheObj
))
{
List
<
SysDictData
>
DictDatas
=
StringUtils
.
cast
(
cacheObj
);
return
DictDatas
;
}
return
null
;
}
/**
* 清空字典缓存
*/
public
static
void
clearDictCache
()
{
CacheUtils
.
removeAll
(
getCacheName
());
}
/**
* 获取cache name
*
* @return 缓存名
*/
public
static
String
getCacheName
()
{
return
Constants
.
SYS_DICT_CACHE
;
}
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
public
static
String
getCacheKey
(
String
configKey
)
{
return
Constants
.
SYS_DICT_KEY
+
configKey
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment