Authored by LUOXC

refactor

... ... @@ -42,6 +42,7 @@ import com.yohoufo.order.service.proxy.*;
import com.yohoufo.order.service.seller.setting.SellerService;
import com.yohoufo.order.service.seller.support.SkupTypeCodeSupport;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.NamedThreadFactory;
import com.yohoufo.order.utils.OrderAssist;
import com.yohoufo.order.utils.PaymentHelper;
import lombok.Builder;
... ... @@ -59,8 +60,7 @@ import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
... ... @@ -69,6 +69,10 @@ import java.util.stream.Collectors;
*/
@Service
public class BuyerOrderCancelService {
private ExecutorService executorService = new ThreadPoolExecutor(4, 10,
60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), NamedThreadFactory.newThreadFactory("buyer-order-cancel"));
private Logger logger = LoggerUtils.getOrderCloseLogger();
@Autowired
... ... @@ -399,6 +403,7 @@ public class BuyerOrderCancelService {
logger.warn("cancelOverseasOrder fail -> buyerOrderMapper.updateStatusByOrderCode, orderCode {}", orderCode);
return;
}
saveFailRecord(buyerUid, orderCode, failReason);
int sellerUid = buyerOrder.getSellerUid();
... ... @@ -412,39 +417,49 @@ public class BuyerOrderCancelService {
ErpBuyerOrderEvent event = new ErpBuyerOrderEvent(buyerUid);
EventBusPublisher.publishEvent(event);
BigDecimal leftGoodsMoney = buyerOrder.getAmount();
refundGoodsAmount(buyerOrder, targetStatus, consumer, needCompensateCoupon);
BuyerOrderGoods pbog = buyerOrderGoodsMapper.selectOnlyByOrderCode(orderCode);
Integer skup = pbog.getSkup();
//
buyerOrder.setStatus(targetStatus.getCode());
RefundGoodsAmoutNode rgaNode = RefundGoodsAmoutNode.builder()
.buyerOrder(buyerOrder)
.skup(skup)
.targetOrderStatus(targetStatus)
.leftBuyerMoney(leftGoodsMoney)
.needCompensateCoupon(needCompensateCoupon)
.build();
//
consumer.accept(rgaNode);
asyncRefundCoupon(buyerOrder.getUid(), buyerOrder.getOrderCode(), BuyerRefundCouponEvent.BizCase.PLATFORM_BLOWN_CUSTOMS_CLEARANCE);
//
orderStatusFlowService.addAsy(orderCode,targetStatus.getCode());
}
private int saveFailRecord(int uid, long orderCode, String failReason){
BuyerOrderMeta record = new BuyerOrderMeta();
record.setOrderCode(orderCode);
record.setUid(uid);
record.setMetaKey(MetaKey.CUSTOMS_CLEARANCE);
CustomsClearanceResult ccr = CustomsClearanceResult.builder()
.type(CustomsClearanceResultType.fail.getCode())
.failReason(failReason)
.build();
record.setMetaValue(JSONObject.toJSONString(ccr));
return buyerOrderMetaMapper.insert(record);
private void refundGoodsAmount(BuyerOrder buyerOrder, OrderStatus targetStatus, Consumer<RefundGoodsAmoutNode> consumer, boolean needCompensateCoupon) {
executorService.submit(()->{
BigDecimal leftGoodsMoney = buyerOrder.getAmount();
BuyerOrderGoods pbog = buyerOrderGoodsMapper.selectOnlyByOrderCode(buyerOrder.getOrderCode());
Integer skup = pbog.getSkup();
buyerOrder.setStatus(targetStatus.getCode());
RefundGoodsAmoutNode rgaNode = RefundGoodsAmoutNode.builder()
.buyerOrder(buyerOrder)
.skup(skup)
.targetOrderStatus(targetStatus)
.leftBuyerMoney(leftGoodsMoney)
.needCompensateCoupon(needCompensateCoupon)
.build();
//
consumer.accept(rgaNode);
});
}
private void saveFailRecord(int uid, long orderCode, String failReason){
executorService.submit(()-> {
BuyerOrderMeta record = new BuyerOrderMeta();
record.setOrderCode(orderCode);
record.setUid(uid);
record.setMetaKey(MetaKey.CUSTOMS_CLEARANCE);
CustomsClearanceResult ccr = CustomsClearanceResult.builder()
.type(CustomsClearanceResultType.fail.getCode())
.failReason(failReason)
.build();
record.setMetaValue(JSONObject.toJSONString(ccr));
return buyerOrderMetaMapper.insert(record);
});
}
/**
... ...