Authored by wujiexiang

Merge branch 'dev-seller-order-stat-6.9.9' into test6.9.9

... ... @@ -23,6 +23,7 @@ import com.yohoufo.order.service.stats.impl.SellerOrderStatsConfiguration;
import com.yohoufo.order.service.stats.impl.SellerOrderStatsEntry;
import com.yohoufo.order.service.support.BuyerOrderMetaMapperSupport;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.RetryerUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -281,20 +282,30 @@ public class BuyerOrderChangeBusinessPostProcessor {
private class SellerOrderQuantityStatsBusinessProcessor extends BusinessProcessorAdapter {
@Override
public void appraiseSuccess(BusinessProcessorContext context) {
doProcess(context.buyerOrder);
try {
RetryerUtils.getRetryer().call(() -> doProcess(context.buyerOrder));
} catch (Exception e) {
logger.error("appraiseSuccess happened exception:{}", e);
//便于异常告警
throw new RuntimeException(e);
}
}
@Override
public void acceptFault(BusinessProcessorContext context) {
doProcess(context.buyerOrder);
try {
RetryerUtils.getRetryer().call(() -> doProcess(context.buyerOrder));
} catch (Exception e) {
logger.error("acceptFault happened exception:{}", e);
//便于异常告警
throw new RuntimeException(e);
}
}
private void doProcess(BuyerOrder buyerOrder) {
private boolean doProcess(BuyerOrder buyerOrder) {
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), buyerOrder.getOrderCode());
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(buyerOrderGoods.getSkup());
SellerOrderStatsEntry statsEntry = SellerOrderStatsEntry.builder()
.buyerUid(buyerOrder.getUid())
.buyerOrderCode(buyerOrder.getOrderCode())
... ... @@ -303,8 +314,8 @@ public class BuyerOrderChangeBusinessPostProcessor {
.build();
SellerOrderStatsConfiguration statsConfig = statsConfigurationManager.getStatsConfig(statsEntry);
statsConfigurationManager.getStatsProcessor(statsConfig.getStatsProcessorName()).accept(statsEntry, statsConfig);
return true;
}
}
... ...
package com.yohoufo.order.utils;
import com.github.rholder.retry.*;
import com.google.common.base.Predicates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
/**
* Created by jiexiang.wu on 2019/7/24.
*/
public class RetryerUtils {
private static final Logger logger = LoggerFactory.getLogger(RetryerUtils.class);
//重试
private static Retryer<Boolean> RETRYER = RetryerBuilder.<Boolean>newBuilder()
.retryIfException()
.retryIfResult(Predicates.equalTo(false))
//重调策略
.withWaitStrategy(WaitStrategies.fixedWait(200, TimeUnit.MILLISECONDS))
//尝试次数
.withStopStrategy(StopStrategies.stopAfterAttempt(3))
.withRetryListener(new RetryListener() {
@Override
public <V> void onRetry(Attempt<V> attempt) {
if (attempt.hasException()) {
logger.error("retry happened exception at attempt:{}", attempt.getAttemptNumber());
}
}
}).build();
public static Retryer getRetryer() {
return RETRYER;
}
}
... ...