|
|
package com.yohoufo.order.service.handler;
|
|
|
|
|
|
import com.github.rholder.retry.Retryer;
|
|
|
import com.github.rholder.retry.RetryerBuilder;
|
|
|
import com.github.rholder.retry.StopStrategies;
|
|
|
import com.github.rholder.retry.WaitStrategies;
|
|
|
import com.yohobuy.ufo.model.order.constants.DepotType;
|
|
|
import com.yohobuy.ufo.model.order.req.SellerDeliverToDepotReq;
|
|
|
import com.yohobuy.ufo.model.order.resp.FastDeliveryReq;
|
|
|
import com.yohoufo.common.alarm.CommonAlarmEventPublisher;
|
|
|
import com.yohoufo.common.alarm.IEventHandler;
|
|
|
import com.yohoufo.order.event.FastDeliveryChangeEvent;
|
|
|
import com.yohoufo.order.service.IExpressInfoService;
|
|
|
import com.yohoufo.order.service.proxy.FastDeliveryProxyService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
@Component
|
|
|
public class FastDeliveryChangeHandler implements IEventHandler<FastDeliveryChangeEvent> {
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
|
|
|
@Autowired
|
|
|
FastDeliveryProxyService fastDeliveryProxyService;
|
|
|
|
|
|
Retryer<Void> retryer = RetryerBuilder.<Void>newBuilder()
|
|
|
.retryIfRuntimeException()
|
|
|
.withStopStrategy(StopStrategies.stopAfterAttempt(2))
|
|
|
.withWaitStrategy(WaitStrategies.fixedWait(50, TimeUnit.MILLISECONDS)).build();
|
|
|
|
|
|
private ExecutorService executors = Executors.newFixedThreadPool(1);
|
|
|
|
|
|
@Autowired
|
|
|
private IExpressInfoService expressInfoService;
|
|
|
|
|
|
@Override
|
|
|
public void handle(FastDeliveryChangeEvent event) {
|
|
|
|
|
|
if (event.getOpt() == null || event.getFastDeliveryReq()== null){
|
|
|
logger.warn("req required, please check param");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!fastDeliveryProxyService.isFastDeliveryGoods(event.getFastDeliveryReq().getSkup())){
|
|
|
logger.info("skup is not fastDelivery, no need handle");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
switch (event.getOpt()){
|
|
|
case Delivery:
|
|
|
|
|
|
FastDeliveryReq fastDeliveryReq = event.getFastDeliveryReq();
|
|
|
|
|
|
// 生成虚拟单号
|
|
|
String wayBillCode = fastDeliveryProxyService.getVRWaybillCode(fastDeliveryReq.getOrderCode());
|
|
|
fastDeliveryReq.setWaybillCode(wayBillCode);
|
|
|
|
|
|
try{
|
|
|
retryer.call(()->{
|
|
|
fastDeliveryProxyService.delivery(fastDeliveryReq);
|
|
|
return null;
|
|
|
});
|
|
|
}catch (Exception e){
|
|
|
// 多次重试失败后,报警
|
|
|
|
|
|
CommonAlarmEventPublisher.publish("极速订单通知第三方发货", "fast.delivery.delivery", "sku:["+fastDeliveryReq.getSkup()+"]");
|
|
|
|
|
|
logger.warn("multi fast delivery delivery fail, alarm, e {}", e);
|
|
|
}
|
|
|
|
|
|
// 卖家自动发货
|
|
|
executors.submit(()->{
|
|
|
SellerDeliverToDepotReq sdtdReq = SellerDeliverToDepotReq.builder()
|
|
|
.sellerUid(fastDeliveryReq.getSellerUid())
|
|
|
.orderCode(fastDeliveryReq.getOrderCode())
|
|
|
.wayBillCode(wayBillCode)
|
|
|
.depotNum(DepotType.NJ.getCode())
|
|
|
.expressCompanyId(0)
|
|
|
.build();
|
|
|
expressInfoService.deliverToDepot(sdtdReq);
|
|
|
});
|
|
|
|
|
|
|
|
|
case Cancel:
|
|
|
|
|
|
try{
|
|
|
retryer.call(()->{
|
|
|
fastDeliveryProxyService.cancel(event.getFastDeliveryReq());
|
|
|
return null;
|
|
|
});
|
|
|
}catch (Exception e){
|
|
|
// 多次重试失败后,报警
|
|
|
|
|
|
CommonAlarmEventPublisher.publish("极速订单释放库存", "fast.delivery.cancel", "sku:["+event.getFastDeliveryReq().getSkup()+"]");
|
|
|
|
|
|
logger.warn("multi fast delivery cancel fail, alarm, e {}", e);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
logger.warn("no exist opt type, please check param");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|