|
@@ -40,34 +40,34 @@ public class ConfigController extends GenericController<Config, String> {
|
|
* 批量获取缓存,如传入["core.system.version","upload.path"] 将获取core中的system.version属性和upload中的path属性
|
|
* 批量获取缓存,如传入["core.system.version","upload.path"] 将获取core中的system.version属性和upload中的path属性
|
|
* <br/>并返回结果如: {"core":{"system.version":"1.0"},"upload":{"path":"/files"}}
|
|
* <br/>并返回结果如: {"core":{"system.version":"1.0"},"upload":{"path":"/files"}}
|
|
*
|
|
*
|
|
- * @param resources 请求获取的配置列表
|
|
|
|
|
|
+ * @param ids 请求获取的配置列表
|
|
* @return 配置内容
|
|
* @return 配置内容
|
|
*/
|
|
*/
|
|
@RequestMapping(value = "/info", method = RequestMethod.GET)
|
|
@RequestMapping(value = "/info", method = RequestMethod.GET)
|
|
- @Cacheable(value = CACHE_KEY, key = "'info_list'+#resources.hashCode()")
|
|
|
|
|
|
+ @Cacheable(value = CACHE_KEY, key = "'info_list'+#ids.hashCode()")
|
|
@AccessLogger("批量获取配置")
|
|
@AccessLogger("批量获取配置")
|
|
- public Object batch(@RequestParam(value = "resources", defaultValue = "[]") String resources) {
|
|
|
|
- List<String> requestData = JSON.parseArray(resources, String.class);
|
|
|
|
|
|
+ public Object batch(@RequestParam(value = "ids", defaultValue = "[]") String ids, boolean map) {
|
|
|
|
+ List<String> requestData = JSON.parseArray(ids, String.class);
|
|
//获取缓存里的配置
|
|
//获取缓存里的配置
|
|
Map<String, Object> config = new LinkedHashMap<>();
|
|
Map<String, Object> config = new LinkedHashMap<>();
|
|
//临时缓存,用于当进行如: cfg.name,cfg.data,cfg.other。等获取时,cfg只获取一次,提升效率
|
|
//临时缓存,用于当进行如: cfg.name,cfg.data,cfg.other。等获取时,cfg只获取一次,提升效率
|
|
Map<String, Map<String, String>> temp = new LinkedHashMap<>();
|
|
Map<String, Map<String, String>> temp = new LinkedHashMap<>();
|
|
for (String request : requestData) {
|
|
for (String request : requestData) {
|
|
|
|
+ Config conf = null;
|
|
|
|
+ try {
|
|
|
|
+ conf = configService.selectByPk(request);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ }
|
|
//如果包含[.],则代表是获取当个配置属性。如: core.system.version,将获取core配置中的system.version属性
|
|
//如果包含[.],则代表是获取当个配置属性。如: core.system.version,将获取core配置中的system.version属性
|
|
- if (request.contains(".")) {
|
|
|
|
- String[] res = request.split("[.]");
|
|
|
|
- if (res.length > 2) {
|
|
|
|
- for (int i = 2; i < res.length; i++) {
|
|
|
|
- res[1] = res[1].concat(".").concat(res[i]);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (conf == null && request.contains(".")) {
|
|
|
|
+ String[] res = request.split("[.]", 2);
|
|
String name = res[0]; //如: core
|
|
String name = res[0]; //如: core
|
|
String key = res[1]; //如: system.version
|
|
String key = res[1]; //如: system.version
|
|
Map cache;
|
|
Map cache;
|
|
//获取临时缓存中的配置
|
|
//获取临时缓存中的配置
|
|
if ((cache = temp.get(name)) == null) {
|
|
if ((cache = temp.get(name)) == null) {
|
|
try {
|
|
try {
|
|
- Config conf = configService.selectByPk(name);
|
|
|
|
|
|
+ conf = configService.selectByPk(name);
|
|
cache = conf.toMap();
|
|
cache = conf.toMap();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
}
|
|
}
|
|
@@ -87,13 +87,8 @@ public class ConfigController extends GenericController<Config, String> {
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
//获取完整配置
|
|
//获取完整配置
|
|
- Config conf = null;
|
|
|
|
- try {
|
|
|
|
- conf = configService.selectByPk(request);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- }
|
|
|
|
if (conf != null) {
|
|
if (conf != null) {
|
|
- config.put(request, conf.toMap());
|
|
|
|
|
|
+ config.put(request, map ? conf.toMap() : conf.toList());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -107,12 +102,19 @@ public class ConfigController extends GenericController<Config, String> {
|
|
* @param name 配置名称
|
|
* @param name 配置名称
|
|
* @return 配置内容
|
|
* @return 配置内容
|
|
*/
|
|
*/
|
|
- @RequestMapping(value = "/info/{name:.+}", method = RequestMethod.GET)
|
|
|
|
- @AccessLogger("根据配置名获取配置")
|
|
|
|
|
|
+ @RequestMapping(value = "/{name:.+}.map", method = RequestMethod.GET)
|
|
|
|
+ @AccessLogger("根据配置名获取配置(map格式)")
|
|
public Object configInfo(@PathVariable("name") String name) throws Exception {
|
|
public Object configInfo(@PathVariable("name") String name) throws Exception {
|
|
return configService.get(name);
|
|
return configService.get(name);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @RequestMapping(value = "/{name:.+}.array", method = RequestMethod.GET)
|
|
|
|
+ @AccessLogger("根据配置名获取配置(list格式)")
|
|
|
|
+ public Object listInfo(@PathVariable("name") String name) throws Exception {
|
|
|
|
+ String content = configService.getContent(name);
|
|
|
|
+ if (content == null) content = "[]";
|
|
|
|
+ return content;
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* 获取一个配置中的某个属性
|
|
* 获取一个配置中的某个属性
|
|
@@ -121,10 +123,10 @@ public class ConfigController extends GenericController<Config, String> {
|
|
* @param key 配置属性,支持.,如 system.version
|
|
* @param key 配置属性,支持.,如 system.version
|
|
* @return 配置内容
|
|
* @return 配置内容
|
|
*/
|
|
*/
|
|
- @RequestMapping(value = {"/info/{name:.+}/{key:.+}"}, method = RequestMethod.GET)
|
|
|
|
|
|
+ @RequestMapping(value = {"/{name:.+}/{key:.+}"}, method = RequestMethod.GET)
|
|
@AccessLogger("根据配置名和键获取配置")
|
|
@AccessLogger("根据配置名和键获取配置")
|
|
public Object configInfo(@PathVariable("name") String name, @PathVariable("key") String key) throws Exception {
|
|
public Object configInfo(@PathVariable("name") String name, @PathVariable("key") String key) throws Exception {
|
|
- return configService.get(name, key,"");
|
|
|
|
|
|
+ return configService.get(name, key, "");
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -139,8 +141,16 @@ public class ConfigController extends GenericController<Config, String> {
|
|
return super.add(object);
|
|
return super.add(object);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ @Authorize(module = "config", action = "D")
|
|
|
|
+ @RequestMapping(value = "/{id:.+}", method = RequestMethod.DELETE)
|
|
|
|
+ public ResponseMessage delete(@PathVariable("id") String id) throws Exception {
|
|
|
|
+ return super.delete(id);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Authorize(module = "config", action = "U")
|
|
@Authorize(module = "config", action = "U")
|
|
|
|
+ @RequestMapping(value = "/{id:.+}", method = RequestMethod.PUT)
|
|
public ResponseMessage update(@PathVariable("id") String id, @RequestBody Config object) throws Exception {
|
|
public ResponseMessage update(@PathVariable("id") String id, @RequestBody Config object) throws Exception {
|
|
return super.update(id, object);
|
|
return super.update(id, object);
|
|
}
|
|
}
|