Authored by LUOXC

Merge branch 'hotfix-20181219' into test6.8.4

@@ -16,6 +16,7 @@ import com.yohoufo.resource.util.RedisLoadingCache; @@ -16,6 +16,7 @@ import com.yohoufo.resource.util.RedisLoadingCache;
16 import com.yohoufo.resource.util.ValueSerializer; 16 import com.yohoufo.resource.util.ValueSerializer;
17 import org.slf4j.Logger; 17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 18 import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.InitializingBean;
19 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
20 import org.springframework.stereotype.Service; 21 import org.springframework.stereotype.Service;
21 22
@@ -28,7 +29,7 @@ import java.util.concurrent.TimeUnit; @@ -28,7 +29,7 @@ import java.util.concurrent.TimeUnit;
28 import java.util.stream.Collectors; 29 import java.util.stream.Collectors;
29 30
30 @Service 31 @Service
31 -public class ConfigTypeServiceImpl implements IConfigTypeService { 32 +public class ConfigTypeServiceImpl implements IConfigTypeService, InitializingBean {
32 private static final Logger LOGGER = LoggerFactory.getLogger(ConfigTypeServiceImpl.class); 33 private static final Logger LOGGER = LoggerFactory.getLogger(ConfigTypeServiceImpl.class);
33 34
34 private LocalCache localCache = new LocalCache(); 35 private LocalCache localCache = new LocalCache();
@@ -44,41 +45,46 @@ public class ConfigTypeServiceImpl implements IConfigTypeService { @@ -44,41 +45,46 @@ public class ConfigTypeServiceImpl implements IConfigTypeService {
44 @Redis("yohoNoSyncRedis") 45 @Redis("yohoNoSyncRedis")
45 private YHValueOperations valueOperations; 46 private YHValueOperations valueOperations;
46 47
47 - private final RedisLoadingCache<String, ConfigType> codeConfigTypeRedisCache = RedisCacheBuilder.newBuilder()  
48 - .withYhRedis(redisTemplate, valueOperations)  
49 - .withExpire(5, TimeUnit.SECONDS)  
50 - .withKeySerializer(new KeySerializer<String>() {  
51 - @Override  
52 - public RedisKeyBuilder serialize(String obj) {  
53 - return new RedisKeyBuilder().appendFixed("ufo:resources:configType:code:").appendVar(obj);  
54 - }  
55 -  
56 - @Override  
57 - public String deserialize(RedisKeyBuilder keyBuilder) {  
58 - return keyBuilder.getKey().substring(keyBuilder.getKey().lastIndexOf("ufo:resources:configType:") + 1);  
59 - }  
60 - })  
61 - .withValueSerializer(new ValueSerializer<ConfigType>() {  
62 -  
63 - @Override  
64 - public String serialize(ConfigType obj) {  
65 - return JSONObject.toJSONString(obj);  
66 - }  
67 -  
68 - @Override  
69 - public ConfigType deserialize(String objectData) {  
70 - return JSONObject.parseObject(objectData, ConfigType.class);  
71 - }  
72 -  
73 - })  
74 - .build(new CacheLoader<String, ConfigType>() {  
75 -  
76 - @Override  
77 - public ConfigType load(String code) throws Exception {  
78 - return configTypeMapper.selectByCode(code);  
79 - }  
80 -  
81 - }); 48 + private RedisLoadingCache<String, ConfigType> codeConfigTypeRedisCache;
  49 +
  50 + @Override
  51 + public void afterPropertiesSet() throws Exception {
  52 + codeConfigTypeRedisCache = RedisCacheBuilder.newBuilder()
  53 + .withYhRedis(redisTemplate, valueOperations)
  54 + .withExpire(5, TimeUnit.SECONDS)
  55 + .withKeySerializer(new KeySerializer<String>() {
  56 + @Override
  57 + public RedisKeyBuilder serialize(String obj) {
  58 + return new RedisKeyBuilder().appendFixed("ufo:resources:configType:code:").appendVar(obj);
  59 + }
  60 +
  61 + @Override
  62 + public String deserialize(RedisKeyBuilder keyBuilder) {
  63 + return keyBuilder.getKey().substring(keyBuilder.getKey().lastIndexOf("ufo:resources:configType:") + 1);
  64 + }
  65 + })
  66 + .withValueSerializer(new ValueSerializer<ConfigType>() {
  67 +
  68 + @Override
  69 + public String serialize(ConfigType obj) {
  70 + return JSONObject.toJSONString(obj);
  71 + }
  72 +
  73 + @Override
  74 + public ConfigType deserialize(String objectData) {
  75 + return JSONObject.parseObject(objectData, ConfigType.class);
  76 + }
  77 +
  78 + })
  79 + .build(new CacheLoader<String, ConfigType>() {
  80 +
  81 + @Override
  82 + public ConfigType load(String code) throws Exception {
  83 + return configTypeMapper.selectByCode(code);
  84 + }
  85 +
  86 + });
  87 + }
82 88
83 @PostConstruct 89 @PostConstruct
84 private void init() { 90 private void init() {
@@ -126,4 +132,5 @@ public class ConfigTypeServiceImpl implements IConfigTypeService { @@ -126,4 +132,5 @@ public class ConfigTypeServiceImpl implements IConfigTypeService {
126 return rows; 132 return rows;
127 } 133 }
128 134
  135 +
129 } 136 }