Authored by chenchao

add cache

... ... @@ -54,9 +54,9 @@ public class CacheKeyBuilder {
SELLER_ORDER_DETAIL("ufo:order:orderDetail:", "uid:{}:tabType:{}:batchNo:{}:price{}:status{}"),
BUYER_ORDER_NUMS("ufo:order:buyer:orderNums", "uid:{}");
BUYER_ORDER_NUMS("ufo:order:buyer:orderNums:", "uid:{}"),
BUYER_CANCEL_PENALTY("ufo:order:buyer:cancel:penalty:config", "");
private String fix;
private String placeHolder;
... ... @@ -78,6 +78,10 @@ public class CacheKeyBuilder {
String appendPart = fillPlaceHolder(args);
return new RedisKeyBuilder().appendFixed(fix).appendVar(appendPart);
}
public RedisKeyBuilder builderKeyOnlyFixed(){
return new RedisKeyBuilder().appendFixed(fix);
}
}
... ... @@ -123,4 +127,7 @@ public class CacheKeyBuilder {
return cke.getKey();
}
public static RedisKeyBuilder buyerCancelPenaltyConfigKey(){
return KeyTemp.BUYER_CANCEL_PENALTY.builderKeyOnlyFixed();
}
}
... ...
... ... @@ -14,4 +14,6 @@ public interface ExpiredTime {
int ORDER_SUMMARY = 300;
int BUYER_ORDER_NUMS = 300;
int BUYER_CANCEL_PANELTY_CONFIG = 300;
}
... ...
package com.yohoufo.order.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.order.common.MetaConfigKey;
import com.yohoufo.common.cache.CacheClient;
import com.yohoufo.dal.order.MetaConfigMapper;
import com.yohoufo.dal.order.model.MetaConfig;
import com.yohoufo.order.model.dto.BuyerPenalty;
import com.yohoufo.order.service.cache.CacheKeyBuilder;
import com.yohoufo.order.service.cache.ExpiredTime;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -23,21 +28,32 @@ public class MetaConfigService {
@Autowired
private MetaConfigMapper metaConfigMapper;
@Autowired
private CacheClient cacheClient;
/**
* TODO use cache
* @return
*/
public BuyerPenalty getBuyerPenalty(){
RedisKeyBuilder rkb = CacheKeyBuilder.buyerCancelPenaltyConfigKey();
String value = cacheClient.get(rkb, String.class);
String key = MetaConfigKey.BUYER_PENALTY;
BuyerPenalty bp = new BuyerPenalty();
MetaConfig metaConfig = metaConfigMapper.selectByCode(key);
if (Objects.nonNull(metaConfig)){
String value = metaConfig.getValue();
try{
bp = JSONObject.parseObject(value, BuyerPenalty.class);
}catch (Exception ex){
logger.warn("in getBuyerPenalty parse config value fail, key {} value {}", key, value);
if (StringUtils.isBlank(value)){
MetaConfig metaConfig = metaConfigMapper.selectByCode(key);
logger.info("getBuyerPenalty fetch from DB value {}", value);
if (Objects.nonNull(metaConfig)){
value = metaConfig.getValue();
cacheClient.setEx(rkb, value, ExpiredTime.BUYER_CANCEL_PANELTY_CONFIG);
}
}else {
logger.info("getBuyerPenalty hit in cache value {}", value);
}
BuyerPenalty bp ;
try{
bp = JSONObject.parseObject(value, BuyerPenalty.class);
}catch (Exception ex){
bp = new BuyerPenalty();
logger.warn("in getBuyerPenalty parse config value fail, key {} value {}", key, value);
}
return bp;
}
... ...
package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.common.EntrySellerType;
import com.yohoufo.dal.order.SuperEntrySellerMapper;
import com.yohoufo.dal.order.model.SuperEntrySeller;
import com.yohoufo.order.common.SurperEntrySellerStatus;
... ... @@ -98,5 +99,9 @@ public class SellerService {
}
public EntrySellerType getEntrySellerType(int uid){
logger.info("getEntrySellerType uid {}", uid);
return EntrySellerType.getEntrySellerType(null);
}
}
... ...