Authored by chenchao

add cache

... ... @@ -7,6 +7,7 @@ import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.order.service.impl.BuyerOrderViewService;
import com.yohoufo.order.service.impl.OrderViewService;
import com.yohoufo.order.service.impl.SellerOrderViewService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
... ... @@ -24,33 +25,16 @@ public class OrderViewController {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private BuyerOrderViewService buyerOrderViewService;
private OrderViewService orderViewService;
@Autowired
private SellerOrderViewService sellerOrderViewService;
@Autowired
private OrderCodeGenerator orderCodeGenerator;
@RequestMapping(params = "method=ufo.order.goodsDetail")
public ApiResponse orderGoodsDetail(@RequestParam("orderCode") long orderCode,
@RequestParam("uid") int uid){
logger.info("in ufo.order.goodsDetail uid {} orderCode {}", uid, orderCode);
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
if (Objects.isNull(codeMeta)){
logger.warn("orderGoodsDetail orderCode illegal, orderCode {}", orderCode);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
GoodsInfo goodsInfo = null;
switch (orderCodeType){
case BUYER_TYPE:
goodsInfo = buyerOrderViewService.getGoodsInfoOfOrder(uid, orderCode);
break;
case SELLER_TYPE:
goodsInfo = sellerOrderViewService.getGoodsInfoOfOrder(uid, orderCode);
break;
}
GoodsInfo goodsInfo = orderViewService.getGoodsInfoOfOrder(uid, orderCode);
return new ApiResponse.ApiResponseBuilder().data(goodsInfo).code(200).message("成功").build();
}
... ... @@ -60,22 +44,7 @@ public class OrderViewController {
public ApiResponse orderPayDetail(@RequestParam("orderCode") long orderCode,
@RequestParam("uid") int uid){
logger.info("in ufo.order.payDetail uid {} orderCode {}", uid, orderCode);
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
if (Objects.isNull(codeMeta)){
logger.warn("payDetail orderCode illegal, orderCode {}", orderCode);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
OrderDetailInfo orderDetailInfo = null;
switch (orderCodeType){
case BUYER_TYPE:
orderDetailInfo = buyerOrderViewService.getPayDetail(uid, orderCode);
break;
case SELLER_TYPE:
orderDetailInfo = sellerOrderViewService.getPayDatail(uid, orderCode);
break;
}
OrderDetailInfo orderDetailInfo = orderViewService.getPayDetail(uid, orderCode);
return new ApiResponse.ApiResponseBuilder().data(orderDetailInfo).code(200).message("成功").build();
}
}
... ...
... ... @@ -95,7 +95,12 @@ public class CacheKeyBuilder {
SELLER_SALE_GOODS_SUMMARY("ufo:order:summary:","uid:{}:tabType:{}"),
//买家buyer_order_meta数据缓存
BUYER_ORDER_META("ufo:order:buyer:meta:", "orderCode:{}:metaKey:{}")
BUYER_ORDER_META("ufo:order:buyer:meta:", "orderCode:{}:metaKey:{}"),
ORDER_GOODS_DETAIL("ufo:order:orderGoodsDetail:", "uid:{}:tabType:{}:orderCode:{}"),
ORDER_PAY_DETAIL("ufo:order:orderPayDetail:", "uid:{}:tabType:{}:orderCode:{}"),
;
private String fix;
... ... @@ -216,4 +221,14 @@ public class CacheKeyBuilder {
public static RedisKeyBuilder getBuyerOrderMetaKey(long orderCode, String metaKey) {
return KeyTemp.BUYER_ORDER_META.builderKey(new Object[]{orderCode, metaKey});
}
public static RedisKeyBuilder orderPayDetailKey(int uid, String actor, long orderCode){
return KeyTemp.ORDER_PAY_DETAIL.builderKey(new Object[]{uid, actor, orderCode});
}
public static RedisKeyBuilder orderGoodsDetailKey(int uid, String actor, long orderCode){
return KeyTemp.ORDER_GOODS_DETAIL.builderKey(new Object[]{uid, actor, orderCode});
}
}
... ...
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.BuyerOrderNums;
import com.yohobuy.ufo.model.order.vo.OrderListVo;
... ... @@ -216,4 +217,35 @@ public class OrderCacheService {
}
public void cacheOrderGoodsDetailInfo(int uid, long orderCode,TabType actor, GoodsInfo orderDetailInfo){
RedisKeyBuilder kb = CacheKeyBuilder.orderGoodsDetailKey(uid, actor.getValue(), orderCode);
cacheClient.set(kb.getKey(), ExpiredTime.ORDER_DETAIL , orderDetailInfo);
logger.info("put OrderGoodsDetail cache ,uid {} orderCode {} actor {}", uid, orderCode, actor);
}
public GoodsInfo getOrderGoodsDetailInfo(int uid, long orderCode, TabType actor){
logger.info("try fetch OrderGoodsDetail from cache ,uid {} orderCode {} actor {}", uid, orderCode, actor);
RedisKeyBuilder kb = CacheKeyBuilder.orderGoodsDetailKey(uid, actor.getValue(), orderCode);
GoodsInfo orderDetailInfo = cacheClient.get(kb.getKey(), GoodsInfo.class);
logger.info("hit OrderDetail cache ,uid {} orderCode {} actor {} orderDetailInfo {}",
uid, orderCode, actor, orderDetailInfo);
return orderDetailInfo;
}
public void cacheOrderPayDetailInfo(int uid, long orderCode,TabType actor, OrderDetailInfo orderDetailInfo){
RedisKeyBuilder kb = CacheKeyBuilder.orderPayDetailKey(uid, actor.getValue(), orderCode);
cacheClient.set(kb.getKey(), ExpiredTime.ORDER_DETAIL , orderDetailInfo);
logger.info("put OrderPayDetail cache ,uid {} orderCode {} actor {}", uid, orderCode, actor);
}
public OrderDetailInfo getOrderPayDetailInfo(int uid, long orderCode, TabType actor){
logger.info("try fetch OrderPayDetail from cache ,uid {} orderCode {} actor {}", uid, orderCode, actor);
RedisKeyBuilder kb = CacheKeyBuilder.orderPayDetailKey(uid, actor.getValue(), orderCode);
OrderDetailInfo orderDetailInfo = cacheClient.get(kb.getKey(), OrderDetailInfo.class);
logger.info("hit OrderPayDetail cache ,uid {} orderCode {} actor {} orderDetailInfo {}",
uid, orderCode, actor, orderDetailInfo);
return orderDetailInfo;
}
}
... ...
package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.bo.CustomsClearanceResult;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.bo.TimeoutBo;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderStatus;
... ... @@ -16,6 +17,7 @@ import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.model.*;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.constants.MetaKey;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.model.bo.BidOrderMetaBo;
import com.yohoufo.order.model.bo.DetailItem;
import com.yohoufo.order.model.request.OrderRequest;
... ... @@ -317,4 +319,16 @@ public class BuyerOrderDetailService extends AbsOrderDetailService implements IO
orderDetailInfo.setStatusDetail(statusDetail);
return orderDetailInfo;
}
public GoodsInfo getGoodsInfoOfOrder(int uid, long orderCode){
logger.info("getGoodsInfoOfOrder uid {} orderCode {}", uid, orderCode);
final TabType tabType = TabType.BUY;
GoodsInfo goodsInfo = null;
BuyerOrderAssistant.PreparedData preparedData = buyerOrderAssistant.prepare(orderCode);
SellerOrderGoods psog;
if ((psog= preparedData.getSellerOrderGoods()) != null){
goodsInfo = GoodsInfoConvertor.sellerOrderGoods2GoodsInfo(psog, tabType);
}
return goodsInfo;
}
}
... ...
... ... @@ -2,21 +2,17 @@ package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.OrderCancelComputeResult;
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
import com.yohobuy.ufo.model.order.resp.OrderListInfo;
import com.yohobuy.ufo.model.order.resp.PageResp;
import com.yohobuy.ufo.model.order.vo.OrderListVo;
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.model.dto.BuyerPenaltyCalResult;
import com.yohoufo.order.model.request.OrderListRequest;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
import com.yohoufo.order.service.IOrderDetailService;
import com.yohoufo.order.service.IOrderListService;
import com.yohoufo.order.service.cache.OrderCacheService;
... ... @@ -52,10 +48,8 @@ public class BuyerOrderViewService implements IOrderListService, IOrderDetailSer
private BuyerCancelCompensateComputeHandler buyerCancelCompensateComputeHandler;
@Autowired
BuyerOrderGoodsMapper buyerOrderGoodsMapper;
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
@Autowired
private BuyerOrderAssistant buyerOrderAssistant;
@Override
... ... @@ -156,21 +150,4 @@ public class BuyerOrderViewService implements IOrderListService, IOrderDetailSer
return occr;
}
public GoodsInfo getGoodsInfoOfOrder(int uid, long orderCode){
logger.info("getGoodsInfoOfOrder uid {} orderCode {}", uid, orderCode);
final TabType tabType = TabType.BUY;
GoodsInfo goodsInfo = null;
BuyerOrderAssistant.PreparedData preparedData = buyerOrderAssistant.prepare(orderCode);
SellerOrderGoods psog;
if ((psog= preparedData.getSellerOrderGoods()) != null){
goodsInfo = GoodsInfoConvertor.sellerOrderGoods2GoodsInfo(psog, tabType);
}
return goodsInfo;
}
public OrderDetailInfo getPayDetail(int uid, long orderCode){
return buyerOrderDetailService.getPayDetail(uid, orderCode);
}
}
... ...
package com.yohoufo.order.service.impl;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.common.OrderCodeType;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
import com.yohoufo.order.service.cache.OrderCacheService;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
import java.util.function.Supplier;
@Service
public class OrderViewService {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private OrderCodeGenerator orderCodeGenerator;
@Autowired
private OrderCacheService orderCacheService;
@Autowired
private SellerOrderDetailService sellerOrderDetailService;
@Autowired
private BuyerOrderDetailService buyerOrderDetailService;
public GoodsInfo getGoodsInfoOfOrder(int uid, long orderCode){
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
if (Objects.isNull(codeMeta)){
logger.warn("orderGoodsDetail orderCode illegal, orderCode {}", orderCode);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
GoodsInfo goodsInfo = null;
Supplier<GoodsInfo> goodsInfoSupplier;
TabType tabType;
switch (orderCodeType){
case BUYER_TYPE:
tabType = TabType.BUY;
goodsInfoSupplier = () -> buyerOrderDetailService.getGoodsInfoOfOrder(uid, orderCode);
break;
case SELLER_TYPE:
tabType = TabType.SELL;
goodsInfoSupplier = () -> sellerOrderDetailService.getGoodsInfoOfOrder(uid, orderCode);
break;
default:
return null;
}
goodsInfo = orderCacheService.getOrderGoodsDetailInfo(uid, orderCode, tabType);
if (Objects.nonNull(goodsInfo)){
return goodsInfo;
}
goodsInfo = goodsInfoSupplier.get();
if (Objects.nonNull(goodsInfo)){
orderCacheService.cacheOrderGoodsDetailInfo(uid, orderCode, tabType, goodsInfo);
}
return goodsInfo;
}
public OrderDetailInfo getPayDetail(int uid, long orderCode){
CodeMeta codeMeta = orderCodeGenerator.expId(orderCode);
if (Objects.isNull(codeMeta)){
logger.warn("payDetail orderCode illegal, orderCode {}", orderCode);
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
}
OrderCodeType orderCodeType = OrderCodeType.getOrderCodeType(codeMeta.getType());
Supplier<OrderDetailInfo> orderDetailInfoSupplier = null;
TabType tabType;
switch (orderCodeType){
case BUYER_TYPE:
tabType = TabType.BUY;
orderDetailInfoSupplier = () -> buyerOrderDetailService.getPayDetail(uid, orderCode);
break;
case SELLER_TYPE:
tabType = TabType.SELL;
orderDetailInfoSupplier = () -> sellerOrderDetailService.getPayDetail(uid, orderCode);
break;
default:
return null;
}
OrderDetailInfo orderDetailInfo = orderCacheService.getOrderPayDetailInfo(uid, orderCode, tabType);
if (orderDetailInfo == null){
orderDetailInfo = orderDetailInfoSupplier.get();
if (Objects.nonNull(orderDetailInfo)){
orderCacheService.cacheOrderPayDetailInfo(uid, orderCode, tabType, orderDetailInfo);
}
}
return orderDetailInfo;
}
}
... ...
... ... @@ -648,4 +648,23 @@ public class SellerOrderDetailService extends AbsOrderDetailService implements I
orderDetailInfo.setStatusDetail(statusDetail);
return orderDetailInfo;
}
public GoodsInfo getGoodsInfoOfOrder(int uid, long orderCode){
logger.info("getGoodsInfoOfOrder uid {} orderCode {}", uid, orderCode);
final TabType tabType = TabType.SELL;
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
if (Objects.isNull(sellerOrder)){
logger.warn("getPayDetail can not find seller orderCode, orderCode {}", orderCode);
return null;
}
Integer skup = sellerOrder.getSkup();
SellerOrderGoods psog;
psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
GoodsInfo goodsInfo = null;
if (psog != null){
goodsInfo = GoodsInfoConvertor.sellerOrderGoods2GoodsInfo(psog, tabType);
}
return goodsInfo;
}
}
... ...
package com.yohoufo.order.service.impl;
import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
import com.yohobuy.ufo.model.order.bo.PrdPrice;
import com.yohobuy.ufo.model.order.common.ButtonShow;
import com.yohobuy.ufo.model.order.common.SellerOrderListType;
... ... @@ -9,16 +8,11 @@ import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohobuy.ufo.model.order.common.TabType;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.resp.OrderCntResp;
import com.yohobuy.ufo.model.order.resp.OrderDetailInfo;
import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.common.utils.BigDecimalHelper;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.common.ActionStatusHold;
import com.yohoufo.order.convert.GoodsInfoConvertor;
import com.yohoufo.order.convert.PrdPriceConvertor;
import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.response.OrderSummaryResp;
... ... @@ -35,7 +29,6 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
... ... @@ -54,14 +47,10 @@ public class SellerOrderViewService {
@Autowired
private OrderCacheService orderCacheService;
@Autowired
private SellerOrderMapper sellerOrderMapper;
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private SellerOrderDetailService sellerOrderDetailService;
private static final List<Integer> SHOW_OVER_FLOW_PRICE_STATUS = Arrays.asList(SkupStatus.CAN_SELL.getCode());
... ... @@ -227,26 +216,4 @@ public class SellerOrderViewService {
}
public GoodsInfo getGoodsInfoOfOrder(int uid, long orderCode){
logger.info("getGoodsInfoOfOrder uid {} orderCode {}", uid, orderCode);
final TabType tabType = TabType.SELL;
SellerOrder sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
if (Objects.isNull(sellerOrder)){
logger.warn("getPayDetail can not find seller orderCode, orderCode {}", orderCode);
return null;
}
Integer skup = sellerOrder.getSkup();
SellerOrderGoods psog;
psog = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
GoodsInfo goodsInfo = null;
if (psog != null){
goodsInfo = GoodsInfoConvertor.sellerOrderGoods2GoodsInfo(psog, tabType);
}
return goodsInfo;
}
public OrderDetailInfo getPayDatail(int uid, long orderCode){
return sellerOrderDetailService.getPayDetail(uid, orderCode);
}
}
... ...