ConfigCache.java
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package com.jflyfox.system.config;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.jfinal.log.Log;
import com.jflyfox.system.user.UserCache;
import com.jflyfox.util.NumberUtils;
import com.jflyfox.util.cache.Cache;
import com.jflyfox.util.cache.CacheManager;
/**
* 配置管理缓存
*
* 2016年12月17日 下午11:26:25 flyfox 369191470@qq.com
*/
public class ConfigCache {
private final static Log log = Log.getLog(UserCache.class);
private final static String cacheName = "ConfigCache";
private static Cache cache;
private ConfigCache() {
}
public static void init() {
if (cache == null) {
cache = CacheManager.get(cacheName);
}
log.info("####参数配置Cache初始化......");
Map<String, SysConfig> cacheMap = new HashMap<String, SysConfig>();
List<SysConfig> userList = SysConfig.dao.findByWhere(" order by sort,id ");
for (SysConfig config : userList) {
cacheMap.put(config.getKey(), config);
}
cache.add("cacheMap", cacheMap);
}
public static void update() {
init();
}
public static SysConfig getSysConfig(String key) {
return getSysConfigMap().get(key);
}
public static String getValue(String key) {
return getSysConfig(key) == null ? null : getSysConfig(key).getValue();
}
public static int getValueToInt(String key) {
return NumberUtils.parseInt(getValue(key));
}
public static Boolean getValueToBoolean(String key) {
String val = getValue(key);
try {
return Boolean.valueOf(val);
} catch (Exception e) {
return false;
}
}
public static String getCode(String key) {
return getSysConfig(key) == null ? null : getSysConfig(key).getCode();
}
private static Map<String, SysConfig> getSysConfigMap() {
return cache.get("cacheMap");
}
}