Authored by chenchao

add query buyer order

@@ -35,6 +35,7 @@ import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; @@ -35,6 +35,7 @@ import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
35 import com.yohoufo.order.utils.LoggerUtils; 35 import com.yohoufo.order.utils.LoggerUtils;
36 import com.yohoufo.order.utils.PaymentHelper; 36 import com.yohoufo.order.utils.PaymentHelper;
37 import lombok.experimental.Builder; 37 import lombok.experimental.Builder;
  38 +import org.apache.commons.collections.CollectionUtils;
38 import org.slf4j.Logger; 39 import org.slf4j.Logger;
39 import org.springframework.beans.factory.annotation.Autowired; 40 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.stereotype.Service; 41 import org.springframework.stereotype.Service;
@@ -44,6 +45,7 @@ import java.util.Arrays; @@ -44,6 +45,7 @@ import java.util.Arrays;
44 import java.util.List; 45 import java.util.List;
45 import java.util.Objects; 46 import java.util.Objects;
46 import java.util.Optional; 47 import java.util.Optional;
  48 +import java.util.stream.Collectors;
47 49
48 /** 50 /**
49 * Created by chenchao on 2018/9/17. 51 * Created by chenchao on 2018/9/17.
@@ -106,26 +108,53 @@ public class SellerOrderCancelService { @@ -106,26 +108,53 @@ public class SellerOrderCancelService {
106 cancel(uid, orderCode, actor); 108 cancel(uid, orderCode, actor);
107 } 109 }
108 110
  111 + private final static List<Integer> relatedBuyerStatusList = Arrays.asList(OrderStatus.WAITING_PAY.getCode(),
  112 + OrderStatus.HAS_PAYED.getCode(), OrderStatus.SELLER_SEND_OUT.getCode(), OrderStatus.PLATFORM_CHECKING.getCode(),
  113 + OrderStatus.WAITING_RECEIVE.getCode(), OrderStatus.DONE.getCode());
  114 +
  115 + private BuyerOrder getBuyerOrderBySkup(Integer skup, int uid, Long orderCode, OrderCodeType actor){
  116 + List<BuyerOrderGoods> pbogList = buyerOrderGoodsMapper.selectBySkups(Arrays.asList(skup));
  117 + BuyerOrder buyerOrder = null;
  118 + if (CollectionUtils.isNotEmpty(pbogList)){
  119 + List<Long> orderCodeList = pbogList.parallelStream().map(BuyerOrderGoods::getOrderCode).collect(Collectors.toList());
  120 + List<BuyerOrder> pboList = buyerOrderMapper.selectByOrderCodes(orderCodeList, relatedBuyerStatusList);
  121 + if (CollectionUtils.isNotEmpty(pboList)){
  122 + if(pboList.size() > 1){
  123 + logger.warn("in seller cancel ,related buyer order size {} buyer orderCodeList {} uid {} orderCode {} actor {}",
  124 + pboList.size(), orderCodeList, uid, orderCode, actor);
  125 + throw new UfoServiceException(501, "订单不能取消");
  126 + }
  127 + buyerOrder = pboList.get(0);
  128 + }
  129 + }
  130 + return buyerOrder;
  131 + }
109 132
110 public int cancel(int uid, long orderCode, OrderCodeType actor){ 133 public int cancel(int uid, long orderCode, OrderCodeType actor){
111 int result = 0; 134 int result = 0;
112 SellerOrder sellerOrder = null; 135 SellerOrder sellerOrder = null;
113 - 136 + BuyerOrder buyerOrder = null;
  137 + Integer skup=null;
  138 + //seller order code
114 if (OrderCodeType.SELLER_TYPE.equals(actor)){ 139 if (OrderCodeType.SELLER_TYPE.equals(actor)){
115 sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid); 140 sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
  141 + if (Objects.isNull(sellerOrder)){
  142 + return result;
116 } 143 }
117 -  
118 - BuyerOrder buyerOrder = null; 144 + skup = sellerOrder.getSkup();
  145 + buyerOrder = getBuyerOrderBySkup(skup, uid, orderCode, actor);
  146 + }
  147 + //buyer order code
119 if (OrderCodeType.BUYER_TYPE.equals(actor)){ 148 if (OrderCodeType.BUYER_TYPE.equals(actor)){
120 buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode); 149 buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
121 BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), orderCode); 150 BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), orderCode);
122 sellerOrder = sellerOrderMapper.selectBySkup(buyerOrderGoods.getSkup()); 151 sellerOrder = sellerOrderMapper.selectBySkup(buyerOrderGoods.getSkup());
123 - }  
124 -  
125 if (Objects.isNull(sellerOrder)){ 152 if (Objects.isNull(sellerOrder)){
126 return result; 153 return result;
127 } 154 }
128 - final int skup = sellerOrder.getSkup(); 155 + skup = sellerOrder.getSkup();
  156 + }
  157 +
129 Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null); 158 Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null);
130 logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status); 159 logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status);
131 if (Objects.isNull(status)){ 160 if (Objects.isNull(status)){
@@ -316,7 +345,7 @@ public class SellerOrderCancelService { @@ -316,7 +345,7 @@ public class SellerOrderCancelService {
316 */ 345 */
317 Integer buyerOrderStatus = buyerOrder.getStatus(); 346 Integer buyerOrderStatus = buyerOrder.getStatus();
318 if (Objects.isNull(buyerOrderStatus) || !ActionStatusHold.sellerCanCancelBuyerOrder(buyerOrderStatus)){ 347 if (Objects.isNull(buyerOrderStatus) || !ActionStatusHold.sellerCanCancelBuyerOrder(buyerOrderStatus)){
319 - throw new UfoServiceException(501, "不能取消"); 348 + throw new UfoServiceException(501, "买家支付中,不能取消");
320 } 349 }
321 350
322 final int sellerUid = sellerOrder.getUid(), buyerUid = buyerOrder.getUid(); 351 final int sellerUid = sellerOrder.getUid(), buyerUid = buyerOrder.getUid();