Authored by chenchao

add finish 4 parent order of seller deposit

  1 +package com.yohoufo.order.event;
  2 +
  3 +import lombok.Getter;
  4 +import lombok.Setter;
  5 +import lombok.ToString;
  6 +
  7 +import java.util.function.Function;
  8 +@ToString(of = { "orderCode" })
  9 +public class SellerDepositOrderStatusConsistencyAsyncEvent
  10 + extends AsyncEvent{
  11 + @Getter@Setter
  12 + private Long orderCode;
  13 +
  14 + public SellerDepositOrderStatusConsistencyAsyncEvent(Function<SellerDepositOrderStatusConsistencyAsyncEvent,Integer> function) {
  15 + super(function);
  16 + }
  17 +
  18 + @Override
  19 + AsyncEvent getAsyncEvent() {
  20 + return this;
  21 + }
  22 +}
@@ -424,16 +424,4 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements @@ -424,16 +424,4 @@ public class AppraiseOrderService extends AbsGoodsServiceOrderService implements
424 inBoxFacade.paidAppraiseOrderNotice(orderInfo.getUid(), orderInfo.getOrderCode(), targetStatus); 424 inBoxFacade.paidAppraiseOrderNotice(orderInfo.getUid(), orderInfo.getOrderCode(), targetStatus);
425 } 425 }
426 426
427 -  
428 - public int platformFinishReceiveGoods(long orderCode, long parentCode){  
429 -  
430 - return 0;  
431 - }  
432 -  
433 -  
434 - public int detectAppraiseFinish(long orderCode){  
435 -  
436 -  
437 - return 0;  
438 - }  
439 } 427 }
@@ -31,6 +31,7 @@ import com.yohoufo.order.constants.MetaKey; @@ -31,6 +31,7 @@ import com.yohoufo.order.constants.MetaKey;
31 import com.yohoufo.order.event.OrderCancelEvent; 31 import com.yohoufo.order.event.OrderCancelEvent;
32 import com.yohoufo.order.event.PayConfirmEvent; 32 import com.yohoufo.order.event.PayConfirmEvent;
33 import com.yohoufo.order.event.SellerDepositOrderCancelAsyncEvent; 33 import com.yohoufo.order.event.SellerDepositOrderCancelAsyncEvent;
  34 +import com.yohoufo.order.event.SellerDepositOrderStatusConsistencyAsyncEvent;
34 import com.yohoufo.order.model.PayQueryBo; 35 import com.yohoufo.order.model.PayQueryBo;
35 import com.yohoufo.order.model.dto.PlatformFeeDto; 36 import com.yohoufo.order.model.dto.PlatformFeeDto;
36 import com.yohoufo.order.model.dto.SellerDepositOrderContext; 37 import com.yohoufo.order.model.dto.SellerDepositOrderContext;
@@ -54,10 +55,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -54,10 +55,7 @@ import org.springframework.beans.factory.annotation.Autowired;
54 import org.springframework.stereotype.Service; 55 import org.springframework.stereotype.Service;
55 56
56 import java.math.BigDecimal; 57 import java.math.BigDecimal;
57 -import java.util.ArrayList;  
58 -import java.util.List;  
59 -import java.util.Map;  
60 -import java.util.Objects; 58 +import java.util.*;
61 import java.util.stream.Collectors; 59 import java.util.stream.Collectors;
62 60
63 @Service 61 @Service
@@ -343,6 +341,9 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -343,6 +341,9 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
343 if (rows == 0){ 341 if (rows == 0){
344 return rows; 342 return rows;
345 } 343 }
  344 + //
  345 + triggerStatusConsistencyCheck(orderCode);
  346 +
346 Long paidCode = pao.getParentOrderCode(); 347 Long paidCode = pao.getParentOrderCode();
347 inBoxFacade.sellerDepositOrderNotice(pao.getUid(), orderCode, targetStatus); 348 inBoxFacade.sellerDepositOrderNotice(pao.getUid(), orderCode, targetStatus);
348 BigDecimal left = calLeftMoney(pao.getAmount(), orderCode); 349 BigDecimal left = calLeftMoney(pao.getAmount(), orderCode);
@@ -405,6 +406,10 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -405,6 +406,10 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
405 if (rows == 0){ 406 if (rows == 0){
406 return rows; 407 return rows;
407 } 408 }
  409 + //
  410 + Long orderCode = appraiseOrder.getOrderCode();
  411 + triggerStatusConsistencyCheck(orderCode);
  412 + //
408 AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.CHECKING_FAKE; 413 AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.CHECKING_FAKE;
409 inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus); 414 inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus);
410 depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode()); 415 depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode());
@@ -421,6 +426,9 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -421,6 +426,9 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
421 if (rows == 0){ 426 if (rows == 0){
422 return rows; 427 return rows;
423 } 428 }
  429 + //
  430 + Long orderCode = appraiseOrder.getOrderCode();
  431 + triggerStatusConsistencyCheck(orderCode);
424 //refund amount 432 //refund amount
425 new GoodsServiceRefundHandler() 433 new GoodsServiceRefundHandler()
426 .loadLogger(logger) 434 .loadLogger(logger)
@@ -447,6 +455,10 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -447,6 +455,10 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
447 if (rows == 0){ 455 if (rows == 0){
448 return rows; 456 return rows;
449 } 457 }
  458 + //
  459 + Long orderCode = appraiseOrder.getOrderCode();
  460 + triggerStatusConsistencyCheck(orderCode);
  461 + //
450 AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.SHAM_SEND_OUT; 462 AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.SHAM_SEND_OUT;
451 inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus); 463 inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus);
452 //refund amount 464 //refund amount
@@ -567,16 +579,18 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -567,16 +579,18 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
567 if (rows == 0){ 579 if (rows == 0){
568 return rows; 580 return rows;
569 } 581 }
  582 + Long orderCode = appraiseOrder.getOrderCode();
  583 + triggerStatusConsistencyCheck(orderCode);
570 AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.QUALITY_CHECK_FAKE; 584 AppraiseOrderStatus targetOrderStatus = AppraiseOrderStatus.QUALITY_CHECK_FAKE;
571 - inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), targetOrderStatus); 585 + inBoxFacade.sellerDepositOrderNotice(appraiseOrder.getUid(), orderCode, targetOrderStatus);
572 new GoodsServiceRefundHandler() 586 new GoodsServiceRefundHandler()
573 .loadLogger(logger) 587 .loadLogger(logger)
574 .loadUser(appraiseOrder.getUid()) 588 .loadUser(appraiseOrder.getUid())
575 .loadActionCase(SellerWalletDetail.Type.FLAW) 589 .loadActionCase(SellerWalletDetail.Type.FLAW)
576 .loadRefundAction(payRefundService::refund) 590 .loadRefundAction(payRefundService::refund)
577 - .loadOrder(appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode(), appraiseOrder.getPayment(), appraiseOrder.getAmount()) 591 + .loadOrder(orderCode, appraiseOrder.getParentOrderCode(), appraiseOrder.getPayment(), appraiseOrder.getAmount())
578 .refund(); 592 .refund();
579 - depositService.insertFakeDeposit(appraiseOrder.getUid(), appraiseOrder.getOrderCode(), appraiseOrder.getParentOrderCode()); 593 + depositService.insertFakeDeposit(appraiseOrder.getUid(), orderCode, appraiseOrder.getParentOrderCode());
580 return rows; 594 return rows;
581 } 595 }
582 596
@@ -621,12 +635,23 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -621,12 +635,23 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
621 logger.warn("in getSubOrderStatistic selectByOrderCode null, orderCode {}", orderCode); 635 logger.warn("in getSubOrderStatistic selectByOrderCode null, orderCode {}", orderCode);
622 return new ArrayList<>(0); 636 return new ArrayList<>(0);
623 } 637 }
624 - long occ = appraiseOrder.getParentOrderCode()==null ? orderCode : appraiseOrder.getParentOrderCode(); 638 + long occ = findoutParentOrderCode(orderCode);
625 List<AppraiseOrder> paoList = appraiseOrderMapper.selectSubOrderStatistic(occ); 639 List<AppraiseOrder> paoList = appraiseOrderMapper.selectSubOrderStatistic(occ);
626 logger.info("getSubOrderStatistic orderCode {} ParentOrderCode {} AppraiseOrder list {}", orderCode, occ, paoList); 640 logger.info("getSubOrderStatistic orderCode {} ParentOrderCode {} AppraiseOrder list {}", orderCode, occ, paoList);
627 return paoList; 641 return paoList;
628 } 642 }
629 643
  644 + private Long findoutParentOrderCode(long orderCode){
  645 + AppraiseOrder appraiseOrder = appraiseOrderMapper.selectByOrderCode(orderCode);
  646 + if (Objects.isNull(appraiseOrder)){
  647 + logger.warn("in getSubOrderStatistic selectByOrderCode null, orderCode {}", orderCode);
  648 + return orderCode;
  649 + }
  650 + return appraiseOrder.getParentOrderCode()==null ? orderCode : appraiseOrder.getParentOrderCode();
  651 + }
  652 +
  653 +
  654 +
630 public DepositOrderStatisticInfo getAppraiseProgress(int uid, long orderCode){ 655 public DepositOrderStatisticInfo getAppraiseProgress(int uid, long orderCode){
631 List<AppraiseOrder> paoList = buildSubOrderStatisticList(orderCode); 656 List<AppraiseOrder> paoList = buildSubOrderStatisticList(orderCode);
632 657
@@ -681,4 +706,33 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple @@ -681,4 +706,33 @@ public class SellerDepositOrderService extends AbsGoodsServiceOrderService imple
681 706
682 return dosi; 707 return dosi;
683 } 708 }
  709 +
  710 + public int platformFinishReceiveGoods(long parentCode){
  711 + AppraiseOrderStatus targetStatus = AppraiseOrderStatus.FINISH,
  712 + expectedStatus = AppraiseOrderStatus.PLATFORM_RECEIVE;
  713 + return triggerStatusChange(parentCode,targetStatus,expectedStatus);
  714 + }
  715 +
  716 +
  717 + public int detectAppraiseFinish(SellerDepositOrderStatusConsistencyAsyncEvent event ){
  718 + logger.info("detectAppraiseFinish event {}", event);
  719 + long orderCode = event.getOrderCode();
  720 + long parentOrderCode = findoutParentOrderCode(orderCode);
  721 + int cnt =appraiseOrderMapper.selectSubOrderCntIncludeStatus(parentOrderCode,Arrays.asList(AppraiseOrderStatus.PLATFORM_RECEIVE.getCode()));
  722 + logger.info("detectAppraiseFinish event {},parentOrderCode {} PLATFORM_RECEIVE count {}", event, parentOrderCode, cnt);
  723 + if (cnt == 0){
  724 + int prows = platformFinishReceiveGoods(parentOrderCode);
  725 + logger.info("detectAppraiseFinish platformFinishReceiveGoods, orderCode {},parentOrderCode {} parent count {}",
  726 + orderCode, parentOrderCode, prows);
  727 + return prows;
  728 + }
  729 + return 0;
  730 + }
  731 +
  732 + public void triggerStatusConsistencyCheck(long orderCode){
  733 + SellerDepositOrderStatusConsistencyAsyncEvent asyncEvent
  734 + = new SellerDepositOrderStatusConsistencyAsyncEvent(this::detectAppraiseFinish);
  735 + asyncEvent.setOrderCode(orderCode);
  736 + EventBusPublisher.publishEvent(asyncEvent);
  737 + }
684 } 738 }