|
|
package com.yohoufo.order.service.support;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.yohoufo.common.cache.CacheClient;
|
|
|
import com.yohoufo.dal.order.BuyerOrderMetaMapper;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrderMeta;
|
|
|
import com.yohoufo.order.service.cache.CacheKeyBuilder;
|
|
|
import com.yohoufo.order.service.cache.ExpiredTime;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* Created by jiexiang.wu on 2019/5/23.
|
|
|
*/
|
...
|
...
|
@@ -19,6 +24,9 @@ public class BuyerOrderMetaMapperSupport { |
|
|
@Autowired
|
|
|
BuyerOrderMetaMapper buyerOrderMetaMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private CacheClient cacheClient;
|
|
|
|
|
|
public <T> T selectByMetaKey(int uid, long orderCode, String metaKey, Class<T> clazz) {
|
|
|
BuyerOrderMeta orderMeta = buyerOrderMetaMapper.selectByMetaKey(uid, orderCode, metaKey);
|
|
|
if (orderMeta == null) {
|
...
|
...
|
@@ -29,6 +37,31 @@ public class BuyerOrderMetaMapperSupport { |
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 先从缓存中获取,缓存中没有才从db中获取
|
|
|
* 备注:不会主动删除缓存,所以缓存的数据必须不会被修改,若使用的数据修改了,会导致数据不一致
|
|
|
*
|
|
|
* @param uid
|
|
|
* @param orderCode
|
|
|
* @param metaKey
|
|
|
* @param clazz
|
|
|
* @param <T>
|
|
|
* @return
|
|
|
*/
|
|
|
public <T> T selectCachedMetaValueByMetaKey(int uid, long orderCode, String metaKey, Class<T> clazz) {
|
|
|
String cachedKey = CacheKeyBuilder.getBuyerOrderMetaKey(orderCode, metaKey).toString();
|
|
|
T t = cacheClient.get(cachedKey, clazz);
|
|
|
if (Objects.nonNull(t)) {
|
|
|
return t;
|
|
|
}
|
|
|
t = selectByMetaKey(uid, orderCode, metaKey, clazz);
|
|
|
if (Objects.nonNull(t)) {
|
|
|
cacheClient.set(cachedKey, ExpiredTime.BUYER_ORDER_META, t);
|
|
|
}
|
|
|
return t;
|
|
|
}
|
|
|
|
|
|
|
|
|
public static <T> T convert(BuyerOrderMeta orderMeta, Class<T> clazz) {
|
|
|
if (orderMeta == null) {
|
|
|
logger.warn("orderMeta is null");
|
...
|
...
|
|