|
|
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.SellerOrderGoodsMapper;
|
...
|
...
|
@@ -10,8 +12,10 @@ import com.yohoufo.dal.order.model.BuyerOrder; |
|
|
import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
|
|
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;
|
...
|
...
|
@@ -52,29 +56,22 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
|
|
|
|
|
|
public void getOrderList(OrderListRequest request){
|
|
|
/**
|
|
|
* 订单列表
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
public OrderInfoListRsp getOrderList(OrderListRequest request){
|
|
|
|
|
|
if (request.getUid() < 0){
|
|
|
logger.warn("getOrderList uid is {}", request.getUid());
|
|
|
throw new ServiceException(ServiceError.ORDER_UID_IS_EMPTY);
|
|
|
}
|
|
|
// check and init请求参数
|
|
|
List<Integer> statusQuery = initOrderListRequest(request);
|
|
|
|
|
|
OrderListType orderListType = OrderListType.getOrderListType(request.getType());
|
|
|
if (orderListType == null){
|
|
|
logger.warn("getOrderList type invalidate, uid is {}, type is {}",request.getUid(), request.getType());
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
request.setPage(request.getPage() > 0 ? request.getPage() : 1);
|
|
|
request.setLimit( request.getLimit() > 0 ? request.getLimit() : 10 );
|
|
|
|
|
|
|
|
|
int total = buyerOrderMapper.selectCntByUidStatus(request.getUid(), orderListType.getStatus());
|
|
|
int total = buyerOrderMapper.selectCntByUidStatus(request.getUid(), statusQuery);
|
|
|
|
|
|
int limit = request.getLimit();
|
|
|
int offset = (request.getPage() - 1) * limit;
|
|
|
|
|
|
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListByUidStatus(request.getUid(), orderListType.getStatus(),offset, limit);
|
|
|
List<BuyerOrder> buyerOrderList = buyerOrderMapper.selectListByUidStatus(request.getUid(), statusQuery,offset, limit);
|
|
|
|
|
|
List<Long> orderCodeList = buyerOrderList.stream().map(BuyerOrder::getOrderCode).collect(Collectors.toList());
|
|
|
|
...
|
...
|
@@ -82,41 +79,101 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCode(orderCodeList);
|
|
|
Map<Long, BuyerOrderGoods> buyerOrderGoodsMap = buyerOrderGoodsList.stream().collect(Collectors.toMap(BuyerOrderGoods::getOrderCode, Function.identity()));
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
buyerOrderList.stream().forEach(buyerOrder -> {
|
|
|
OrderInfo orderInfo = new OrderInfo();
|
|
|
orderInfo.setOrderCode(buyerOrder.getOrderCode());
|
|
|
orderInfo.setRealPrice(buyerOrder.getAmount() == null ? "" : buyerOrder.getAmount().toPlainString());
|
|
|
OrderInfo orderInfo = convertOrderInfo(buyerOrderGoodsMap, sellerOrderGoodsMap, buyerOrder);
|
|
|
if (orderInfo == null) return;
|
|
|
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
|
|
|
if (buyerOrderGoods == null){
|
|
|
return;
|
|
|
}
|
|
|
orderInfo.setSkup(buyerOrderGoods.getSkup());
|
|
|
data.add(orderInfo);
|
|
|
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
|
|
|
orderInfo.setProductName(sellerOrderGoods.getProductName());
|
|
|
orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());
|
|
|
orderInfo.setColorName(sellerOrderGoods.getColorName());
|
|
|
orderInfo.setSizeName(sellerOrderGoods.getSizeName());
|
|
|
|
|
|
// 订单状态显示
|
|
|
});
|
|
|
|
|
|
// 按钮显示
|
|
|
OrderInfoListRsp orderInfoListRsp = OrderInfoListRsp.builder()
|
|
|
.data(data)
|
|
|
.currPage(request.getPage())
|
|
|
.limit(limit)
|
|
|
.total(total)
|
|
|
.currTotal(data.size())
|
|
|
.pageSize((total % limit == 0) ? (total / limit) : (total / limit + 1)).build();
|
|
|
|
|
|
return orderInfoListRsp;
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取返回结果
|
|
|
* @param buyerOrderGoodsMap
|
|
|
* @param sellerOrderGoodsMap
|
|
|
* @param buyerOrder
|
|
|
* @return
|
|
|
*/
|
|
|
private OrderInfo 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());
|
|
|
// 订单中状态显示
|
|
|
orderInfo.setStatus(buyerOrder.getStatus() == null ? -1 : buyerOrder.getStatus());
|
|
|
OrderStatus orderStatus = OrderStatus.getOrderStatus(orderInfo.getStatus());
|
|
|
orderInfo.setStatuStr(orderStatus == null ? "" : orderStatus.getListStatusStr());
|
|
|
|
|
|
// 按钮显示
|
|
|
orderInfo.setButtons(orderStatus == null ? Lists.newArrayList() : orderStatus.getButtonList());
|
|
|
|
|
|
// 当订单状态是待付款, 显示leftTime
|
|
|
if (orderInfo.getStatus() == OrderStatus.WAITING_PAY.getCode()){
|
|
|
orderInfo.setLeftTime(DateUtil.getCurrentTimeSecond() - buyerOrder.getCreateTime());
|
|
|
}
|
|
|
|
|
|
});
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMap.get(buyerOrder.getOrderCode());
|
|
|
if (buyerOrderGoods == null){
|
|
|
return null;
|
|
|
}
|
|
|
orderInfo.setSkup(buyerOrderGoods.getSkup());
|
|
|
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMap.get(buyerOrderGoods.getSkup());
|
|
|
if (sellerOrderGoods == null){
|
|
|
return null;
|
|
|
}
|
|
|
orderInfo.setProductName(sellerOrderGoods.getProductName());
|
|
|
orderInfo.setImageUrl(sellerOrderGoods.getImageUrl());
|
|
|
orderInfo.setColorName(sellerOrderGoods.getColorName());
|
|
|
orderInfo.setSizeName(sellerOrderGoods.getSizeName());
|
|
|
return orderInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据type获取 指定的状态
|
|
|
* @param request
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Integer> initOrderListRequest(OrderListRequest request) {
|
|
|
if (request.getUid() < 0){
|
|
|
logger.warn("getOrderList uid is {}", request.getUid());
|
|
|
throw new ServiceException(ServiceError.ORDER_UID_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
OrderListType orderListType = OrderListType.getOrderListType(request.getType());
|
|
|
if (orderListType == null){
|
|
|
logger.warn("getOrderList type invalidate, uid is {}, type is {}",request.getUid(), request.getType());
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
|
|
|
request.setPage(request.getPage() > 0 ? request.getPage() : 1);
|
|
|
request.setLimit( request.getLimit() > 0 ? request.getLimit() : 10 );
|
|
|
return orderListType.getStatusQuery();
|
|
|
}
|
|
|
} |
...
|
...
|
|