Authored by LUOXC

do refactor

... ... @@ -372,12 +372,11 @@ public class BuyerOrderCancelService {
}
@Data@Builder
private static class RefundGoodsAmoutNode{
private static class RefundGoodsAmountNode {
BuyerOrder buyerOrder;
int skup;
OrderStatus targetOrderStatus;
BigDecimal leftBuyerMoney;
boolean needCompensateCoupon;
}
... ... @@ -552,8 +551,7 @@ public class BuyerOrderCancelService {
String logTag;
private OrderStatus targetStatus;
private Consumer<RefundGoodsAmoutNode> consumer;
private boolean needCompensateCoupon;
private Consumer<RefundGoodsAmountNode> refundGoodsAmountConsumer;
private BuyerOrder buyerOrder;
CancelOverseasOrderModel(long orderCode, String failReason, CutomsClearanceFailType failType) {
... ... @@ -569,17 +567,15 @@ public class BuyerOrderCancelService {
throwServiceExceptionIf(orderCode <= 0L, "订单号不存在");
throwServiceExceptionIf(StringUtils.isBlank(failReason), "失败原因不能为空");
targetStatus = null;
consumer = null;
needCompensateCoupon = false;
refundGoodsAmountConsumer = null;
switch (failType) {
case PLATFORM:
targetStatus = OrderStatus.PLATFORM_BLOWN_CUSTOMS_CLEARANCE;
needCompensateCoupon = true;
consumer = (buyerOrder1) -> cancelOverseasOrderByPlatform(buyerOrder1);
refundGoodsAmountConsumer = refundGoodsAmountNode -> platformReason(refundGoodsAmountNode);
break;
case BUYER:
targetStatus = OrderStatus.BUYER_BLOWN_CUSTOMS_CLEARANCE;
consumer = (buyerOrder1) -> cancelOverseasOrderByBuyer(buyerOrder1);
refundGoodsAmountConsumer = refundGoodsAmountNode -> userReason(refundGoodsAmountNode);
break;
default:
throwServiceException("无效的目标状态");
... ... @@ -603,7 +599,7 @@ public class BuyerOrderCancelService {
int buyerUid = buyerOrder.getUid();
boolean changeStatusFlag = buyerOrderMapper.updateStatusByOrderCode(orderCode, buyerUid, expectedStatus.getCode(),
targetStatus.getCode(), DateUtil.getCurrentTimeSecond()) > 0;
if (!changeStatusFlag){
if (!changeStatusFlag) {
logger.info("{} changeStatus fail", logTag);
throwServiceException("订单状态变更失败");
}
... ... @@ -625,7 +621,7 @@ public class BuyerOrderCancelService {
asyncRefundCoupon(buyerOrder.getUid(), buyerOrder.getOrderCode(), BuyerRefundCouponEvent.BizCase.PLATFORM_BLOWN_CUSTOMS_CLEARANCE);
orderStatusFlowService.addAsy(orderCode,targetStatus.getCode());
orderStatusFlowService.addAsy(orderCode, targetStatus.getCode());
}
... ... @@ -639,15 +635,14 @@ public class BuyerOrderCancelService {
Integer skup = pbog.getSkup();
buyerOrder.setStatus(targetStatus.getCode());
RefundGoodsAmoutNode rgaNode = RefundGoodsAmoutNode.builder()
RefundGoodsAmountNode rgaNode = RefundGoodsAmountNode.builder()
.buyerOrder(buyerOrder)
.skup(skup)
.targetOrderStatus(targetStatus)
.leftBuyerMoney(leftGoodsMoney)
.needCompensateCoupon(needCompensateCoupon)
.build();
//
consumer.accept(rgaNode);
refundGoodsAmountConsumer.accept(rgaNode);
logger.info("{} asyncRefundGoodsAmount success", logTag);
});
... ... @@ -674,17 +669,15 @@ public class BuyerOrderCancelService {
* 货品平台自己吃了
* 买家钱退给买家
* 赔偿卖家ufo券 券金额还未定
* @param rgaNode
* @param refundGoodsAmountNode
*/
private void cancelOverseasOrderByPlatform(RefundGoodsAmoutNode rgaNode){
BuyerOrder buyerOrder = rgaNode.buyerOrder;
int skup = rgaNode.skup;
OrderStatus targetOrderStatus = rgaNode.targetOrderStatus;
BigDecimal leftBuyerMoney = rgaNode.leftBuyerMoney;
boolean needCompensateCoupon = rgaNode.needCompensateCoupon;
if (needCompensateCoupon){
compensateCoupon2Buyer(buyerOrder.getAmount(), buyerOrder.getUid(), buyerOrder.getOrderCode());
}
private void platformReason(RefundGoodsAmountNode refundGoodsAmountNode){
BuyerOrder buyerOrder = refundGoodsAmountNode.buyerOrder;
int skup = refundGoodsAmountNode.skup;
OrderStatus targetOrderStatus = refundGoodsAmountNode.targetOrderStatus;
BigDecimal leftBuyerMoney = refundGoodsAmountNode.leftBuyerMoney;
compensateCoupon2Buyer(buyerOrder.getAmount(), buyerOrder.getUid(), buyerOrder.getOrderCode());
refundGoodsAmount(buyerOrder, skup, targetOrderStatus, leftBuyerMoney);
}
... ... @@ -693,13 +686,14 @@ public class BuyerOrderCancelService {
* 买家原因失败
* 货品平台自己吃了
* 货款钱退给买家
* @param rgaNode
* @param refundGoodsAmountNode
*/
private void cancelOverseasOrderByBuyer(RefundGoodsAmoutNode rgaNode){
BuyerOrder buyerOrder = rgaNode.buyerOrder;
int skup = rgaNode.skup;
OrderStatus targetOrderStatus = rgaNode.targetOrderStatus;
BigDecimal leftBuyerMoney = rgaNode.leftBuyerMoney;
private void userReason(RefundGoodsAmountNode refundGoodsAmountNode){
BuyerOrder buyerOrder = refundGoodsAmountNode.buyerOrder;
int skup = refundGoodsAmountNode.skup;
OrderStatus targetOrderStatus = refundGoodsAmountNode.targetOrderStatus;
BigDecimal leftBuyerMoney = refundGoodsAmountNode.leftBuyerMoney;
refundGoodsAmount(buyerOrder, skup, targetOrderStatus, leftBuyerMoney);
//notice
... ...