Authored by qinchao

清关物流mq 消费:自动确认收货和 清关失败通知

... ... @@ -16,12 +16,20 @@ import com.yohoufo.dal.order.model.ExpressInfo;
import com.yohoufo.dal.order.model.ExpressRecord;
import com.yohoufo.order.model.bo.ErpExpressBo;
import com.yohoufo.order.mq.publisher.ConsumerExceptionPublisher;
import com.yohoufo.order.service.IBuyerOrderService;
import com.yohoufo.order.service.impl.BuyerOrderCancelService;
import com.yohoufo.order.utils.LoggerUtils;
import com.yohoufo.order.utils.PubThreadFactory;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@Component
public class ExpressInfoUpdateConsumer implements YhConsumer {
... ... @@ -31,6 +39,8 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
private final String topic = "ufo.order.updateExpressInfo";
private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), new PubThreadFactory("express-consumer-processor"));
@Autowired
private ExpressInfoMapper expressInfoMapper;
... ... @@ -43,6 +53,12 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
@Autowired
private BuyerOrderMapper buyerOrderMapper;
@Autowired
private IBuyerOrderService buyerOrderService;
@Autowired
private BuyerOrderCancelService buyerOrderCancelService;
public String getMessageTopic() {
return topic;
}
... ... @@ -141,25 +157,29 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
expressInfo.setState(state);
//清关失败和清关成功的物流信息,需要在OperateTransferCode记录下相应的code ,以便自动确认查询
boolean existClearFail=false;
if(ExpressInfoConstant.EXPRESS_CLEAR_SUCCESS.equals(state)){
//清关成功的纪录
expressInfo.setOperateTransferCode(EnumExpressDataOperateTransferCode.express_clear_success.getCode());
}else if(ExpressInfoConstant.EXPRESS_CLEAR_FAIL_CAUSE_PLATFORM.equals(state)){
//清关失败的记录
//TODO 平台原因清关失败的信息记录下来,需要告诉order,退费
expressInfo.setOperateTransferCode(EnumExpressDataOperateTransferCode.express_clear_fail_cause_platform.getCode());
existClearFail=true;
/*暂时注释掉,等香港仓上线,中通物流返回信息未定
final CutomsClearanceFailType failType=CutomsClearanceFailType.PLATFORM;
LOGGER.info("call order clear fail interface,orderCode {},uid {},waybillCode {},state {} ,failType {}", orderCode,uid,waybillCode,state,failType);
executorService.execute(() -> {
buyerOrderCancelService.cancelOverseasOrder(orderCode, failType);
LOGGER.info("call order clear fail interface end,orderCode {},uid {},waybillCode {},state {},failType {} ", orderCode,uid,waybillCode,state,failType);
});*/
}else if(ExpressInfoConstant.EXPRESS_CLEAR_FAIL_CAUSE_BUYER.equals(state)){
//清关失败的记录
//TODO 买家原因清关失败的信息记录下来,需要告诉order,退费
expressInfo.setOperateTransferCode(EnumExpressDataOperateTransferCode.express_clear_fail_cause_buyer.getCode());
existClearFail=true;
}
if(existClearFail){
//TODO 清关失败需要告诉order,更改订单状态,并退费
//异步通知order清关失败
LOGGER.info("exist express clear fail call,orderCode {},uid {},waybillCode {},state {} ", orderCode,uid,waybillCode,state);
/*暂时注释掉,等香港仓上线,中通物流返回信息未定
final CutomsClearanceFailType failType=CutomsClearanceFailType.BUYER;
LOGGER.info("call order clear fail interface,orderCode {},uid {},waybillCode {},state {} ,failType {}", orderCode,uid,waybillCode,state,failType);
executorService.execute(() -> {
buyerOrderCancelService.cancelOverseasOrder(orderCode, failType);
LOGGER.info("call order clear fail interface end,orderCode {},uid {},waybillCode {},state {},failType {} ", orderCode,uid,waybillCode,state,failType);
});*/
}
expressInfoMapper.insert(expressInfo);
... ... @@ -188,7 +208,16 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
if(expressType!=null&&EnumExpressType.EXPRESS_TYPE_2.getCode().intValue()==expressType.intValue()){
//调用确认收货接口 method=ufo.buyer.confirm
LOGGER.info("handle accept express,orderCode {},uid {},waybillCode {},state {} ", orderCode,uid,waybillCode,state);
/* 暂时注释掉,等香港仓开发上线
executorService.execute(() -> {
OrderRequest orderRequest = OrderRequest.builder()
.uid(uid)
.orderCode(orderCode)
.build();
buyerOrderService.confirm(orderRequest);
LOGGER.info("handle accept express end ,orderCode {},uid {},waybillCode {},state {} ", orderCode,uid,waybillCode,state);
});
*/
}
processExpressInfo( state, logisticsType, orderCode, waybillCode, acceptAddress, acceptRemark, createTime, uid, expressType);
}
... ...