Authored by chenchao

add deliver time out 4 seller deposit order

@@ -3,6 +3,8 @@ package com.yohoufo.order.mq.consumer; @@ -3,6 +3,8 @@ package com.yohoufo.order.mq.consumer;
3 import com.yohoufo.order.event.SellerCancelDeliverEvent; 3 import com.yohoufo.order.event.SellerCancelDeliverEvent;
4 import com.yohoufo.order.mq.TopicConstants; 4 import com.yohoufo.order.mq.TopicConstants;
5 import com.yohoufo.order.service.impl.BuyerOrderCancelService; 5 import com.yohoufo.order.service.impl.BuyerOrderCancelService;
  6 +import com.yohoufo.order.service.impl.ServiceOrderProcessor;
  7 +import com.yohoufo.order.service.seller.deposit.SellerDepositOrderService;
6 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Component; 9 import org.springframework.stereotype.Component;
8 10
@@ -14,8 +16,14 @@ import org.springframework.stereotype.Component; @@ -14,8 +16,14 @@ import org.springframework.stereotype.Component;
14 public class SellerOrderCancelDeliverDelayMsgConsumer extends JsonObjectMessageConsumer<SellerCancelDeliverEvent> { 16 public class SellerOrderCancelDeliverDelayMsgConsumer extends JsonObjectMessageConsumer<SellerCancelDeliverEvent> {
15 17
16 @Autowired 18 @Autowired
  19 + private ServiceOrderProcessor serviceOrderProcessor;
  20 +
  21 + @Autowired
17 private BuyerOrderCancelService buyerOrderCancelService; 22 private BuyerOrderCancelService buyerOrderCancelService;
18 23
  24 + @Autowired
  25 + private SellerDepositOrderService sellerDepositOrderService;
  26 +
19 @Override 27 @Override
20 public String getTopic() { 28 public String getTopic() {
21 return TopicConstants.SELLER_ORDER_AUTO_CANCEL_DELIVER; 29 return TopicConstants.SELLER_ORDER_AUTO_CANCEL_DELIVER;
@@ -23,6 +31,11 @@ public class SellerOrderCancelDeliverDelayMsgConsumer extends JsonObjectMessageC @@ -23,6 +31,11 @@ public class SellerOrderCancelDeliverDelayMsgConsumer extends JsonObjectMessageC
23 31
24 @Override 32 @Override
25 public void handle(SellerCancelDeliverEvent event) { 33 public void handle(SellerCancelDeliverEvent event) {
26 - buyerOrderCancelService.cancelForSellerSendOutTimeout(event.getUid(), event.getOrderCode(), event.getSkup(), event.getSellerOrderGoods()); 34 + long orderCode = event.getOrderCode();
  35 + if (serviceOrderProcessor.isGoodsServiceOrder(orderCode)){
  36 + int rows = sellerDepositOrderService.cancelForSendOutTimeout(orderCode);
  37 + return;
  38 + }
  39 + buyerOrderCancelService.cancelForSellerSendOutTimeout(event.getUid(), orderCode, event.getSkup(), event.getSellerOrderGoods());
27 } 40 }
28 } 41 }
@@ -28,10 +28,7 @@ import com.yohoufo.dal.order.model.*; @@ -28,10 +28,7 @@ import com.yohoufo.dal.order.model.*;
28 import com.yohoufo.order.common.ClientType; 28 import com.yohoufo.order.common.ClientType;
29 import com.yohoufo.order.common.DelStatus; 29 import com.yohoufo.order.common.DelStatus;
30 import com.yohoufo.order.constants.MetaKey; 30 import com.yohoufo.order.constants.MetaKey;
31 -import com.yohoufo.order.event.OrderCancelEvent;  
32 -import com.yohoufo.order.event.PayConfirmEvent;  
33 -import com.yohoufo.order.event.SellerDepositOrderCancelAsyncEvent;  
34 -import com.yohoufo.order.event.SellerDepositOrderStatusConsistencyAsyncEvent; 31 +import com.yohoufo.order.event.*;
35 import com.yohoufo.order.model.PayQueryBo; 32 import com.yohoufo.order.model.PayQueryBo;
36 import com.yohoufo.order.model.dto.PlatformFeeDto; 33 import com.yohoufo.order.model.dto.PlatformFeeDto;
37 import com.yohoufo.order.model.dto.SellerDepositOrderContext; 34 import com.yohoufo.order.model.dto.SellerDepositOrderContext;
@@ -609,14 +606,20 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -609,14 +606,20 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
609 } 606 }
610 607
611 public void processAfterPay(OrderInfo orderInfo){ 608 public void processAfterPay(OrderInfo orderInfo){
  609 + Long orderCode = orderInfo.getOrderCode();
  610 + Integer uid = orderInfo.getUid();
612 AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.HAS_PAYED; 611 AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.HAS_PAYED;
613 inBoxFacade.sellerDepositOrderNotice(orderInfo.getUid(), orderInfo.getOrderCode(), targetOrderStatus); 612 inBoxFacade.sellerDepositOrderNotice(orderInfo.getUid(), orderInfo.getOrderCode(), targetOrderStatus);
614 SellerDepositOrderCancelAsyncEvent event = new SellerDepositOrderCancelAsyncEvent(this::handleOrderCancelAsyncEvent); 613 SellerDepositOrderCancelAsyncEvent event = new SellerDepositOrderCancelAsyncEvent(this::handleOrderCancelAsyncEvent);
615 - event.setUid(orderInfo.getUid());  
616 - event.setOrderCode(orderInfo.getOrderCode()); 614 + event.setUid(uid);
  615 + event.setOrderCode(orderCode);
617 EventBusPublisher.publishEvent(event); 616 EventBusPublisher.publishEvent(event);
618 logger.info("processAfterPay seller deposit order , SellerDepositOrderCancelAsyncEvent send out, event {}", event); 617 logger.info("processAfterPay seller deposit order , SellerDepositOrderCancelAsyncEvent send out, event {}", event);
619 - 618 + SellerCancelDeliverEvent cancelDeliverEvent =
  619 + SellerCancelDeliverEvent.builder()
  620 + .uid(orderInfo.getUid())
  621 + .orderCode(orderCode).build();
  622 + EventBusPublisher.publishEvent(cancelDeliverEvent);
620 } 623 }
621 624
622 625
@@ -735,4 +738,53 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -735,4 +738,53 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
735 asyncEvent.setOrderCode(orderCode); 738 asyncEvent.setOrderCode(orderCode);
736 EventBusPublisher.publishEvent(asyncEvent); 739 EventBusPublisher.publishEvent(asyncEvent);
737 } 740 }
  741 +
  742 + /**
  743 + * 发货超时取消
  744 + * @param orderCode
  745 + */
  746 + public int cancelForSendOutTimeout(long orderCode){
  747 + logger.info("in cancel seller deposit order For Send Out Timeout orderCode {}", orderCode);
  748 + ServiceOrderProcessor.ExistenceNode existenceNode = serviceOrderProcessor.isAppraiseOrder(orderCode);
  749 +
  750 + if (!existenceNode.isExisted()){
  751 + logger.warn("auto cancel AppraiseOrder not exist, orderCode {}", orderCode);
  752 + throw new UfoServiceException(400, "订单已迷路");
  753 + }
  754 + AppraiseOrder pao = existenceNode.getAppraiseOrder();
  755 +
  756 + OrderAttributes oa = OrderAttributes.getOrderAttributes(pao.getAttributes());
  757 + if (!OrderAttributes.DEPOSITE.equals(oa)){
  758 + logger.warn("auto cancel AppraiseOrder not deposit Order, orderCode {}", orderCode);
  759 + throw new UfoServiceException(400, "订单已迷路");
  760 + }
  761 + int uid = pao.getUid();
  762 + AppraiseOrderStatus appraiseOrderStatus = AppraiseOrderStatus.getByCode(pao.getStatus());
  763 + int rows = 0;
  764 + AppraiseOrderStatus targetOrderStatus = null;
  765 + switch (appraiseOrderStatus){
  766 + case HAS_PAYED:
  767 + targetOrderStatus= AppraiseOrderStatus.SEND_OUT_TIMEOUT;
  768 + rows = super.triggerStatusChange(orderCode, targetOrderStatus, appraiseOrderStatus);
  769 + if (rows>0){
  770 + new GoodsServiceRefundHandler()
  771 + .loadLogger(logger)
  772 + .loadUser(uid)
  773 + .loadActionCase(SellerWalletDetail.Type.SELLER_OVER_TIME)
  774 + .loadRefundAction(payRefundService::refund)
  775 + .loadOrder(orderCode, orderCode, pao.getPayment(), pao.getAmount())
  776 + .refund();
  777 + //notice
  778 + inBoxFacade.sellerDepositOrderNotice(uid, orderCode, targetOrderStatus);
  779 + }
  780 +
  781 +
  782 + break;
  783 + default:
  784 + throw new UfoServiceException(400, "订单不支持取消");
  785 + }
  786 +
  787 + return rows;
  788 +
  789 + }
738 } 790 }