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