Authored by LUOXC

添加查询商品接口

... ... @@ -34,6 +34,8 @@ public interface SellerOrderMapper {
List<SellerOrder> selectBySkups(@Param("skupList") Collection<Integer> skups);
List<SellerOrder> selectByOrderCodes(@Param("orderCodes")Collection<Long> orderCodes);
/**
* 根据用户id查询卖的单数
* @param uid
... ...
... ... @@ -65,6 +65,18 @@
order by create_time desc
</select>
<select id="selectByOrderCodes" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from seller_order
where order_code IN
<foreach collection="orderCodes" item="orderCode" open="(" separator="," close=")">
#{orderCode,jdbcType=BIGINT}
</foreach>
</select>
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.yohoufo.dal.order.model.SellerOrder" useGeneratedKeys="true">
insert into seller_order (order_code, skup, uid,
... ...
package com.yohoufo.order.controller;
import com.google.common.base.Splitter;
import com.yohobuy.ufo.model.order.common.OrderListType;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.common.SellerOrderListType;
... ... @@ -18,14 +19,17 @@ import com.yohoufo.order.model.request.OrderRequest;
import com.yohoufo.order.model.request.SaveQualityCheckInfoRequest;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.IPaymentService;
import com.yohoufo.order.service.OrderGoodsFinder;
import com.yohoufo.order.service.impl.*;
import com.yohoufo.order.utils.LoggerUtils;
import lombok.val;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/erp")
... ... @@ -52,6 +56,9 @@ public class ErpGWOrderController {
@Autowired
private BuyerOrderViewService buyerOrderViewService;
@Autowired
private OrderGoodsFinder orderGoodsFinder;
@RequestMapping(params = "method=ufo.buyer.orderNums")
@IgnoreSession
public BuyerOrderNums getBuyerOrderNums(@RequestParam("uid") int uid){
... ... @@ -208,6 +215,16 @@ public class ErpGWOrderController {
}
@IgnoreSignature
@IgnoreSession
@RequestMapping(value = "/findOrderGoods")
public ApiResponse findOrderGoods(@RequestParam(value = "orderCodes") String orderCodes) {
List<Long> orderCodeList = Splitter.on(",").trimResults().splitToList(orderCodes).stream()
.map(Long::valueOf)
.collect(Collectors.toList());
val result = orderGoodsFinder.find(orderCodeList);
return new ApiResponse.ApiResponseBuilder().code(200).data(result).build();
}
}
... ...
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());
}
}
... ...