cee572f2
RuoYi
若依 3.0
|
1
|
package com.ruoyi.system.service.impl;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
2
|
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
3
|
import java.util.Collection;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
4
|
import java.util.List;
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
5
|
import javax.annotation.PostConstruct;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
6
7
|
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
|
cee572f2
RuoYi
若依 3.0
|
8
|
import com.ruoyi.common.annotation.DataSource;
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
9
|
import com.ruoyi.common.constant.Constants;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
10
|
import com.ruoyi.common.constant.UserConstants;
|
cee572f2
RuoYi
若依 3.0
|
11
|
import com.ruoyi.common.core.redis.RedisCache;
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
12
|
import com.ruoyi.common.core.text.Convert;
|
cee572f2
RuoYi
若依 3.0
|
13
|
import com.ruoyi.common.enums.DataSourceType;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
14
|
import com.ruoyi.common.utils.StringUtils;
|
cee572f2
RuoYi
若依 3.0
|
15
16
17
|
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.service.ISysConfigService;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
18
19
20
21
22
23
24
25
26
27
28
29
|
/**
* 参数配置 服务层实现
*
* @author ruoyi
*/
@Service
public class SysConfigServiceImpl implements ISysConfigService
{
@Autowired
private SysConfigMapper configMapper;
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
@Autowired
private RedisCache redisCache;
/**
* 项目启动时,初始化参数到缓存
*/
@PostConstruct
public void init()
{
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
for (SysConfig config : configsList)
{
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
}
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
46
47
48
49
50
51
52
|
/**
* 查询参数配置信息
*
* @param configId 参数配置ID
* @return 参数配置信息
*/
@Override
|
cee572f2
RuoYi
若依 3.0
|
53
|
@DataSource(DataSourceType.MASTER)
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
public SysConfig selectConfigById(Long configId)
{
SysConfig config = new SysConfig();
config.setConfigId(configId);
return configMapper.selectConfig(config);
}
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数key
* @return 参数键值
*/
@Override
|
b508e6f2
RuoYi
新增用户导入
|
68
|
public String selectConfigByKey(String configKey)
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
69
|
{
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
70
71
72
73
74
|
String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
if (StringUtils.isNotEmpty(configValue))
{
return configValue;
}
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
75
76
77
|
SysConfig config = new SysConfig();
config.setConfigKey(configKey);
SysConfig retConfig = configMapper.selectConfig(config);
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
78
79
80
81
82
83
|
if (StringUtils.isNotNull(retConfig))
{
redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
return retConfig.getConfigValue();
}
return StringUtils.EMPTY;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
}
/**
* 查询参数配置列表
*
* @param config 参数配置信息
* @return 参数配置集合
*/
@Override
public List<SysConfig> selectConfigList(SysConfig config)
{
return configMapper.selectConfigList(config);
}
/**
* 新增参数配置
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public int insertConfig(SysConfig config)
{
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
107
108
109
110
111
112
|
int row = configMapper.insertConfig(config);
if (row > 0)
{
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return row;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
113
114
115
116
117
118
119
120
121
122
123
|
}
/**
* 修改参数配置
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public int updateConfig(SysConfig config)
{
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
124
125
126
127
128
129
|
int row = configMapper.updateConfig(config);
if (row > 0)
{
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return row;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
130
131
132
|
}
/**
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
133
|
* 批量删除参数信息
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
134
|
*
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
135
|
* @param configIds 需要删除的参数ID
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
136
137
138
|
* @return 结果
*/
@Override
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
139
|
public int deleteConfigByIds(Long[] configIds)
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
140
|
{
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
141
142
143
144
145
146
147
|
int count = configMapper.deleteConfigByIds(configIds);
if (count > 0)
{
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
redisCache.deleteObject(keys);
}
return count;
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
148
149
150
|
}
/**
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
151
|
* 清空缓存数据
|
bcee37b8
RuoYi
若依 1.1
|
152
|
*/
|
f39be3ab
Sxile
添加缺少的@ Override
|
153
|
@Override
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
154
|
public void clearCache()
|
bcee37b8
RuoYi
若依 1.1
|
155
|
{
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
156
157
|
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
redisCache.deleteObject(keys);
|
bcee37b8
RuoYi
若依 1.1
|
158
159
160
|
}
/**
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
* 校验参数键名是否唯一
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public String 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())
{
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
|
0d546e4b
RuoYi
参数管理支持缓存操作
|
177
178
179
180
181
182
183
184
185
186
187
|
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
private String getCacheKey(String configKey)
{
return Constants.SYS_CONFIG_KEY + configKey;
}
|
46444bd0
RuoYi
RuoYi-Vue 1.0
|
188
|
}
|