Authored by wujiexiang

Merge branch 'dev_bid' into test6.9.13

@@ -207,7 +207,7 @@ public abstract class AbstractBuyerOrderStateChanger<T extends RequestedStatusCh @@ -207,7 +207,7 @@ public abstract class AbstractBuyerOrderStateChanger<T extends RequestedStatusCh
207 int uid = buyerOrder.getUid(); 207 int uid = buyerOrder.getUid();
208 long orderCode = buyerOrder.getOrderCode(); 208 long orderCode = buyerOrder.getOrderCode();
209 //查询定金 209 //查询定金
210 - BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), orderCode, MetaKey.BID_KEY, BidOrderMetaBo.class); 210 + BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(buyerOrder.getUid(), orderCode, MetaKey.BID_KEY, BidOrderMetaBo.class);
211 if (bidOrderMetaBo == null) { 211 if (bidOrderMetaBo == null) {
212 logger.warn("bidOrderMetaBo exist, orderCode is {}, uid is {}", orderCode, buyerOrder.getUid()); 212 logger.warn("bidOrderMetaBo exist, orderCode is {}, uid is {}", orderCode, buyerOrder.getUid());
213 throw new ServiceException(ServiceError.ORDER_NULL); 213 throw new ServiceException(ServiceError.ORDER_NULL);
@@ -124,7 +124,7 @@ public class BuyerBidDepositPaymentService extends AbstractOrderPaymentService { @@ -124,7 +124,7 @@ public class BuyerBidDepositPaymentService extends AbstractOrderPaymentService {
124 } 124 }
125 125
126 private BidOrderMetaBo checkAndGetBidOrderMetaBo(BuyerOrder buyerOrder) { 126 private BidOrderMetaBo checkAndGetBidOrderMetaBo(BuyerOrder buyerOrder) {
127 - BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class); 127 + BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
128 if (bidOrderMetaBo == null) { 128 if (bidOrderMetaBo == null) {
129 logger.warn("bidOrderMetaBo exist, orderCode is {}, uid is {}", buyerOrder.getOrderCode(), buyerOrder.getUid()); 129 logger.warn("bidOrderMetaBo exist, orderCode is {}, uid is {}", buyerOrder.getOrderCode(), buyerOrder.getUid());
130 throw new ServiceException(ServiceError.ORDER_NULL); 130 throw new ServiceException(ServiceError.ORDER_NULL);
@@ -93,6 +93,9 @@ public class CacheKeyBuilder { @@ -93,6 +93,9 @@ public class CacheKeyBuilder {
93 DISTRIBUTED_LOCK_DEPOSIT_GOODS(DISTRIBUTED_LOCK_PREFIX, "depositCode:{}"), 93 DISTRIBUTED_LOCK_DEPOSIT_GOODS(DISTRIBUTED_LOCK_PREFIX, "depositCode:{}"),
94 94
95 SELLER_SALE_GOODS_SUMMARY("ufo:order:summary:","uid:{}:tabType:{}"), 95 SELLER_SALE_GOODS_SUMMARY("ufo:order:summary:","uid:{}:tabType:{}"),
  96 +
  97 + //买家buyer_order_meta数据缓存
  98 + BUYER_ORDER_META("ufo:order:buyer:meta:", "orderCode:{}:metaKey:{}")
96 ; 99 ;
97 100
98 private String fix; 101 private String fix;
@@ -209,4 +212,8 @@ public class CacheKeyBuilder { @@ -209,4 +212,8 @@ public class CacheKeyBuilder {
209 212
210 return PatternKeyTemplate.SELLER_SALE_GOODS_TABLIST_SUMMARY.getKeyPattern(); 213 return PatternKeyTemplate.SELLER_SALE_GOODS_TABLIST_SUMMARY.getKeyPattern();
211 } 214 }
  215 +
  216 + public static RedisKeyBuilder getBuyerOrderMetaKey(long orderCode, String metaKey) {
  217 + return KeyTemp.BUYER_ORDER_META.builderKey(new Object[]{orderCode, metaKey});
  218 + }
212 } 219 }
@@ -26,4 +26,6 @@ public interface ExpiredTime { @@ -26,4 +26,6 @@ public interface ExpiredTime {
26 int DISTRIBUTED_LOCK_DEPOSIT_GOODS = 5; 26 int DISTRIBUTED_LOCK_DEPOSIT_GOODS = 5;
27 27
28 int SELLER_SALE_GOODS_TAB_LIST_SUMMARY = 300; 28 int SELLER_SALE_GOODS_TAB_LIST_SUMMARY = 300;
  29 +
  30 + int BUYER_ORDER_META = 7200;
29 } 31 }
@@ -100,7 +100,7 @@ public class BuyerOrderPayDepositSuccessChanger extends AbstractBuyerOrderStateC @@ -100,7 +100,7 @@ public class BuyerOrderPayDepositSuccessChanger extends AbstractBuyerOrderStateC
100 100
101 101
102 private void fireAutoCancelAsyncEvent(BuyerOrder buyerOrder) { 102 private void fireAutoCancelAsyncEvent(BuyerOrder buyerOrder) {
103 - BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class); 103 + BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
104 //未变现取消事件 104 //未变现取消事件
105 int day = bidOrderMetaBo.getDay(); 105 int day = bidOrderMetaBo.getDay();
106 BuyerOrderDelayCancelEvent buyerCancelEvent = BuyerOrderDelayCancelEvent.builder().uid(buyerOrder.getUid()) 106 BuyerOrderDelayCancelEvent buyerCancelEvent = BuyerOrderDelayCancelEvent.builder().uid(buyerOrder.getUid())
@@ -342,7 +342,7 @@ public class BuyerOrderChangeBusinessPostProcessor { @@ -342,7 +342,7 @@ public class BuyerOrderChangeBusinessPostProcessor {
342 int uid = buyerOrder.getUid(); 342 int uid = buyerOrder.getUid();
343 long orderCode = buyerOrder.getOrderCode(); 343 long orderCode = buyerOrder.getOrderCode();
344 //查询定金 344 //查询定金
345 - BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(uid, orderCode, MetaKey.BID_KEY, BidOrderMetaBo.class); 345 + BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(uid, orderCode, MetaKey.BID_KEY, BidOrderMetaBo.class);
346 if (bidOrderMetaBo == null) { 346 if (bidOrderMetaBo == null) {
347 logger.warn("bidOrderMetaBo not exist, orderCode is {}, uid is {}", orderCode, uid); 347 logger.warn("bidOrderMetaBo not exist, orderCode is {}, uid is {}", orderCode, uid);
348 throw new ServiceException(ServiceError.ORDER_NULL); 348 throw new ServiceException(ServiceError.ORDER_NULL);
1 package com.yohoufo.order.service.support; 1 package com.yohoufo.order.service.support;
2 2
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
  4 +import com.yohoufo.common.cache.CacheClient;
4 import com.yohoufo.dal.order.BuyerOrderMetaMapper; 5 import com.yohoufo.dal.order.BuyerOrderMetaMapper;
5 import com.yohoufo.dal.order.model.BuyerOrderMeta; 6 import com.yohoufo.dal.order.model.BuyerOrderMeta;
  7 +import com.yohoufo.order.service.cache.CacheKeyBuilder;
  8 +import com.yohoufo.order.service.cache.ExpiredTime;
6 import com.yohoufo.order.utils.LoggerUtils; 9 import com.yohoufo.order.utils.LoggerUtils;
7 import org.slf4j.Logger; 10 import org.slf4j.Logger;
8 import org.springframework.beans.factory.annotation.Autowired; 11 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Component; 12 import org.springframework.stereotype.Component;
10 13
  14 +import java.util.Objects;
  15 +
11 /** 16 /**
12 * Created by jiexiang.wu on 2019/5/23. 17 * Created by jiexiang.wu on 2019/5/23.
13 */ 18 */
@@ -19,6 +24,9 @@ public class BuyerOrderMetaMapperSupport { @@ -19,6 +24,9 @@ public class BuyerOrderMetaMapperSupport {
19 @Autowired 24 @Autowired
20 BuyerOrderMetaMapper buyerOrderMetaMapper; 25 BuyerOrderMetaMapper buyerOrderMetaMapper;
21 26
  27 + @Autowired
  28 + private CacheClient cacheClient;
  29 +
22 public <T> T selectByMetaKey(int uid, long orderCode, String metaKey, Class<T> clazz) { 30 public <T> T selectByMetaKey(int uid, long orderCode, String metaKey, Class<T> clazz) {
23 BuyerOrderMeta orderMeta = buyerOrderMetaMapper.selectByMetaKey(uid, orderCode, metaKey); 31 BuyerOrderMeta orderMeta = buyerOrderMetaMapper.selectByMetaKey(uid, orderCode, metaKey);
24 if (orderMeta == null) { 32 if (orderMeta == null) {
@@ -29,6 +37,31 @@ public class BuyerOrderMetaMapperSupport { @@ -29,6 +37,31 @@ public class BuyerOrderMetaMapperSupport {
29 } 37 }
30 38
31 39
  40 + /**
  41 + * 先从缓存中获取,缓存中没有才从db中获取
  42 + * 备注:不会主动删除缓存,所以缓存的数据必须不会被修改,若使用的数据修改了,会导致数据不一致
  43 + *
  44 + * @param uid
  45 + * @param orderCode
  46 + * @param metaKey
  47 + * @param clazz
  48 + * @param <T>
  49 + * @return
  50 + */
  51 + public <T> T selectCachedMetaValueByMetaKey(int uid, long orderCode, String metaKey, Class<T> clazz) {
  52 + String cachedKey = CacheKeyBuilder.getBuyerOrderMetaKey(orderCode, metaKey).toString();
  53 + T t = cacheClient.get(cachedKey, clazz);
  54 + if (Objects.nonNull(t)) {
  55 + return t;
  56 + }
  57 + t = selectByMetaKey(uid, orderCode, metaKey, clazz);
  58 + if (Objects.nonNull(t)) {
  59 + cacheClient.set(cachedKey, ExpiredTime.BUYER_ORDER_META, t);
  60 + }
  61 + return t;
  62 + }
  63 +
  64 +
32 public static <T> T convert(BuyerOrderMeta orderMeta, Class<T> clazz) { 65 public static <T> T convert(BuyerOrderMeta orderMeta, Class<T> clazz) {
33 if (orderMeta == null) { 66 if (orderMeta == null) {
34 logger.warn("orderMeta is null"); 67 logger.warn("orderMeta is null");
@@ -41,7 +41,7 @@ public class OrderStatusDetailItemFactory { @@ -41,7 +41,7 @@ public class OrderStatusDetailItemFactory {
41 detailItem = new WaitingPayDepositItem(createTime); 41 detailItem = new WaitingPayDepositItem(createTime);
42 break; 42 break;
43 case BIDING: 43 case BIDING:
44 - BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class); 44 + BidOrderMetaBo bidOrderMetaBo = buyerOrderMetaMapperSupport.selectCachedMetaValueByMetaKey(buyerOrder.getUid(), buyerOrder.getOrderCode(), MetaKey.BID_KEY, BidOrderMetaBo.class);
45 detailItem = new BidingOrderItem(bidOrderMetaBo.getDay()); 45 detailItem = new BidingOrderItem(bidOrderMetaBo.getDay());
46 break; 46 break;
47 case WAITING_PAY: 47 case WAITING_PAY: