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