Authored by chenchao

customs clear fail

... ... @@ -20,9 +20,17 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{
private Integer uid;
private Integer sellerUid;
private Long orderCode;
private BigDecimal goodsMoney;
private BigDecimal finalMoney;
private Integer payment;
private Integer skup;
private final static RefundCase refundCase = RefundCase.BUYER_GOODS_MONEY;
public RefundGoodsMoneyHandler loadTargetOrderStatus(OrderStatus targetOrderStatus){
... ... @@ -35,12 +43,13 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{
return this;
}
public RefundGoodsMoneyHandler loadPaymentRequest(Integer uid,Long orderCode,BigDecimal goodsMoney){
public RefundGoodsMoneyHandler loadPaymentRequest(Integer uid,Long orderCode,Integer payment, BigDecimal goodsMoney){
this.uid = uid;
this.orderCode = orderCode;
this.goodsMoney = goodsMoney;
this.finalMoney = goodsMoney;
this.payment = payment;
this.paymentRequest = PaymentRequest.builder().uid(uid)
.refundCase(RefundCase.BUYER_GOODS_MONEY)
.refundCase(refundCase)
.orderCode(orderCode).refundAmount(goodsMoney.doubleValue())
.build();
return this;
... ... @@ -51,13 +60,33 @@ public class RefundGoodsMoneyHandler extends AbsRefundOrderHandler{
return this;
}
public RefundGoodsMoneyHandler loadSellerOrderGoods(Integer sellerUid, Integer skup){
this.sellerUid = sellerUid;
this.skup = skup;
return this;
}
private BillLogEvent.BillLogEventBuilder buildBillLogEvent(){
BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
.buyerUid(uid).sellerUid(sellerUid).orderCode(orderCode)
.payType(payment).refundCase(refundCase)
.amount(finalMoney)
.skup(skup);
return blebOfBuyer;
}
public RefundGoodsMoneyHandler loadBillLogEventBuilder(BillLogEvent.BillLogEventBuilder bleb){
this.bleb = bleb;
return this;
}
@Override
public boolean refund(){
try {
if (bleb == null){
bleb = buildBillLogEvent();
}
refundConsumer.accept(paymentRequest, bleb);
return true;
}catch (Exception ex){
... ...
... ... @@ -610,16 +610,20 @@ public class AppraiseService {
//退买家的钱
BigDecimal goodsMoney = buyerOrder.getAmount();
/*
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler().loadPaymentRequest(buyerUid, orderCode, goodsMoney)
.loadBillLogEventBuilder(bleb)
*/
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
.loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
//.loadBillLogEventBuilder(bleb)
.loadTargetOrderStatus(targetStatus)
.loadRefundAction(payRefundService::refund)
.loadLogger(LOGGER)
.loadSellerOrderGoods(sellerUid, skup)
.refund();
if (!refundGoodsMoneyFlag) {
apiResponse.setCode(400);
... ... @@ -931,16 +935,18 @@ public class AppraiseService {
//退钱给买家
BigDecimal goodsMoney = buyerOrder.getAmount();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
/*BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(skup);
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler().loadPaymentRequest(buyerUid, orderCode, goodsMoney)
.loadBillLogEventBuilder(bleb)
.skup(skup);*/
boolean refundGoodsMoneyFlag = new RefundGoodsMoneyHandler()
.loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), goodsMoney)
//.loadBillLogEventBuilder(bleb)
.loadTargetOrderStatus(targetStatus)
.loadRefundAction(payRefundService::refund)
.loadLogger(LOGGER)
.loadSellerOrderGoods(sellerUid, skup)
.refund();
model.setRefundGoodsMoneyFlag(refundGoodsMoneyFlag);
... ...
... ... @@ -52,6 +52,9 @@ import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.locks.Lock;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
... ... @@ -332,31 +335,48 @@ public class BuyerOrderCancelService {
}
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if (buyerOrder == null){
logger.info("in cancelOverseasOrder buyer Order not exist, orderCode {} CutomsClearanceFailType {}", orderCode, failType);
logger.warn("in cancelOverseasOrder buyer Order not exist, orderCode {} CutomsClearanceFailType {}", orderCode, failType);
return;
}
Integer orderAttr = buyerOrder.getAttributes();
SkupTypeCodeSupport.CodeNode codeNode = SkupTypeCodeSupport.explain(orderAttr);
if (codeNode.getRegion() == RegionEnum.MAINLAND.getCode()){
logger.info("in cancelOverseasOrder buyer Order is not overseas, Attr {}, orderCode {} CutomsClearanceFailType {}",
logger.warn("in cancelOverseasOrder buyer Order is not overseas, Attr {}, orderCode {} CutomsClearanceFailType {}",
orderAttr, orderCode, failType);
return;
}
OrderStatus targetStatus = null;
Consumer<BuyerOrder> consumer = null;
switch (failType){
case PLATFORM:
targetStatus = OrderStatus.PLATFORM_BLOWN_CUSTOMS_CLEARANCE;
cancelOverseasOrderByPlatform(buyerOrder);
consumer = (buyerOrder1) -> cancelOverseasOrderByPlatform(buyerOrder1);
break;
case BUYER:
targetStatus = OrderStatus.BUYER_BLOWN_CUSTOMS_CLEARANCE;
cancelOverseasOrderByBuyer(buyerOrder);
consumer = (buyerOrder1) -> cancelOverseasOrderByBuyer(buyerOrder1);
break;
}
if (targetStatus != null){
orderStatusFlowService.addAsy(orderCode,targetStatus.getCode());
if (targetStatus == null){
logger.warn("cancelOverseasOrder buyer Order targetStatus is null, Attr {}, orderCode {} CutomsClearanceFailType {}",
orderAttr, orderCode, failType);
return;
}
final OrderStatus expectedStatus = OrderStatus.WAITING_RECEIVE;
int buyerUid = buyerOrder.getUid();
boolean changeStatusFlag = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectedStatus.getCode(),
targetStatus.getCode(), DateUtil.getCurrentTimeSecond()) > 0;
if (!changeStatusFlag){
logger.warn("cancelOverseasOrder fail -> buyerOrderMapper.updateStatusByOrderCode, orderCode {}", orderCode);
return;
}
//
buyerOrder.setStatus(targetStatus.getCode());
consumer.accept(buyerOrder);
//
orderStatusFlowService.addAsy(orderCode,targetStatus.getCode());
}
/**
... ... @@ -380,6 +400,26 @@ public class BuyerOrderCancelService {
}
private void refundGoodsAmount(BuyerOrder buyerOrder,int skup, OrderStatus targetOrderStatus, BigDecimal leftBuyerMoney){
Integer buyerUid = buyerOrder.getUid();
Integer sellerUid = buyerOrder.getSellerUid();
Long orderCode = buyerOrder.getOrderCode();
//
logger.info("cancelOverseasOrder refundGoodsAmount begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
buyerUid, orderCode, skup, leftBuyerMoney );
new RefundGoodsMoneyHandler().loadLogger(logger)
.loadPaymentRequest(buyerUid,orderCode,buyerOrder.getPayment(), leftBuyerMoney)
.loadRefundAction(payRefundService::refund)
.loadTargetOrderStatus(targetOrderStatus)
.loadSellerOrderGoods(sellerUid, skup)
.refund();
logger.info("cancelOverseasOrder refundGoodsAmount after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
buyerUid, orderCode, skup, leftBuyerMoney );
}
class BuyerCancelAfterProcessTask implements Callable<PayRefundBo>{
int buyerUid;
long orderCode;
... ... @@ -468,19 +508,22 @@ public class BuyerOrderCancelService {
void refundLeftOrderAmount(BuyerPenaltyCalResult bpcr, BuyerOrder buyerOrder){
Integer sellerUid = buyerOrder.getSellerUid();
BigDecimal leftBuyerMoney = bpcr.getLeftAmount();
/*
BillLogEvent.BillLogEventBuilder blebOfBuyer = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(orderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(leftBuyerMoney)
.skup(skup);
*/
logger.info("in BuyerCancelAfterProcessTask call begin payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
buyerUid, orderCode, skup, leftBuyerMoney );
new RefundGoodsMoneyHandler().loadLogger(logger)
.loadPaymentRequest(buyerUid,orderCode,leftBuyerMoney)
.loadBillLogEventBuilder(blebOfBuyer)
.loadPaymentRequest(buyerUid, orderCode, buyerOrder.getPayment(), leftBuyerMoney)
//.loadBillLogEventBuilder(blebOfBuyer)
.loadRefundAction(payRefundService::refund)
.loadTargetOrderStatus(targetOrderStatus)
.loadSellerOrderGoods(sellerUid, skup)
.refund();
logger.info("in BuyerCancelAfterProcessTask call after payRefundService.refund buyer, buyerUid {}, orderCode {}, skup {} refundAmount {}",
buyerUid, orderCode, skup, leftBuyerMoney );
... ...
... ... @@ -570,11 +570,7 @@ public class SellerOrderCancelService {
//calculate all kind of amount of refund or transfer
BigDecimal goodsMoney = buyerOrder.getAmount();
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(buyerOrderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(sellerOrder.getSkup());
//分赃(分账) 有待考虑使用2比对
int skup = sellerOrder.getSkup();
... ... @@ -625,12 +621,20 @@ public class SellerOrderCancelService {
} else {
logger.error("can not find penalty result, uid = {}, skup={}", sellerOrder.getUid(), sellerOrder.getSkup());
}
/*
BillLogEvent.BillLogEventBuilder bleb = BillLogEvent.builder()
.buyerUid(buyerUid).sellerUid(sellerUid).orderCode(buyerOrderCode)
.payType(buyerOrder.getPayment()).refundCase(RefundCase.BUYER_GOODS_MONEY)
.amount(goodsMoney)
.skup(sellerOrder.getSkup());
*/
// 退买家货款
new RefundGoodsMoneyHandler().loadLogger(logger)
.loadTargetOrderStatus(targetBOStatus)
.loadRefundAction(payRefundService::refund)
.loadBillLogEventBuilder(bleb)
.loadPaymentRequest(buyerUid,buyerOrderCode,goodsMoney)
//.loadBillLogEventBuilder(bleb)
.loadPaymentRequest(buyerUid,buyerOrderCode,buyerOrder.getPayment(), goodsMoney)
.loadSellerOrderGoods(sellerUid, skup)
.refund();
//异步
//消息通知
... ...