1
|
package com.yohoufo.order.service.impl;
|
1
|
package com.yohoufo.order.service.impl;
|
2
|
|
2
|
|
3
|
import com.alibaba.fastjson.JSONObject;
|
3
|
import com.alibaba.fastjson.JSONObject;
|
|
|
4
|
+import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
4
|
import com.yohobuy.ufo.model.order.common.MetaConfigKey;
|
5
|
import com.yohobuy.ufo.model.order.common.MetaConfigKey;
|
|
|
6
|
+import com.yohoufo.common.cache.CacheClient;
|
5
|
import com.yohoufo.dal.order.MetaConfigMapper;
|
7
|
import com.yohoufo.dal.order.MetaConfigMapper;
|
6
|
import com.yohoufo.dal.order.model.MetaConfig;
|
8
|
import com.yohoufo.dal.order.model.MetaConfig;
|
7
|
import com.yohoufo.order.model.dto.BuyerPenalty;
|
9
|
import com.yohoufo.order.model.dto.BuyerPenalty;
|
|
|
10
|
+import com.yohoufo.order.service.cache.CacheKeyBuilder;
|
|
|
11
|
+import com.yohoufo.order.service.cache.ExpiredTime;
|
|
|
12
|
+import org.apache.commons.lang3.StringUtils;
|
8
|
import org.slf4j.Logger;
|
13
|
import org.slf4j.Logger;
|
9
|
import org.slf4j.LoggerFactory;
|
14
|
import org.slf4j.LoggerFactory;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -23,22 +28,33 @@ public class MetaConfigService { |
|
@@ -23,22 +28,33 @@ public class MetaConfigService { |
23
|
@Autowired
|
28
|
@Autowired
|
24
|
private MetaConfigMapper metaConfigMapper;
|
29
|
private MetaConfigMapper metaConfigMapper;
|
25
|
|
30
|
|
|
|
31
|
+ @Autowired
|
|
|
32
|
+ private CacheClient cacheClient;
|
26
|
/**
|
33
|
/**
|
27
|
* TODO use cache
|
34
|
* TODO use cache
|
28
|
* @return
|
35
|
* @return
|
29
|
*/
|
36
|
*/
|
30
|
public BuyerPenalty getBuyerPenalty(){
|
37
|
public BuyerPenalty getBuyerPenalty(){
|
|
|
38
|
+ RedisKeyBuilder rkb = CacheKeyBuilder.buyerCancelPenaltyConfigKey();
|
|
|
39
|
+ String value = cacheClient.get(rkb, String.class);
|
31
|
String key = MetaConfigKey.BUYER_PENALTY;
|
40
|
String key = MetaConfigKey.BUYER_PENALTY;
|
32
|
- BuyerPenalty bp = new BuyerPenalty();
|
41
|
+ if (StringUtils.isBlank(value)){
|
33
|
MetaConfig metaConfig = metaConfigMapper.selectByCode(key);
|
42
|
MetaConfig metaConfig = metaConfigMapper.selectByCode(key);
|
|
|
43
|
+ logger.info("getBuyerPenalty fetch from DB value {}", value);
|
34
|
if (Objects.nonNull(metaConfig)){
|
44
|
if (Objects.nonNull(metaConfig)){
|
35
|
- String value = metaConfig.getValue();
|
45
|
+ value = metaConfig.getValue();
|
|
|
46
|
+ cacheClient.setEx(rkb, value, ExpiredTime.BUYER_CANCEL_PANELTY_CONFIG);
|
|
|
47
|
+ }
|
|
|
48
|
+ }else {
|
|
|
49
|
+ logger.info("getBuyerPenalty hit in cache value {}", value);
|
|
|
50
|
+ }
|
|
|
51
|
+ BuyerPenalty bp ;
|
36
|
try{
|
52
|
try{
|
37
|
bp = JSONObject.parseObject(value, BuyerPenalty.class);
|
53
|
bp = JSONObject.parseObject(value, BuyerPenalty.class);
|
38
|
}catch (Exception ex){
|
54
|
}catch (Exception ex){
|
|
|
55
|
+ bp = new BuyerPenalty();
|
39
|
logger.warn("in getBuyerPenalty parse config value fail, key {} value {}", key, value);
|
56
|
logger.warn("in getBuyerPenalty parse config value fail, key {} value {}", key, value);
|
40
|
}
|
57
|
}
|
41
|
- }
|
|
|
42
|
return bp;
|
58
|
return bp;
|
43
|
}
|
59
|
}
|
44
|
|
60
|
|