Authored by mali

Merge branch 'test6.9.13' of http://git.yoho.cn/ufo/yohoufo-fore into test6.9.13

... ... @@ -207,7 +207,7 @@ public abstract class AbstractBuyerOrderStateChanger<T extends RequestedStatusCh
int uid = buyerOrder.getUid();
long orderCode = buyerOrder.getOrderCode();
//查询定金
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), orderCode, MetaKey.BID_KEY, BidOrderMetaBo.class);
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(buyerOrder.getUid(), orderCode, MetaKey.BID_KEY, BidOrderMetaBo.class);
if (bidOrderMetaBo == null) {
logger.warn("bidOrderMetaBo exist, orderCode is {}, uid is {}", orderCode, buyerOrder.getUid());
throw new ServiceException(ServiceError.ORDER_NULL);
... ...
... ... @@ -124,7 +124,7 @@ public class BuyerBidDepositPaymentService extends AbstractOrderPaymentService {
}
private BidOrderMetaBo checkAndGetBidOrderMetaBo(BuyerOrder buyerOrder) {
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
if (bidOrderMetaBo == null) {
logger.warn("bidOrderMetaBo exist, orderCode is {}, uid is {}", buyerOrder.getOrderCode(), buyerOrder.getUid());
throw new ServiceException(ServiceError.ORDER_NULL);
... ...
... ... @@ -93,6 +93,9 @@ public class CacheKeyBuilder {
DISTRIBUTED_LOCK_DEPOSIT_GOODS(DISTRIBUTED_LOCK_PREFIX, "depositCode:{}"),
SELLER_SALE_GOODS_SUMMARY("ufo:order:summary:","uid:{}:tabType:{}"),
//买家buyer_order_meta数据缓存
BUYER_ORDER_META("ufo:order:buyer:meta:", "orderCode:{}:metaKey:{}")
;
private String fix;
... ... @@ -209,4 +212,8 @@ public class CacheKeyBuilder {
return PatternKeyTemplate.SELLER_SALE_GOODS_TABLIST_SUMMARY.getKeyPattern();
}
public static RedisKeyBuilder getBuyerOrderMetaKey(long orderCode, String metaKey) {
return KeyTemp.BUYER_ORDER_META.builderKey(new Object[]{orderCode, metaKey});
}
}
... ...
... ... @@ -26,4 +26,6 @@ public interface ExpiredTime {
int DISTRIBUTED_LOCK_DEPOSIT_GOODS = 5;
int SELLER_SALE_GOODS_TAB_LIST_SUMMARY = 300;
int BUYER_ORDER_META = 7200;
}
... ...
... ... @@ -100,7 +100,7 @@ public class BuyerOrderPayDepositSuccessChanger extends AbstractBuyerOrderStateC
private void fireAutoCancelAsyncEvent(BuyerOrder buyerOrder) {
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
//未变现取消事件
int day = bidOrderMetaBo.getDay();
BuyerOrderDelayCancelEvent buyerCancelEvent = BuyerOrderDelayCancelEvent.builder().uid(buyerOrder.getUid())
... ...
... ... @@ -342,7 +342,7 @@ public class BuyerOrderChangeBusinessPostProcessor {
int uid = buyerOrder.getUid();
long orderCode = buyerOrder.getOrderCode();
//查询定金
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(uid, orderCode, MetaKey.BID_KEY, BidOrderMetaBo.class);
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(uid, orderCode, MetaKey.BID_KEY, BidOrderMetaBo.class);
if (bidOrderMetaBo == null) {
logger.warn("bidOrderMetaBo not exist, orderCode is {}, uid is {}", orderCode, uid);
throw new ServiceException(ServiceError.ORDER_NULL);
... ...
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");
... ...
... ... @@ -41,7 +41,7 @@ public class OrderStatusDetailItemFactory {
detailItem = new WaitingPayDepositItem(createTime);
break;
case BIDING:
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
detailItem = new BidingOrderItem(bidOrderMetaBo.getDay());
break;
case WAITING_PAY:
... ...