|
|
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;
|
|
|
}
|
...
|
...
|
|