Skip to content

Commit 0d79a38

Browse files
committed
#448 Console system config need to be case sensitive
1 parent f0ab827 commit 0d79a38

File tree

8 files changed

+70
-6
lines changed

8 files changed

+70
-6
lines changed

saturn-console-api/src/main/java/com/vip/saturn/job/console/controller/gui/ConsoleConfigController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public SuccessResponseEntity getConfigs() throws IOException, SaturnJobConsoleEx
104104
//获取配置meta
105105
Map<String, List<JobConfigMeta>> jobConfigGroups = getSystemConfigMeta();
106106
//返回所有配置信息
107-
List<SystemConfig> systemConfigs = systemConfigService.getSystemConfigsDirectly(null);
107+
List<SystemConfig> systemConfigs = systemConfigService.getAllSystemConfigs();
108108
//剔除EXECUTOR_CONFIGS
109109
removeExecutorConfigs(systemConfigs);
110110

saturn-console-api/src/main/java/com/vip/saturn/job/console/mybatis/repository/SystemConfigRepository.java

+3
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ public interface SystemConfigRepository {
2020

2121
Integer updateById(SystemConfig systemConfig);
2222

23+
List<SystemConfig> selectByProperty(String property);
24+
25+
List<SystemConfig> selectAllConfig();
2326
}

saturn-console-api/src/main/java/com/vip/saturn/job/console/mybatis/service/SystemConfig4SqlService.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
package com.vip.saturn.job.console.mybatis.service;
22

33
import com.vip.saturn.job.console.mybatis.entity.SystemConfig;
4+
45
import java.util.List;
56

67
/**
78
* @author hebelala
89
*/
910
public interface SystemConfig4SqlService {
1011

12+
List<SystemConfig> selectAllConfig();
13+
14+
List<SystemConfig> selectByProperty(String property);
15+
1116
List<SystemConfig> selectByPropertiesAndLastly(List<String> properties);
1217

1318
List<SystemConfig> selectByLastly();

saturn-console-api/src/main/java/com/vip/saturn/job/console/mybatis/service/impl/SystemConfig4SqlServiceImpl.java

+10
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ public class SystemConfig4SqlServiceImpl implements SystemConfig4SqlService {
1818
@Autowired
1919
private SystemConfigRepository systemConfigRepository;
2020

21+
@Override
22+
public List<SystemConfig> selectAllConfig() {
23+
return systemConfigRepository.selectAllConfig();
24+
}
25+
26+
@Override
27+
public List<SystemConfig> selectByProperty(String property) {
28+
return systemConfigRepository.selectByProperty(property);
29+
}
30+
2131
@Transactional(readOnly = true)
2232
@Override
2333
public List<SystemConfig> selectByPropertiesAndLastly(List<String> properties) {

saturn-console-api/src/main/java/com/vip/saturn/job/console/service/SystemConfigService.java

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public interface SystemConfigService {
2222

2323
boolean getBooleanValue(String property, boolean defaultValue);
2424

25+
List<SystemConfig> getAllSystemConfigs();
26+
2527
List<SystemConfig> getSystemConfigsDirectly(List<String> properties) throws SaturnJobConsoleException;
2628

2729
List<SystemConfig> getSystemConfigsByPrefix(String prefix) throws SaturnJobConsoleException;

saturn-console-api/src/main/java/com/vip/saturn/job/console/service/impl/SystemConfigServiceImpl.java

+27-5
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ public boolean getBooleanValue(String property, boolean defaultValue) {
136136
}
137137
}
138138

139+
@Override
140+
public List<SystemConfig> getAllSystemConfigs() {
141+
return systemConfig4SqlService.selectAllConfig();
142+
}
143+
139144
@Override
140145
public List<SystemConfig> getSystemConfigsDirectly(List<String> properties) throws SaturnJobConsoleException {
141146
return properties != null && !properties.isEmpty() ?
@@ -194,9 +199,18 @@ public Integer insertOrUpdate(SystemConfig systemConfig) throws SaturnJobConsole
194199
public Integer createConfig(SystemConfig systemConfig) throws SaturnJobConsoleException {
195200
List<String> properties = new ArrayList<>();
196201
properties.add(systemConfig.getProperty());
197-
List<SystemConfig> systemConfigs = systemConfig4SqlService.selectByPropertiesAndLastly(properties);
202+
List<SystemConfig> systemConfigs = systemConfig4SqlService.selectByProperty(systemConfig.getProperty());
203+
204+
boolean found = false;
205+
for (int i = 0; i < systemConfigs.size(); i++) {
206+
SystemConfig config = systemConfigs.get(i);
207+
if (StringUtils.equals(config.getProperty(), systemConfig.getProperty())) {
208+
found = true;
209+
break;
210+
}
211+
}
198212

199-
if (systemConfig != null && systemConfigs.size() > 0) {
213+
if (systemConfig != null && systemConfigs.size() > 0 && found) {
200214
throw new SaturnJobConsoleException(
201215
String.format("systemConfig %s already existed", systemConfig.getProperty()));
202216
}
@@ -210,14 +224,22 @@ public Integer createConfig(SystemConfig systemConfig) throws SaturnJobConsoleEx
210224
public Integer updateConfig(SystemConfig systemConfig) throws SaturnJobConsoleException {
211225
List<String> properties = new ArrayList<>();
212226
properties.add(systemConfig.getProperty());
213-
List<SystemConfig> systemConfigs = systemConfig4SqlService.selectByPropertiesAndLastly(properties);
227+
List<SystemConfig> systemConfigs = systemConfig4SqlService.selectByProperty(systemConfig.getProperty());
214228

215-
if (systemConfig == null || systemConfigs.size() == 0) {
229+
SystemConfig targetConfig = null;
230+
for (int i = 0; i < systemConfigs.size(); i++) {
231+
SystemConfig config = systemConfigs.get(i);
232+
if (StringUtils.equals(config.getProperty(), systemConfig.getProperty())) {
233+
targetConfig = config;
234+
break;
235+
}
236+
}
237+
if (targetConfig == null) {
216238
throw new SaturnJobConsoleException(
217239
String.format("systemConfig %s not existed, update fail", systemConfig.getProperty()));
218240
}
219241

220-
SystemConfig config = systemConfigs.get(0);
242+
SystemConfig config = targetConfig;
221243
config.setProperty(systemConfig.getProperty());
222244
config.setValue(systemConfig.getValue());
223245
int result = systemConfig4SqlService.updateById(config);

saturn-console-api/src/main/resources/mapper/SystemConfigMapper.xml

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
<sql id="Base_Column_List">
1010
id, property, value
1111
</sql>
12+
<select id="selectAllConfig" resultMap="BaseResultMap">
13+
select
14+
<include refid="Base_Column_List"/>
15+
from sys_config
16+
</select>
17+
<select id="selectByProperty" resultMap="BaseResultMap">
18+
select
19+
<include refid="Base_Column_List"/>
20+
from sys_config
21+
where property = #{property}
22+
</select>
1223
<select id="selectByPropertiesAndLastly" resultMap="BaseResultMap">
1324
select
1425
<include refid="Base_Column_List"/>

saturn-console-core/src/main/resources/mapper/SystemConfigMapper.xml

+11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@
99
<sql id="Base_Column_List">
1010
id, property, value
1111
</sql>
12+
<select id="selectAllConfig" resultMap="BaseResultMap">
13+
select
14+
<include refid="Base_Column_List"/>
15+
from sys_config
16+
</select>
17+
<select id="selectByProperty" resultMap="BaseResultMap">
18+
select
19+
<include refid="Base_Column_List"/>
20+
from sys_config
21+
where property = #{property}
22+
</select>
1223
<select id="selectByPropertiesAndLastly" resultMap="BaseResultMap">
1324
select
1425
<include refid="Base_Column_List"/>

0 commit comments

Comments
 (0)