Authored by chenchao

add cache

@@ -54,9 +54,9 @@ public class CacheKeyBuilder { @@ -54,9 +54,9 @@ public class CacheKeyBuilder {
54 54
55 SELLER_ORDER_DETAIL("ufo:order:orderDetail:", "uid:{}:tabType:{}:batchNo:{}:price{}:status{}"), 55 SELLER_ORDER_DETAIL("ufo:order:orderDetail:", "uid:{}:tabType:{}:batchNo:{}:price{}:status{}"),
56 56
57 - BUYER_ORDER_NUMS("ufo:order:buyer:orderNums", "uid:{}");  
58 - 57 + BUYER_ORDER_NUMS("ufo:order:buyer:orderNums:", "uid:{}"),
59 58
  59 + BUYER_CANCEL_PENALTY("ufo:order:buyer:cancel:penalty:config", "");
60 private String fix; 60 private String fix;
61 61
62 private String placeHolder; 62 private String placeHolder;
@@ -78,6 +78,10 @@ public class CacheKeyBuilder { @@ -78,6 +78,10 @@ public class CacheKeyBuilder {
78 String appendPart = fillPlaceHolder(args); 78 String appendPart = fillPlaceHolder(args);
79 return new RedisKeyBuilder().appendFixed(fix).appendVar(appendPart); 79 return new RedisKeyBuilder().appendFixed(fix).appendVar(appendPart);
80 } 80 }
  81 +
  82 + public RedisKeyBuilder builderKeyOnlyFixed(){
  83 + return new RedisKeyBuilder().appendFixed(fix);
  84 + }
81 } 85 }
82 86
83 87
@@ -123,4 +127,7 @@ public class CacheKeyBuilder { @@ -123,4 +127,7 @@ public class CacheKeyBuilder {
123 return cke.getKey(); 127 return cke.getKey();
124 } 128 }
125 129
  130 + public static RedisKeyBuilder buyerCancelPenaltyConfigKey(){
  131 + return KeyTemp.BUYER_CANCEL_PENALTY.builderKeyOnlyFixed();
  132 + }
126 } 133 }
@@ -14,4 +14,6 @@ public interface ExpiredTime { @@ -14,4 +14,6 @@ public interface ExpiredTime {
14 int ORDER_SUMMARY = 300; 14 int ORDER_SUMMARY = 300;
15 15
16 int BUYER_ORDER_NUMS = 300; 16 int BUYER_ORDER_NUMS = 300;
  17 +
  18 + int BUYER_CANCEL_PANELTY_CONFIG = 300;
17 } 19 }
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
1 package com.yohoufo.order.service.impl; 1 package com.yohoufo.order.service.impl;
2 2
  3 +import com.yohobuy.ufo.model.order.common.EntrySellerType;
3 import com.yohoufo.dal.order.SuperEntrySellerMapper; 4 import com.yohoufo.dal.order.SuperEntrySellerMapper;
4 import com.yohoufo.dal.order.model.SuperEntrySeller; 5 import com.yohoufo.dal.order.model.SuperEntrySeller;
5 import com.yohoufo.order.common.SurperEntrySellerStatus; 6 import com.yohoufo.order.common.SurperEntrySellerStatus;
@@ -98,5 +99,9 @@ public class SellerService { @@ -98,5 +99,9 @@ public class SellerService {
98 } 99 }
99 100
100 101
  102 + public EntrySellerType getEntrySellerType(int uid){
  103 + logger.info("getEntrySellerType uid {}", uid);
  104 + return EntrySellerType.getEntrySellerType(null);
  105 + }
101 106
102 } 107 }