|
|
package com.yohoufo.order.service;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.resp.OrderGoodsFindBO;
|
|
|
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
|
|
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.SellerOrderMapper;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.SellerOrder;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
|
|
|
import lombok.val;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class OrderGoodsFinder {
|
|
|
|
|
|
@Autowired
|
|
|
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerOrderMapper sellerOrderMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private OrderCodeGenerator orderCodeGenerator;
|
|
|
|
|
|
|
|
|
public List<OrderGoodsFindBO> find(List<Long> orderCodes) {
|
|
|
val orderCodeHoldList = orderCodes.stream()
|
|
|
.map(orderCode -> Pair.of(orderCode, orderCodeGenerator.expId(orderCode)))
|
|
|
.collect(Collectors.toList());
|
|
|
val buyerOrderCodeList = orderCodeHoldList.stream()
|
|
|
.filter(e -> e.getRight().getType() == OrderCodeType.BUYER_TYPE.getType())
|
|
|
.map(e -> e.getLeft())
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
val sellerOrderCodeList = orderCodeHoldList.stream()
|
|
|
.filter(e -> e.getRight().getType() == OrderCodeType.SELLER_TYPE.getType())
|
|
|
.map(e -> e.getLeft())
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
List<Pair<Long, Integer>> orderCodeList = Lists.newArrayList();
|
|
|
orderCodeList.addAll(findSkupForSellerOrderCode(sellerOrderCodeList));
|
|
|
orderCodeList.addAll(findSkupForBuyerOrderCode(buyerOrderCodeList));
|
|
|
if (CollectionUtils.isEmpty(orderCodeList)) {
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
val skupList = orderCodeList.stream()
|
|
|
.map(e -> e.getRight())
|
|
|
.collect(Collectors.toList());
|
|
|
List<SellerOrderGoods> sellerOrderGoodsList = sellerOrderGoodsMapper.selectBySkups(skupList);
|
|
|
return orderCodeList.stream()
|
|
|
.map(order -> sellerOrderGoodsList.stream()
|
|
|
.filter(e -> Objects.equals(e.getId(), order.getRight()))
|
|
|
.findFirst()
|
|
|
.map(e -> {
|
|
|
OrderGoodsFindBO bo = new OrderGoodsFindBO();
|
|
|
bo.setOrderCode(order.getLeft());
|
|
|
bo.setProductName(e.getProductName());
|
|
|
return bo;
|
|
|
})
|
|
|
.orElse(null)
|
|
|
)
|
|
|
.filter(Objects::nonNull)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
}
|
|
|
|
|
|
private List<Pair<Long, Integer>> findSkupForSellerOrderCode(List<Long> sellerOrderCodeList) {
|
|
|
if (CollectionUtils.isEmpty(sellerOrderCodeList)) {
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
List<SellerOrder> sellerOrders = sellerOrderMapper.selectByOrderCodes(sellerOrderCodeList);
|
|
|
return sellerOrders.stream()
|
|
|
.map(e -> Pair.of(e.getOrderCode(), e.getSkup()))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
private List<Pair<Long, Integer>> findSkupForBuyerOrderCode(List<Long> buyerOrderCodeList) {
|
|
|
if (CollectionUtils.isEmpty(buyerOrderCodeList)) {
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
List<BuyerOrderGoods> buyerOrderGoodsList = buyerOrderGoodsMapper.selectByOrderCodes(buyerOrderCodeList);
|
|
|
return buyerOrderGoodsList.stream()
|
|
|
.map(e -> Pair.of(e.getOrderCode(), e.getSkup()))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|