|
|
package com.yohoufo.order.service.impl;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.BuyerOrderMapper;
|
|
|
import com.yohoufo.dal.order.BuyerOrderMetaMapper;
|
|
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrder;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrderMeta;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.order.common.OrderListType;
|
|
|
import com.yohoufo.order.common.OrderStatus;
|
|
|
import com.yohoufo.order.request.OrderListRequest;
|
|
|
import com.yohoufo.order.response.OrderInfo;
|
|
|
import com.yohoufo.order.response.OrderInfoListRsp;
|
|
|
import com.yohoufo.order.service.IBuyerOrderService;
|
|
|
import com.yohoufo.order.common.OrderCodeType;
|
|
|
import com.yohoufo.order.common.SkupStatus;
|
|
|
import com.yohoufo.order.common.*;
|
|
|
import com.yohoufo.order.constants.MetaKey;
|
|
|
import com.yohoufo.order.constants.OrderConstant;
|
|
|
import com.yohoufo.order.model.dto.OrderBuilder;
|
|
|
import com.yohoufo.order.request.ShoppingRequest;
|
|
|
import com.yohoufo.order.response.OrderSubmitResponse;
|
|
|
import com.yohoufo.order.response.ShoppingPaymentResponse;
|
|
|
import com.yohoufo.order.request.OrderListRequest;
|
|
|
import com.yohoufo.order.request.OrderRequest;
|
|
|
import com.yohoufo.order.response.GoodsInfo;
|
|
|
import com.yohoufo.order.response.OrderDetailInfo;
|
|
|
import com.yohoufo.order.response.OrderListInfo;
|
|
|
import com.yohoufo.order.response.OrderListInfoRsp;
|
|
|
import com.yohoufo.order.service.IBuyerOrderService;
|
|
|
import com.yohoufo.order.service.IOrdeCreationService;
|
|
|
import com.yohoufo.order.service.support.ShoppingSupport;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -37,9 +30,6 @@ import java.util.List; |
|
|
import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Service
|
|
|
public class BuyerOrderServiceImpl implements IBuyerOrderService {
|
...
|
...
|
@@ -55,13 +45,145 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
@Autowired
|
|
|
SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
BuyerOrderMetaMapper buyerOrderMetaMapper;
|
|
|
|
|
|
|
|
|
public OrderDetailInfo getOrderDetail(OrderRequest orderRequest){
|
|
|
|
|
|
// 参数检查
|
|
|
if (orderRequest.getUid() < 0
|
|
|
|| orderRequest.getOrderCode() < 0){
|
|
|
logger.warn("getOrderDetail uid or orderCode empty");
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
TabType tabType = TabType.getTabType(orderRequest.getTabType());
|
|
|
if (tabType == null){
|
|
|
logger.warn("getOrderDetail tabType invalidate, uid is {}, orderCode is {}",
|
|
|
orderRequest.getUid(), orderRequest.getOrderCode());
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
if (TabType.BUY != tabType){
|
|
|
return new OrderDetailInfo();
|
|
|
}
|
|
|
|
|
|
// 查询订单状态
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderRequest.getOrderCode(), orderRequest.getUid());
|
|
|
if (buyerOrder == null){
|
|
|
logger.warn("getOrderDetail orderCode exist, uid is {}, orderCode is {}",
|
|
|
orderRequest.getUid(), orderRequest.getOrderCode() );
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
// 检查 订单状态
|
|
|
int status = buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus().intValue();
|
|
|
OrderStatus orderStatus = OrderStatus.getOrderStatus(status);
|
|
|
if (orderStatus == null){
|
|
|
logger.warn("getOrderDetail status invalidate, uid is {}, orderCode is {}, status is {}",
|
|
|
orderRequest.getUid(), orderRequest.getOrderCode(), buyerOrder.getStatus());
|
|
|
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
|
|
|
}
|
|
|
|
|
|
// 收货地址 and 用户信息 TODO
|
|
|
BuyerOrderMeta buyerOrderMeta = buyerOrderMetaMapper.selectByMetaKey(orderRequest.getUid(),
|
|
|
orderRequest.getOrderCode(), MetaKey.BUYER_DELIVERY_ADDRESS);
|
|
|
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(), orderRequest.getOrderCode());
|
|
|
if (buyerOrderGoods == null){
|
|
|
logger.warn("getOrderDetail skup not exist, uid is {}, orderCode is {}", orderRequest.getUid(), orderRequest.getOrderCode());
|
|
|
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(buyerOrderGoods.getSkup());
|
|
|
if (sellerOrderGoods == null){
|
|
|
logger.warn("getOrderDetail order goods not exist, uid is {}, orderCode is {}, skup is {}",
|
|
|
orderRequest.getUid(), orderRequest.getOrderCode(), buyerOrderGoods.getSkup());
|
|
|
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
OrderDetailInfo orderDetailInfo = buildOrderDetail(buyerOrder, orderStatus, buyerOrderGoods, sellerOrderGoods);
|
|
|
|
|
|
return orderDetailInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
private OrderDetailInfo buildOrderDetail(BuyerOrder buyerOrder, OrderStatus orderStatus, BuyerOrderGoods buyerOrderGoods, SellerOrderGoods sellerOrderGoods) {
|
|
|
OrderDetailInfo orderDetailInfo = new OrderDetailInfo();
|
|
|
orderDetailInfo.setUid(buyerOrder.getUid());
|
|
|
orderDetailInfo.setOrderCode(buyerOrder.getOrderCode());
|
|
|
orderDetailInfo.setButtons(orderStatus.getDetailButtons());
|
|
|
|
|
|
OrderDetailInfo.StatusDetail statusDetail = getStatusDetail(buyerOrder, orderStatus);
|
|
|
orderDetailInfo.setStatusDetail(statusDetail);
|
|
|
GoodsInfo goodsInfo = getGoodsInfo(sellerOrderGoods);
|
|
|
orderDetailInfo.setGoodsInfo(goodsInfo);
|
|
|
|
|
|
OrderDetailInfo.PriceInfo priceInfo = OrderDetailInfo.PriceInfo.builder()
|
|
|
.goodPrice(buyerOrderGoods.getGoodsPrice() == null ? "0" : buyerOrderGoods.getGoodsPrice().toPlainString() )
|
|
|
.feePrice(buyerOrder.getShipFee() == null ? "0" : buyerOrder.getShipFee().toPlainString())
|
|
|
.realPayPrice(buyerOrder.getAmount() == null ? "0" : buyerOrder.getAmount().toPlainString())
|
|
|
.build();
|
|
|
|
|
|
// 支付状态
|
|
|
if (buyerOrder.getPayment() != null){
|
|
|
Payment payment = Payment.getPayment(buyerOrder.getPayment());
|
|
|
if (payment != null){
|
|
|
orderDetailInfo.setPaymentStr(payment.getDesc());
|
|
|
orderDetailInfo.setPayment(buyerOrder.getPayment());
|
|
|
}
|
|
|
}
|
|
|
return orderDetailInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 商品信息
|
|
|
* @param sellerOrderGoods
|
|
|
* @return
|
|
|
*/
|
|
|
private GoodsInfo getGoodsInfo(SellerOrderGoods sellerOrderGoods) {
|
|
|
GoodsInfo goodsInfo = new GoodsInfo();
|
|
|
goodsInfo.setProductName(sellerOrderGoods.getProductName());
|
|
|
goodsInfo.setColorName(sellerOrderGoods.getColorName());
|
|
|
goodsInfo.setSizeName(sellerOrderGoods.getSizeName());
|
|
|
goodsInfo.setImageUrl(sellerOrderGoods.getImageUrl());
|
|
|
goodsInfo.setGoodPrice(sellerOrderGoods.getGoodsPrice().toPlainString());
|
|
|
return goodsInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取详情页 状态位明细
|
|
|
* @param buyerOrder
|
|
|
* @param orderStatus
|
|
|
* @return
|
|
|
*/
|
|
|
private OrderDetailInfo.StatusDetail getStatusDetail(BuyerOrder buyerOrder,OrderStatus orderStatus) {
|
|
|
OrderDetailInfo.StatusDetail statusDetail = OrderDetailInfo.StatusDetail.builder()
|
|
|
.status(orderStatus.getCode())
|
|
|
.statuStr(orderStatus.getStatusStr())
|
|
|
.build();
|
|
|
|
|
|
// TODO 需要查询 时间点 and 物流定位
|
|
|
if (OrderConstant.EXPRESS_SENDTIME_TO_QUERY.equals(orderStatus.getDetailDesc())){
|
|
|
|
|
|
}
|
|
|
|
|
|
// 待付款时,剩余时间
|
|
|
if (orderStatus.getCode() == OrderStatus.WAITING_PAY.getCode()){
|
|
|
statusDetail.setLeftTime(DateUtil.getCurrentTimeSecond() - buyerOrder.getCreateTime());
|
|
|
}
|
|
|
|
|
|
return statusDetail;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 订单列表
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
public OrderInfoListRsp getOrderList(OrderListRequest request){
|
|
|
public OrderListInfoRsp getOrderList(OrderListRequest request){
|
|
|
|
|
|
// check and init请求参数
|
|
|
List<Integer> statusQuery = initOrderListRequest(request);
|
...
|
...
|
@@ -75,26 +197,27 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
|
|
|
List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
|
|
|
|
|
|
// buyer_order_goods ===> skup+商品成交价
|
|
|
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCode(orderCodeList);
|
|
|
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity()));
|
|
|
// buyer_order_goods ===> skup+商品成交价 1:1
|
|
|
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCodeList(request.getUid(), orderCodeList);
|
|
|
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream()
|
|
|
.collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity(), (key1, key2) -> key2));
|
|
|
|
|
|
List<Integer> skups = buyerOrderGoodsList.stream().map(BuyerOrderGoods::getSkup).collect(Collectors.toList());
|
|
|
// seller_order_goods ===> 商品信息
|
|
|
List<SellerOrderGoods> sellerOrderGoodsList = sellerOrderGoodsMapper.selectBySkups(skups);
|
|
|
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap = sellerOrderGoodsList.stream().collect(Collectors.toMap(SellerOrderGoods::getId, Function.identity()));
|
|
|
|
|
|
List<OrderInfo> data = Lists.newArrayList();
|
|
|
List<OrderListInfo> data = Lists.newArrayList();
|
|
|
|
|
|
buyerOrderList.stream().forEach(buyerOrder -> {
|
|
|
OrderInfo orderInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder);
|
|
|
if (orderInfo == null) return;
|
|
|
OrderListInfo orderListInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder);
|
|
|
if (orderListInfo == null) return;
|
|
|
|
|
|
data.add(orderInfo);
|
|
|
data.add(orderListInfo);
|
|
|
|
|
|
});
|
|
|
|
|
|
OrderInfoListRsp orderInfoListRsp = OrderInfoListRsp.builder()
|
|
|
OrderListInfoRsp orderListInfoRsp = OrderListInfoRsp.builder()
|
|
|
.data(data)
|
|
|
.currPage(request.getPage())
|
|
|
.limit(limit)
|
...
|
...
|
@@ -102,7 +225,7 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
.currTotal(data.size())
|
|
|
.pageSize((total % limit == 0) ? (total / limit) : (total / limit + 1)).build();
|
|
|
|
|
|
return orderInfoListRsp;
|
|
|
return orderListInfoRsp;
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -113,46 +236,64 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
* @param buyerOrder
|
|
|
* @return
|
|
|
*/
|
|
|
private OrderInfo convertOrderInfo(Map<Long, BuyerOrderGoods> buyerOrderGoodsMap,
|
|
|
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap,
|
|
|
BuyerOrder buyerOrder) {
|
|
|
private OrderListInfo convertOrderInfo(Map<Long, BuyerOrderGoods> buyerOrderGoodsMap,
|
|
|
Map<Integer, SellerOrderGoods> sellerOrderGoodsMap,
|
|
|
BuyerOrder buyerOrder) {
|
|
|
|
|
|
/**
|
|
|
* 1.查询 buyer_order
|
|
|
* 2.查询 buyer_order_goods ==> skup
|
|
|
* 3.查询 seller_order_goods
|
|
|
*/
|
|
|
OrderInfo orderInfo = new OrderInfo();
|
|
|
orderInfo.setOrderCode(buyerOrder.getOrderCode());
|
|
|
orderInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
|
|
|
OrderListInfo orderListInfo = new OrderListInfo();
|
|
|
orderListInfo.setUid(buyerOrder.getUid());
|
|
|
orderListInfo.setOrderCode(buyerOrder.getOrderCode());
|
|
|
orderListInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
|
|
|
// 订单中状态显示
|
|
|
orderInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
|
|
|
OrderStatus orderStatus = OrderStatus.getOrderStatus(orderInfo.getStatus());
|
|
|
orderInfo.setStatuStr(orderStatus == null ? "" : orderStatus.getListStatusStr());
|
|
|
orderListInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
|
|
|
OrderStatus orderStatus = OrderStatus.getOrderStatus(orderListInfo.getStatus());
|
|
|
|
|
|
if (orderStatus == null){
|
|
|
logger.warn("getOrderList orderStatus not exist, uid is {}, orderCode is {}, status is {}",
|
|
|
buyerOrder.getUid(), orderListInfo.getOrderCode(), buyerOrder.getStatus());
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
orderListInfo.setStatuStr(orderStatus.getStatusStr());
|
|
|
|
|
|
// 按钮显示
|
|
|
orderInfo.setButtons(orderStatus == null ? Lists.newArrayList() : orderStatus.getButtonList());
|
|
|
orderListInfo.setButtons(orderStatus.getListButtons());
|
|
|
|
|
|
// 当订单状态是待付款, 显示leftTime
|
|
|
if (orderInfo.getStatus() == OrderStatus.WAITING_PAY.getCode()){
|
|
|
orderInfo.setLeftTime(DateUtil.getCurrentTimeSecond() - buyerOrder.getCreateTime());
|
|
|
if (orderListInfo.getStatus() == OrderStatus.WAITING_PAY.getCode()){
|
|
|
orderListInfo.setLeftTime(DateUtil.getCurrentTimeSecond() - buyerOrder.getCreateTime());
|
|
|
}
|
|
|
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
|
|
|
if (buyerOrderGoods == null){
|
|
|
logger.warn("getOrderList buyer goods not exist, uid is {}, orderCode is {}",
|
|
|
buyerOrder.getUid(), orderListInfo.getOrderCode());
|
|
|
return null;
|
|
|
}
|
|
|
orderInfo.setSkup(buyerOrderGoods.getSkup());
|
|
|
orderListInfo.setSkup(buyerOrderGoods.getSkup());
|
|
|
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
|
|
|
if (sellerOrderGoods == null){
|
|
|
logger.warn("getOrderList seller goods not exist, uid is {}, orderCode is {}",
|
|
|
buyerOrder.getUid(), orderListInfo.getOrderCode());
|
|
|
return null;
|
|
|
}
|
|
|
orderInfo.setProductName(sellerOrderGoods.getProductName());
|
|
|
orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());
|
|
|
orderInfo.setColorName(sellerOrderGoods.getColorName());
|
|
|
orderInfo.setSizeName(sellerOrderGoods.getSizeName());
|
|
|
return orderInfo;
|
|
|
|
|
|
GoodsInfo goodsInfo = new GoodsInfo();
|
|
|
goodsInfo.setColorName(sellerOrderGoods.getColorName());
|
|
|
goodsInfo.setProductName(sellerOrderGoods.getProductName());
|
|
|
goodsInfo.setImageUrl(sellerOrderGoods.getImageUrl());
|
|
|
goodsInfo.setSizeName(sellerOrderGoods.getSizeName());
|
|
|
goodsInfo.setGoodPrice(buyerOrderGoods.getGoodsPrice() == null ? "" :buyerOrderGoods.getGoodsPrice().toPlainString());
|
|
|
|
|
|
orderListInfo.setGoodsInfo(goodsInfo);
|
|
|
|
|
|
return orderListInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
|