Authored by qinchao

增加状态:鉴定通过和发货相关流程

@@ -107,7 +107,28 @@ public class AppraiseController { @@ -107,7 +107,28 @@ public class AppraiseController {
107 @IgnoreSignature 107 @IgnoreSignature
108 public ApiResponse appraiseSuccess(@RequestBody AppraiseExpressInfoBo appraiseExpressInfoBo) { 108 public ApiResponse appraiseSuccess(@RequestBody AppraiseExpressInfoBo appraiseExpressInfoBo) {
109 logger.info("in appraiseSuccess, req {}", appraiseExpressInfoBo); 109 logger.info("in appraiseSuccess, req {}", appraiseExpressInfoBo);
110 - return appraiseService.appraiseSuccess(appraiseExpressInfoBo.getExpressCompanyId(), appraiseExpressInfoBo.getOrderCode(), appraiseExpressInfoBo.getWayBillCode(),appraiseExpressInfoBo.getDepotNum(),appraiseExpressInfoBo.getMobile()); 110 + return appraiseService.appraiseSuccessAndDelivery(appraiseExpressInfoBo.getExpressCompanyId(), appraiseExpressInfoBo.getOrderCode(), appraiseExpressInfoBo.getWayBillCode(),appraiseExpressInfoBo.getDepotNum(),appraiseExpressInfoBo.getMobile());
  111 + }
  112 +
  113 +
  114 + /**
  115 + * TODO 手机质检: 鉴定通过流程,订单进入JUDGE_PASS状态,但是没有发货
  116 + * 瑕疵确认通过 -->鉴定通过
  117 + * 平台鉴定中 -->鉴定通过
  118 + */
  119 + public ApiResponse judgeCenterPass(Long orderCode){
  120 + logger.info("in judgeCenterPass, orderCode {}", orderCode);
  121 + return appraiseService.judgeCenterPass(orderCode);
  122 + }
  123 +
  124 + /**
  125 + * TODO 手机质检: 发货
  126 + * 鉴定通过 -- 待收货
  127 + */
  128 + public ApiResponse deliveryGoodsToBuyer(AppraiseExpressInfoBo appraiseExpressInfoBo){
  129 + logger.info("in deliveryGoodsToBuyer, appraiseExpressInfoBo {}", appraiseExpressInfoBo);
  130 + appraiseService.deliveryGoodsToBuyer(appraiseExpressInfoBo);
  131 + return new ApiResponse();
111 } 132 }
112 133
113 /* 134 /*
@@ -714,7 +714,173 @@ public class AppraiseService { @@ -714,7 +714,173 @@ public class AppraiseService {
714 } 714 }
715 } 715 }
716 716
717 - public ApiResponse appraiseSuccess(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum,String mobile){ 717 + /**
  718 + * 正常发货
  719 + * 鉴定通过 -- 待收货
  720 + */
  721 + public void deliveryGoodsToBuyer(AppraiseExpressInfoBo appraiseExpressInfoBo){
  722 + LOGGER.info("deliveryGoodsToBuyer enter req {}", appraiseExpressInfoBo);
  723 + final OrderStatus expectOrderStatus = OrderStatus.JUDGE_PASS;
  724 + final OrderStatus targetOrderStatus = OrderStatus.WAITING_RECEIVE;
  725 + Long orderCode = appraiseExpressInfoBo.getOrderCode();
  726 + BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
  727 +
  728 + if (buyerOrder == null){
  729 + LOGGER.warn("deliveryGoodsToBuyer getOrderInfo order not exist, orderCode is {}", orderCode);
  730 + throw new ServiceException(ServiceError.ORDER_NULL);
  731 + }
  732 +
  733 + if (expectOrderStatus.getCode() != buyerOrder.getStatus().intValue()){
  734 + LOGGER.warn("in deliveryGoodsToBuyer, buyer Order orderCode {} pstatus {}, expect Order Status {}",
  735 + orderCode, buyerOrder.getStatus(), expectOrderStatus);
  736 + throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
  737 + }
  738 +
  739 + Integer buyerUid = buyerOrder.getUid();
  740 + int updateBuyerCnt = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid,
  741 + expectOrderStatus.getCode(), targetOrderStatus.getCode(), DateUtil.getCurrentTimeSecond());
  742 + if (updateBuyerCnt == 1){
  743 + //发货,这个时候产生:买家确认收货的mq
  744 + BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
  745 + EventBusPublisher.publishEvent(buyerConfirmEvent);
  746 +
  747 + //记录物流信息
  748 + //发物流
  749 + expressInfoService.deliverGoods(buyerUid, appraiseExpressInfoBo.getExpressCompanyId(), orderCode, appraiseExpressInfoBo.getWayBillCode(), appraiseExpressInfoBo.getDepotNum(),appraiseExpressInfoBo.getMobile());
  750 +
  751 + //记录订单的状态变更信息
  752 + orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetOrderStatus.getCode());
  753 +
  754 + //TODO 平台已发货给买家
  755 +
  756 + //清缓存
  757 + cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(),buyerOrder.getUid(),buyerOrder.getSellerUid());
  758 + }else{
  759 + LOGGER.warn("in deliveryGoodsToBuyer update status number zero, buyer Order orderCode {} pstatus {}, expect Order Status {}",
  760 + orderCode, buyerOrder.getStatus(), expectOrderStatus);
  761 + throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
  762 + }
  763 + }
  764 +
  765 + /**
  766 + * 鉴定通过,但是不发货
  767 + * @return
  768 + */
  769 + public ApiResponse judgeCenterPass(Long orderCode){
  770 + LOGGER.info("judgeCenterPass enter req orderCode {}", orderCode);
  771 + ApiResponse apiResponse=new ApiResponse();
  772 + BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
  773 +
  774 + if (buyerOrder == null){
  775 + LOGGER.warn("judgeCenterPass getOrderInfo order not exist, orderCode is {}", orderCode);
  776 + throw new ServiceException(ServiceError.ORDER_NULL);
  777 + }
  778 + final OrderStatus expectOrderStatus ;
  779 + final OrderStatus targetOrderStatus = OrderStatus.JUDGE_PASS;
  780 + if( OrderStatus.PLATFORM_CHECKING.getCode() == buyerOrder.getStatus().intValue()){
  781 + expectOrderStatus = OrderStatus.PLATFORM_CHECKING;
  782 + }else{
  783 + LOGGER.warn("in judgeCenterPass, buyer Order orderCode {} status {}, expect Order Status is OrderStatus.PLATFORM_CHECKING or OrderStatus.MINI_FAULT_ACCEPT ",
  784 + orderCode, buyerOrder.getStatus());
  785 + throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
  786 + }
  787 +
  788 + Integer buyerUid = buyerOrder.getUid();
  789 + BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(buyerUid, orderCode);
  790 + int skup = bog.getSkup();
  791 + SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(skup);
  792 +
  793 +
  794 + int updateBuyerCnt = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid,
  795 + expectOrderStatus.getCode(), targetOrderStatus.getCode(), DateUtil.getCurrentTimeSecond());
  796 +
  797 + if (updateBuyerCnt == 1){
  798 + final Integer sellerUid = sellerOrder.getUid();
  799 + final Long sellerOrderCode = sellerOrder.getOrderCode();
  800 + final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
  801 + final SellerOrderStatus targetSoStatus = SellerOrderStatus.FINISH;
  802 +
  803 + /**
  804 + * 更新卖家订单状态,
  805 + */
  806 + SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid ,sellerOrderCode,expectSOStatus,targetSoStatus,
  807 + skup, orderCode, buyerUid);
  808 +
  809 +
  810 + //退款给卖家(仅退一次)
  811 + PaymentRequest refundReqOfSeller = operateMoneyWhenOk(buyerUid,orderCode,skup,sellerOrder,targetSoStatus);
  812 +
  813 + try {
  814 + //记录订单的状态变更信息
  815 + LOGGER.info("in judgeCenterPass record status change, orderCode {},uid {} ,sellerUid {}", orderCode,buyerUid,sellerUid);
  816 + orderStatusFlowService.addAsy(buyerOrder.getOrderCode(),targetOrderStatus.getCode());
  817 +
  818 + //TODO 鉴定通过,等待发货,消息
  819 + //inBoxFacade.appraisePassNotice(buyerUid, orderCode, sellerOrderGoods);
  820 + }catch (Exception ex){
  821 + LOGGER.warn("in judgeCenterPass,refund fail, refundReqOfSeller {}", refundReqOfSeller, ex);
  822 + String content = "鉴定通过时,订单"+ orderCode + "退还保证金失败";
  823 + apiResponse.setCode(400);
  824 + apiResponse.setMessage(content);
  825 + }finally {
  826 + //记录调拨信息
  827 + EnumExpressType expressType = EnumExpressType.EXPRESS_TYPE_JUDGE_CENTER;
  828 + EnumExpressDataType expressDataType = EnumExpressDataType.operate_transfer;
  829 + EnumExpressDataOperateTransferCode operateTransferCode = EnumExpressDataOperateTransferCode.judge_pass;
  830 + expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
  831 + }
  832 +
  833 + LOGGER.info("in judgeCenterPass, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
  834 + sellerUid, sellerOrderCode, skup, sellerOrder.getEarnestMoney() );
  835 +
  836 +
  837 + }else{
  838 + LOGGER.warn("in judgeCenterPass, buyer Order pstatus {}, expect expectOrderStatus {}",
  839 + buyerOrder.getStatus(), expectOrderStatus);
  840 + apiResponse.setCode(400);
  841 + apiResponse.setMessage("订单状态发生变化");
  842 + }
  843 +
  844 + return apiResponse;
  845 + }
  846 +
  847 + /**
  848 + * 通过时 ,操作钱
  849 + */
  850 + private PaymentRequest operateMoneyWhenOk(Integer buyerUid,Long orderCode,int skup,SellerOrder sellerOrder,SellerOrderStatus targetSoStatus){
  851 + TransferCase transferCase = TransferCase.ALL_GOODS_MONEY_TO_SELLER;
  852 + TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
  853 + .buyerOrderCode(orderCode)
  854 + .type(transferCase.getCode())
  855 + .transferCase(transferCase)
  856 + .alarmConfig(AlarmConfig.APPRAISE_SUCCESS)
  857 + .build();
  858 +
  859 + //先校验,提前把错误抛出
  860 + paymentService.transferMonCheck(tmReq);
  861 +
  862 + //改成异步的分账,不关心分账执行结果
  863 + executorService.execute(()->{
  864 + LOGGER.info("in appraiseSuccess,begin transfer async");
  865 + transferService.transfer(tmReq);
  866 + });
  867 +
  868 + /**
  869 + * 退保证金给卖家
  870 + */
  871 + final Integer sellerUid = sellerOrder.getUid();
  872 + BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
  873 + //refund earnestMoney
  874 + PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.APPRAISE_OK,orderCode,sellerUid ,sellerOrder,skup,buyerUid,targetSoStatus,earnestMoney.doubleValue());
  875 + LOGGER.info("in appraiseSuccess,refund ok, refundReqOfSeller {}", refundReqOfSeller);
  876 + return refundReqOfSeller;
  877 + }
  878 +
  879 + /**
  880 + * 鉴定通过并发货
  881 + */
  882 + public ApiResponse appraiseSuccessAndDelivery(Integer expressCompanyId, Long orderCode, String wayBillCode,Integer depotNum,String mobile){
  883 + LOGGER.info("appraiseSuccessAndDelivery enter req orderCode {},wayBillCode {},mobile {}", orderCode,wayBillCode,mobile);
718 ApiResponse apiResponse=new ApiResponse(); 884 ApiResponse apiResponse=new ApiResponse();
719 BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode); 885 BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
720 886
@@ -744,19 +910,14 @@ public class AppraiseService { @@ -744,19 +910,14 @@ public class AppraiseService {
744 final Long sellerOrderCode = sellerOrder.getOrderCode(); 910 final Long sellerOrderCode = sellerOrder.getOrderCode();
745 final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED; 911 final SellerOrderStatus expectSOStatus = SellerOrderStatus.HAS_PAYED;
746 final SellerOrderStatus targetSoStatus = SellerOrderStatus.FINISH; 912 final SellerOrderStatus targetSoStatus = SellerOrderStatus.FINISH;
747 - /**  
748 - * 更新卖家订单状态,  
749 - * 退款给卖家(仅退一次)  
750 - *  
751 - */  
752 - SellerOrder tso = new SellerOrder();  
753 - tso.setUid(sellerUid);  
754 - tso.setOrderCode(sellerOrderCode);  
755 - tso.setStatus(targetSoStatus.getCode());  
756 - tso.setUpdateTime(DateUtil.getCurrentTimeSecond());  
757 - tso.setExceptStatus(expectSOStatus.getCode());  
758 - int soCnt = sellerOrderMapper.updateByOrderCode(tso);  
759 - TransferCase transferCase = TransferCase.ALL_GOODS_MONEY_TO_SELLER; 913 +
  914 + //更新卖家订单状态
  915 + SellerOrderGoods sellerOrderGoods = updateSellerOrderStatusAndCleanCache(sellerUid ,sellerOrderCode,expectSOStatus,targetSoStatus,
  916 + skup, orderCode, buyerUid);
  917 + //退款给卖家(仅退一次)
  918 + PaymentRequest refundReqOfSeller = operateMoneyWhenOk(buyerUid,orderCode,skup,sellerOrder,targetSoStatus);
  919 +
  920 + /*TransferCase transferCase = TransferCase.ALL_GOODS_MONEY_TO_SELLER;
760 TransferMoneyRequest tmReq = TransferMoneyRequest.builder() 921 TransferMoneyRequest tmReq = TransferMoneyRequest.builder()
761 .buyerOrderCode(orderCode) 922 .buyerOrderCode(orderCode)
762 .type(transferCase.getCode()) 923 .type(transferCase.getCode())
@@ -773,15 +934,13 @@ public class AppraiseService { @@ -773,15 +934,13 @@ public class AppraiseService {
773 transferService.transfer(tmReq); 934 transferService.transfer(tmReq);
774 }); 935 });
775 936
776 - /**  
777 - * 退保证金给卖家  
778 - */ 937 +
779 //refund earnestMoney 938 //refund earnestMoney
780 BigDecimal earnestMoney = sellerOrder.getEarnestMoney(); 939 BigDecimal earnestMoney = sellerOrder.getEarnestMoney();
781 PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.APPRAISE_OK,orderCode,sellerUid ,sellerOrder,skup,buyerUid,targetSoStatus,earnestMoney.doubleValue()); 940 PaymentRequest refundReqOfSeller = refundEarnestMoney(SellerWalletDetail.Type.APPRAISE_OK,orderCode,sellerUid ,sellerOrder,skup,buyerUid,targetSoStatus,earnestMoney.doubleValue());
782 LOGGER.info("in appraiseSuccess,refund ok, refundReqOfSeller {}", refundReqOfSeller); 941 LOGGER.info("in appraiseSuccess,refund ok, refundReqOfSeller {}", refundReqOfSeller);
  942 + */
783 943
784 - SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);  
785 try { 944 try {
786 //鉴定通过后自动发货,这个时候产生:买家确认收货的mq 945 //鉴定通过后自动发货,这个时候产生:买家确认收货的mq
787 BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build(); 946 BuyerConfirmEvent buyerConfirmEvent = BuyerConfirmEvent.builder().uid(buyerUid).orderCode(orderCode).build();
@@ -809,18 +968,8 @@ public class AppraiseService { @@ -809,18 +968,8 @@ public class AppraiseService {
809 expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode); 968 expressInfoService.saveOperateTransferExpressInfo(sellerUid,orderCode,expressType.getCode(),expressDataType,operateTransferCode);
810 } 969 }
811 970
812 - cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),  
813 - CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),  
814 - CacheKeyBuilder.sellerOrderDetailKey(sellerOrderGoods),  
815 - CacheKeyBuilder.orderDetailKey(sellerUid, TabType.SELL.getValue(), orderCode),  
816 - CacheKeyBuilder.orderDetailKey(buyerUid,TabType.BUY.getValue(), orderCode),  
817 - CacheKeyBuilder.buyerOrderNums(buyerUid)));  
818 -  
819 - ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);  
820 - EventBusPublisher.publishEvent(event);  
821 -  
822 LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}", 971 LOGGER.info("in appraiseSuccess, refund earnestMoney finish, seller {}, order code {}, skup {}, earnestMoney {}",
823 - sellerUid, sellerOrderCode, skup, earnestMoney ); 972 + sellerUid, sellerOrderCode, skup, sellerOrder.getEarnestMoney() );
824 973
825 974
826 }else{ 975 }else{