Authored by chenchao

add query buyer order

... ... @@ -35,6 +35,7 @@ import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.PaymentHelper;
import lombok.experimental.Builder;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -44,6 +45,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* Created by chenchao on 2018/9/17.
... ... @@ -106,26 +108,53 @@ public class SellerOrderCancelService {
cancel(uid, orderCode, actor);
}
private final static List<Integer> relatedBuyerStatusList = Arrays.asList(OrderStatus.WAITING_PAY.getCode(),
OrderStatus.HAS_PAYED.getCode(), OrderStatus.SELLER_SEND_OUT.getCode(), OrderStatus.PLATFORM_CHECKING.getCode(),
OrderStatus.WAITING_RECEIVE.getCode(), OrderStatus.DONE.getCode());
private BuyerOrder getBuyerOrderBySkup(Integer skup, int uid, Long orderCode, OrderCodeType actor){
List<BuyerOrderGoods> pbogList = buyerOrderGoodsMapper.selectBySkups(Arrays.asList(skup));
BuyerOrder buyerOrder = null;
if (CollectionUtils.isNotEmpty(pbogList)){
List<Long> orderCodeList = pbogList.parallelStream().map(BuyerOrderGoods::getOrderCode).collect(Collectors.toList());
List<BuyerOrder> pboList = buyerOrderMapper.selectByOrderCodes(orderCodeList, relatedBuyerStatusList);
if (CollectionUtils.isNotEmpty(pboList)){
if(pboList.size() > 1){
logger.warn("in seller cancel ,related buyer order size {} buyer orderCodeList {} uid {} orderCode {} actor {}",
pboList.size(), orderCodeList, uid, orderCode, actor);
throw new UfoServiceException(501, "订单不能取消");
}
buyerOrder = pboList.get(0);
}
}
return buyerOrder;
}
public int cancel(int uid, long orderCode, OrderCodeType actor){
int result = 0;
SellerOrder sellerOrder = null;
BuyerOrder buyerOrder = null;
Integer skup=null;
//seller order code
if (OrderCodeType.SELLER_TYPE.equals(actor)){
sellerOrder = sellerOrderMapper.selectByOrderCodeUid(orderCode, uid);
if (Objects.isNull(sellerOrder)){
return result;
}
skup = sellerOrder.getSkup();
buyerOrder = getBuyerOrderBySkup(skup, uid, orderCode, actor);
}
BuyerOrder buyerOrder = null;
//buyer order code
if (OrderCodeType.BUYER_TYPE.equals(actor)){
buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), orderCode);
sellerOrder = sellerOrderMapper.selectBySkup(buyerOrderGoods.getSkup());
if (Objects.isNull(sellerOrder)){
return result;
}
skup = sellerOrder.getSkup();
}
if (Objects.isNull(sellerOrder)){
return result;
}
final int skup = sellerOrder.getSkup();
Integer status = Optional.ofNullable(sellerOrder).map(SellerOrder::getStatus).orElse(null);
logger.info("in seller cancel, uid {}, orderCode {}, SellerOrder status {}", uid, orderCode, status);
if (Objects.isNull(status)){
... ... @@ -316,7 +345,7 @@ public class SellerOrderCancelService {
*/
Integer buyerOrderStatus = buyerOrder.getStatus();
if (Objects.isNull(buyerOrderStatus) || !ActionStatusHold.sellerCanCancelBuyerOrder(buyerOrderStatus)){
throw new UfoServiceException(501, "不能取消");
throw new UfoServiceException(501, "买家支付中,不能取消");
}
final int sellerUid = sellerOrder.getUid(), buyerUid = buyerOrder.getUid();
... ...