Authored by chenchao

customs clear fail

@@ -20,9 +20,17 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{ @@ -20,9 +20,17 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{
20 20
21 private Integer uid; 21 private Integer uid;
22 22
  23 + private Integer sellerUid;
  24 +
23 private Long orderCode; 25 private Long orderCode;
24 26
25 - private BigDecimal goodsMoney; 27 + private BigDecimal finalMoney;
  28 +
  29 + private Integer payment;
  30 +
  31 + private Integer skup;
  32 +
  33 + private final static RefundCase refundCase = RefundCase.BUYER_GOODS_MONEY;
26 34
27 35
28 public RefundGoodsMoneyHandler loadTargetOrderStatus(OrderStatus targetOrderStatus){ 36 public RefundGoodsMoneyHandler loadTargetOrderStatus(OrderStatus targetOrderStatus){
@@ -35,12 +43,13 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{ @@ -35,12 +43,13 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{
35 return this; 43 return this;
36 } 44 }
37 45
38 - public RefundGoodsMoneyHandler loadPaymentRequest(Integer uid,Long orderCode,BigDecimal goodsMoney){ 46 + public RefundGoodsMoneyHandler loadPaymentRequest(Integer uid,Long orderCode,Integer payment, BigDecimal goodsMoney){
39 this.uid = uid; 47 this.uid = uid;
40 this.orderCode = orderCode; 48 this.orderCode = orderCode;
41 - this.goodsMoney = goodsMoney; 49 + this.finalMoney = goodsMoney;
  50 + this.payment = payment;
42 this.paymentRequest = PaymentRequest.builder().uid(uid) 51 this.paymentRequest = PaymentRequest.builder().uid(uid)
43 - .refundCase(RefundCase.BUYER_GOODS_MONEY) 52 + .refundCase(refundCase)
44 .orderCode(orderCode).refundAmount(goodsMoney.doubleValue()) 53 .orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
45 .build(); 54 .build();
46 return this; 55 return this;
@@ -51,13 +60,33 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{ @@ -51,13 +60,33 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{
51 return this; 60 return this;
52 } 61 }
53 62
  63 + public RefundGoodsMoneyHandler loadSellerOrderGoods(Integer sellerUid, Integer skup){
  64 + this.sellerUid = sellerUid;
  65 + this.skup = skup;
  66 + return this;
  67 + }
  68 +
  69 +
  70 + private BillLogEvent.BillLogEventBuilder buildBillLogEvent(){
  71 + BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
  72 + .buyerUid(uid).sellerUid(sellerUid).orderCode(orderCode)
  73 + .payType(payment).refundCase(refundCase)
  74 + .amount(finalMoney)
  75 + .skup(skup);
  76 + return blebOfBuyer;
  77 + }
  78 +
54 public RefundGoodsMoneyHandler loadBillLogEventBuilder(BillLogEvent.BillLogEventBuilder bleb){ 79 public RefundGoodsMoneyHandler loadBillLogEventBuilder(BillLogEvent.BillLogEventBuilder bleb){
55 this.bleb = bleb; 80 this.bleb = bleb;
56 return this; 81 return this;
57 } 82 }
58 83
  84 + @Override
59 public boolean refund(){ 85 public boolean refund(){
60 try { 86 try {
  87 + if (bleb == null){
  88 + bleb = buildBillLogEvent();
  89 + }
61 refundConsumer.accept(paymentRequest, bleb); 90 refundConsumer.accept(paymentRequest, bleb);
62 return true; 91 return true;
63 }catch (Exception ex){ 92 }catch (Exception ex){
@@ -610,16 +610,20 @@ public class AppraiseService { @@ -610,16 +610,20 @@ public class AppraiseService {
610 610
611 //退买家的钱 611 //退买家的钱
612 BigDecimal goodsMoney = buyerOrder.getAmount(); 612 BigDecimal goodsMoney = buyerOrder.getAmount();
  613 + /*
613 BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder() 614 BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
614 .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode) 615 .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
615 .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY) 616 .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
616 .amount(goodsMoney) 617 .amount(goodsMoney)
617 .skup(skup); 618 .skup(skup);
618 - boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler().loadPaymentRequest(buyerUid, orderCode, goodsMoney)  
619 - .loadBillLogEventBuilder(bleb) 619 + */
  620 + boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
  621 + .loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
  622 + //.loadBillLogEventBuilder(bleb)
620 .loadTargetOrderStatus(targetStatus) 623 .loadTargetOrderStatus(targetStatus)
621 .loadRefundAction(payRefundService::refund) 624 .loadRefundAction(payRefundService::refund)
622 .loadLogger(LOGGER) 625 .loadLogger(LOGGER)
  626 + .loadSellerOrderGoods(sellerUid, skup)
623 .refund(); 627 .refund();
624 if (!refundGoodsMoneyFlag) { 628 if (!refundGoodsMoneyFlag) {
625 apiResponse.setCode(400); 629 apiResponse.setCode(400);
@@ -931,16 +935,18 @@ public class AppraiseService { @@ -931,16 +935,18 @@ public class AppraiseService {
931 935
932 //退钱给买家 936 //退钱给买家
933 BigDecimal goodsMoney = buyerOrder.getAmount(); 937 BigDecimal goodsMoney = buyerOrder.getAmount();
934 - BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder() 938 + /*BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
935 .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode) 939 .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
936 .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY) 940 .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
937 .amount(goodsMoney) 941 .amount(goodsMoney)
938 - .skup(skup);  
939 - boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler().loadPaymentRequest(buyerUid, orderCode, goodsMoney)  
940 - .loadBillLogEventBuilder(bleb) 942 + .skup(skup);*/
  943 + boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
  944 + .loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
  945 + //.loadBillLogEventBuilder(bleb)
941 .loadTargetOrderStatus(targetStatus) 946 .loadTargetOrderStatus(targetStatus)
942 .loadRefundAction(payRefundService::refund) 947 .loadRefundAction(payRefundService::refund)
943 .loadLogger(LOGGER) 948 .loadLogger(LOGGER)
  949 + .loadSellerOrderGoods(sellerUid, skup)
944 .refund(); 950 .refund();
945 951
946 model.setRefundGoodsMoneyFlag(refundGoodsMoneyFlag); 952 model.setRefundGoodsMoneyFlag(refundGoodsMoneyFlag);
@@ -52,6 +52,9 @@ import java.util.List; @@ -52,6 +52,9 @@ import java.util.List;
52 import java.util.Objects; 52 import java.util.Objects;
53 import java.util.concurrent.Callable; 53 import java.util.concurrent.Callable;
54 import java.util.concurrent.Future; 54 import java.util.concurrent.Future;
  55 +import java.util.concurrent.locks.Lock;
  56 +import java.util.function.Consumer;
  57 +import java.util.function.Supplier;
55 import java.util.stream.Collectors; 58 import java.util.stream.Collectors;
56 59
57 /** 60 /**
@@ -332,31 +335,48 @@ public class BuyerOrderCancelService { @@ -332,31 +335,48 @@ public class BuyerOrderCancelService {
332 } 335 }
333 BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode); 336 BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
334 if (buyerOrder == null){ 337 if (buyerOrder == null){
335 - logger.info("in cancelOverseasOrder buyer Order not exist, orderCode {} CutomsClearanceFailType {}", orderCode, failType); 338 + logger.warn("in cancelOverseasOrder buyer Order not exist, orderCode {} CutomsClearanceFailType {}", orderCode, failType);
336 return; 339 return;
337 } 340 }
338 Integer orderAttr = buyerOrder.getAttributes(); 341 Integer orderAttr = buyerOrder.getAttributes();
339 SkupTypeCodeSupport.CodeNode codeNode = SkupTypeCodeSupport.explain(orderAttr); 342 SkupTypeCodeSupport.CodeNode codeNode = SkupTypeCodeSupport.explain(orderAttr);
340 if (codeNode.getRegion() == RegionEnum.MAINLAND.getCode()){ 343 if (codeNode.getRegion() == RegionEnum.MAINLAND.getCode()){
341 - logger.info("in cancelOverseasOrder buyer Order is not overseas, Attr {}, orderCode {} CutomsClearanceFailType {}", 344 + logger.warn("in cancelOverseasOrder buyer Order is not overseas, Attr {}, orderCode {} CutomsClearanceFailType {}",
342 orderAttr, orderCode, failType); 345 orderAttr, orderCode, failType);
343 return; 346 return;
344 } 347 }
345 OrderStatus targetStatus = null; 348 OrderStatus targetStatus = null;
  349 + Consumer<BuyerOrder> consumer = null;
346 switch (failType){ 350 switch (failType){
347 case PLATFORM: 351 case PLATFORM:
348 targetStatus = OrderStatus.PLATFORM_BLOWN_CUSTOMS_CLEARANCE; 352 targetStatus = OrderStatus.PLATFORM_BLOWN_CUSTOMS_CLEARANCE;
349 - cancelOverseasOrderByPlatform(buyerOrder); 353 + consumer = (buyerOrder1) -> cancelOverseasOrderByPlatform(buyerOrder1);
350 break; 354 break;
351 case BUYER: 355 case BUYER:
352 targetStatus = OrderStatus.BUYER_BLOWN_CUSTOMS_CLEARANCE; 356 targetStatus = OrderStatus.BUYER_BLOWN_CUSTOMS_CLEARANCE;
353 - cancelOverseasOrderByBuyer(buyerOrder); 357 + consumer = (buyerOrder1) -> cancelOverseasOrderByBuyer(buyerOrder1);
354 break; 358 break;
355 } 359 }
356 360
357 - if (targetStatus != null){  
358 - orderStatusFlowService.addAsy(orderCode,targetStatus.getCode()); 361 +
  362 + if (targetStatus == null){
  363 + logger.warn("cancelOverseasOrder buyer Order targetStatus is null, Attr {}, orderCode {} CutomsClearanceFailType {}",
  364 + orderAttr, orderCode, failType);
  365 + return;
  366 + }
  367 + final OrderStatus expectedStatus = OrderStatus.WAITING_RECEIVE;
  368 + int buyerUid = buyerOrder.getUid();
  369 + boolean changeStatusFlag = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectedStatus.getCode(),
  370 + targetStatus.getCode(), DateUtil.getCurrentTimeSecond()) > 0;
  371 + if (!changeStatusFlag){
  372 + logger.warn("cancelOverseasOrder fail -> buyerOrderMapper.updateStatusByOrderCode, orderCode {}", orderCode);
  373 + return;
359 } 374 }
  375 + //
  376 + buyerOrder.setStatus(targetStatus.getCode());
  377 + consumer.accept(buyerOrder);
  378 + //
  379 + orderStatusFlowService.addAsy(orderCode,targetStatus.getCode());
360 } 380 }
361 381
362 /** 382 /**
@@ -380,6 +400,26 @@ public class BuyerOrderCancelService { @@ -380,6 +400,26 @@ public class BuyerOrderCancelService {
380 400
381 } 401 }
382 402
  403 + private void refundGoodsAmount(BuyerOrder buyerOrder,int skup, OrderStatus targetOrderStatus, BigDecimal leftBuyerMoney){
  404 + Integer buyerUid = buyerOrder.getUid();
  405 + Integer sellerUid = buyerOrder.getSellerUid();
  406 + Long orderCode = buyerOrder.getOrderCode();
  407 + //
  408 +
  409 + logger.info("cancelOverseasOrder refundGoodsAmount begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
  410 + buyerUid, orderCode, skup, leftBuyerMoney );
  411 +
  412 + new RefundGoodsMoneyHandler().loadLogger(logger)
  413 + .loadPaymentRequest(buyerUid,orderCode,buyerOrder.getPayment(), leftBuyerMoney)
  414 + .loadRefundAction(payRefundService::refund)
  415 + .loadTargetOrderStatus(targetOrderStatus)
  416 + .loadSellerOrderGoods(sellerUid, skup)
  417 + .refund();
  418 + logger.info("cancelOverseasOrder refundGoodsAmount after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
  419 + buyerUid, orderCode, skup, leftBuyerMoney );
  420 + }
  421 +
  422 +
383 class BuyerCancelAfterProcessTask implements Callable<PayRefundBo>{ 423 class BuyerCancelAfterProcessTask implements Callable<PayRefundBo>{
384 int buyerUid; 424 int buyerUid;
385 long orderCode; 425 long orderCode;
@@ -468,19 +508,22 @@ public class BuyerOrderCancelService { @@ -468,19 +508,22 @@ public class BuyerOrderCancelService {
468 void refundLeftOrderAmount(BuyerPenaltyCalResult bpcr, BuyerOrder buyerOrder){ 508 void refundLeftOrderAmount(BuyerPenaltyCalResult bpcr, BuyerOrder buyerOrder){
469 Integer sellerUid = buyerOrder.getSellerUid(); 509 Integer sellerUid = buyerOrder.getSellerUid();
470 BigDecimal leftBuyerMoney = bpcr.getLeftAmount(); 510 BigDecimal leftBuyerMoney = bpcr.getLeftAmount();
  511 + /*
471 BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder() 512 BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
472 .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode) 513 .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
473 .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY) 514 .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
474 .amount(leftBuyerMoney) 515 .amount(leftBuyerMoney)
475 .skup(skup); 516 .skup(skup);
  517 + */
476 logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}", 518 logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
477 buyerUid, orderCode, skup, leftBuyerMoney ); 519 buyerUid, orderCode, skup, leftBuyerMoney );
478 520
479 new RefundGoodsMoneyHandler().loadLogger(logger) 521 new RefundGoodsMoneyHandler().loadLogger(logger)
480 - .loadPaymentRequest(buyerUid,orderCode,leftBuyerMoney)  
481 - .loadBillLogEventBuilder(blebOfBuyer) 522 + .loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), leftBuyerMoney)
  523 + //.loadBillLogEventBuilder(blebOfBuyer)
482 .loadRefundAction(payRefundService::refund) 524 .loadRefundAction(payRefundService::refund)
483 .loadTargetOrderStatus(targetOrderStatus) 525 .loadTargetOrderStatus(targetOrderStatus)
  526 + .loadSellerOrderGoods(sellerUid, skup)
484 .refund(); 527 .refund();
485 logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}", 528 logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
486 buyerUid, orderCode, skup, leftBuyerMoney ); 529 buyerUid, orderCode, skup, leftBuyerMoney );
@@ -570,11 +570,7 @@ public class SellerOrderCancelService { @@ -570,11 +570,7 @@ public class SellerOrderCancelService {
570 //calculate all kind of amount of refund or transfer 570 //calculate all kind of amount of refund or transfer
571 BigDecimal goodsMoney = buyerOrder.getAmount(); 571 BigDecimal goodsMoney = buyerOrder.getAmount();
572 572
573 - BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()  
574 - .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(buyerOrderCode)  
575 - .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)  
576 - .amount(goodsMoney)  
577 - .skup(sellerOrder.getSkup()); 573 +
578 574
579 //分赃(分账) 有待考虑使用2比对 575 //分赃(分账) 有待考虑使用2比对
580 int skup = sellerOrder.getSkup(); 576 int skup = sellerOrder.getSkup();
@@ -625,12 +621,20 @@ public class SellerOrderCancelService { @@ -625,12 +621,20 @@ public class SellerOrderCancelService {
625 } else { 621 } else {
626 logger.error("can not find penalty result, uid = {}, skup={}", sellerOrder.getUid(), sellerOrder.getSkup()); 622 logger.error("can not find penalty result, uid = {}, skup={}", sellerOrder.getUid(), sellerOrder.getSkup());
627 } 623 }
  624 + /*
  625 + BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
  626 + .buyerUid(buyerUid).sellerUid(sellerUid).orderCode(buyerOrderCode)
  627 + .payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
  628 + .amount(goodsMoney)
  629 + .skup(sellerOrder.getSkup());
  630 + */
628 // 退买家货款 631 // 退买家货款
629 new RefundGoodsMoneyHandler().loadLogger(logger) 632 new RefundGoodsMoneyHandler().loadLogger(logger)
630 .loadTargetOrderStatus(targetBOStatus) 633 .loadTargetOrderStatus(targetBOStatus)
631 .loadRefundAction(payRefundService::refund) 634 .loadRefundAction(payRefundService::refund)
632 - .loadBillLogEventBuilder(bleb)  
633 - .loadPaymentRequest(buyerUid,buyerOrderCode,goodsMoney) 635 + //.loadBillLogEventBuilder(bleb)
  636 + .loadPaymentRequest(buyerUid,buyerOrderCode,buyerOrder.getPayment(), goodsMoney)
  637 + .loadSellerOrderGoods(sellerUid, skup)
634 .refund(); 638 .refund();
635 //异步 639 //异步
636 //消息通知 640 //消息通知