|
|
@@ -1,12 +1,15 @@
|
|
1
|
1
|
package com.ruoyi.system.service.impl;
|
|
2
|
2
|
|
|
|
3
|
+import java.util.Collection;
|
|
3
|
4
|
import java.util.List;
|
|
4
|
|
-
|
|
|
5
|
+import javax.annotation.PostConstruct;
|
|
5
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
7
|
import org.springframework.stereotype.Service;
|
|
7
|
|
-
|
|
|
8
|
+import com.ruoyi.common.core.constant.Constants;
|
|
8
|
9
|
import com.ruoyi.common.core.constant.UserConstants;
|
|
|
10
|
+import com.ruoyi.common.core.text.Convert;
|
|
9
|
11
|
import com.ruoyi.common.core.utils.StringUtils;
|
|
|
12
|
+import com.ruoyi.common.redis.service.RedisService;
|
|
10
|
13
|
import com.ruoyi.system.domain.SysConfig;
|
|
11
|
14
|
import com.ruoyi.system.mapper.SysConfigMapper;
|
|
12
|
15
|
import com.ruoyi.system.service.ISysConfigService;
|
|
|
@@ -22,6 +25,22 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
22
|
25
|
@Autowired
|
|
23
|
26
|
private SysConfigMapper configMapper;
|
|
24
|
27
|
|
|
|
28
|
+ @Autowired
|
|
|
29
|
+ private RedisService redisService;
|
|
|
30
|
+
|
|
|
31
|
+ /**
|
|
|
32
|
+ * 项目启动时,初始化参数到缓存
|
|
|
33
|
+ */
|
|
|
34
|
+ @PostConstruct
|
|
|
35
|
+ public void init()
|
|
|
36
|
+ {
|
|
|
37
|
+ List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
|
|
|
38
|
+ for (SysConfig config : configsList)
|
|
|
39
|
+ {
|
|
|
40
|
+ redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
41
|
+ }
|
|
|
42
|
+ }
|
|
|
43
|
+
|
|
25
|
44
|
/**
|
|
26
|
45
|
* 查询参数配置信息
|
|
27
|
46
|
*
|
|
|
@@ -45,10 +64,20 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
45
|
64
|
@Override
|
|
46
|
65
|
public String selectConfigByKey(String configKey)
|
|
47
|
66
|
{
|
|
|
67
|
+ String configValue = Convert.toStr(redisService.getCacheObject(getCacheKey(configKey)));
|
|
|
68
|
+ if (StringUtils.isNotEmpty(configValue))
|
|
|
69
|
+ {
|
|
|
70
|
+ return configValue;
|
|
|
71
|
+ }
|
|
48
|
72
|
SysConfig config = new SysConfig();
|
|
49
|
73
|
config.setConfigKey(configKey);
|
|
50
|
74
|
SysConfig retConfig = configMapper.selectConfig(config);
|
|
51
|
|
- return StringUtils.isNotNull(retConfig) ? retConfig.getConfigValue() : "";
|
|
|
75
|
+ if (StringUtils.isNotNull(retConfig))
|
|
|
76
|
+ {
|
|
|
77
|
+ redisService.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
|
|
|
78
|
+ return retConfig.getConfigValue();
|
|
|
79
|
+ }
|
|
|
80
|
+ return StringUtils.EMPTY;
|
|
52
|
81
|
}
|
|
53
|
82
|
|
|
54
|
83
|
/**
|
|
|
@@ -72,7 +101,12 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
72
|
101
|
@Override
|
|
73
|
102
|
public int insertConfig(SysConfig config)
|
|
74
|
103
|
{
|
|
75
|
|
- return configMapper.insertConfig(config);
|
|
|
104
|
+ int row = configMapper.insertConfig(config);
|
|
|
105
|
+ if (row > 0)
|
|
|
106
|
+ {
|
|
|
107
|
+ redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
108
|
+ }
|
|
|
109
|
+ return row;
|
|
76
|
110
|
}
|
|
77
|
111
|
|
|
78
|
112
|
/**
|
|
|
@@ -84,31 +118,39 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
84
|
118
|
@Override
|
|
85
|
119
|
public int updateConfig(SysConfig config)
|
|
86
|
120
|
{
|
|
87
|
|
- return configMapper.updateConfig(config);
|
|
|
121
|
+ int row = configMapper.updateConfig(config);
|
|
|
122
|
+ if (row > 0)
|
|
|
123
|
+ {
|
|
|
124
|
+ redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
|
|
125
|
+ }
|
|
|
126
|
+ return row;
|
|
88
|
127
|
}
|
|
89
|
128
|
|
|
90
|
129
|
/**
|
|
91
|
|
- * 删除参数配置信息
|
|
|
130
|
+ * 批量删除参数信息
|
|
92
|
131
|
*
|
|
93
|
|
- * @param configId 参数ID
|
|
|
132
|
+ * @param configIds 需要删除的参数ID
|
|
94
|
133
|
* @return 结果
|
|
95
|
134
|
*/
|
|
96
|
135
|
@Override
|
|
97
|
|
- public int deleteConfigById(Long configId)
|
|
|
136
|
+ public int deleteConfigByIds(Long[] configIds)
|
|
98
|
137
|
{
|
|
99
|
|
- return configMapper.deleteConfigById(configId);
|
|
|
138
|
+ int count = configMapper.deleteConfigByIds(configIds);
|
|
|
139
|
+ if (count > 0)
|
|
|
140
|
+ {
|
|
|
141
|
+ Collection<String> keys = redisService.keys(Constants.SYS_CONFIG_KEY + "*");
|
|
|
142
|
+ redisService.deleteObject(keys);
|
|
|
143
|
+ }
|
|
|
144
|
+ return count;
|
|
100
|
145
|
}
|
|
101
|
146
|
|
|
102
|
147
|
/**
|
|
103
|
|
- * 批量删除参数信息
|
|
104
|
|
- *
|
|
105
|
|
- * @param configIds 需要删除的参数ID
|
|
106
|
|
- * @return 结果
|
|
|
148
|
+ * 清空缓存数据
|
|
107
|
149
|
*/
|
|
108
|
|
- @Override
|
|
109
|
|
- public int deleteConfigByIds(Long[] configIds)
|
|
|
150
|
+ public void clearCache()
|
|
110
|
151
|
{
|
|
111
|
|
- return configMapper.deleteConfigByIds(configIds);
|
|
|
152
|
+ Collection<String> keys = redisService.keys(Constants.SYS_CONFIG_KEY + "*");
|
|
|
153
|
+ redisService.deleteObject(keys);
|
|
112
|
154
|
}
|
|
113
|
155
|
|
|
114
|
156
|
/**
|
|
|
@@ -128,4 +170,15 @@ public class SysConfigServiceImpl implements ISysConfigService
|
|
128
|
170
|
}
|
|
129
|
171
|
return UserConstants.UNIQUE;
|
|
130
|
172
|
}
|
|
|
173
|
+
|
|
|
174
|
+ /**
|
|
|
175
|
+ * 设置cache key
|
|
|
176
|
+ *
|
|
|
177
|
+ * @param configKey 参数键
|
|
|
178
|
+ * @return 缓存键key
|
|
|
179
|
+ */
|
|
|
180
|
+ private String getCacheKey(String configKey)
|
|
|
181
|
+ {
|
|
|
182
|
+ return Constants.SYS_CONFIG_KEY + configKey;
|
|
|
183
|
+ }
|
|
131
|
184
|
}
|