Authored by qinchao

多个订单对应一个物流单号2

package com.yohoufo.order.model.bo;
import lombok.Data;
import lombok.ToString;
/**
* erp 传递过来的物流信息bo
*/
@Data
@ToString
public class ErpExpressBo {
private int businessType ;
private String waybillCode ;
private int logisticsType ;
private String acceptAddress ;
private String acceptRemark ;
private int createTime ;
private int state ;
private int uid;
private long orderCode ;
}
... ...
... ... @@ -6,12 +6,11 @@ import com.google.common.collect.Lists;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yohoufo.common.constant.ExpressInfoConstant;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.ExpressInfoMapper;
import com.yohoufo.dal.order.ExpressRecordMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
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.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -38,10 +37,6 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
private ExpressRecordMapper expressRecordMapper;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
@Autowired
private ConsumerExceptionPublisher consumerExceptionPublisher;
public String getMessageTopic() {
... ... @@ -63,37 +58,27 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
}
private void updateExpressInfo(Object message) {
JSONObject jsonMsg = JSONObject.parseObject(message.toString());
if (!checkValidMessage(jsonMsg)) {
ErpExpressBo erpExpressBo = convertErpJsonToObject(message);
if (erpExpressBo==null||!checkValidMessage(erpExpressBo)) {
return;
}
int uid = jsonMsg.getIntValue("uid");
String waybillCode = erpExpressBo.getWaybillCode();
int logisticsType = erpExpressBo.getLogisticsType();
String acceptAddress = erpExpressBo.getAcceptAddress();
String acceptRemark = erpExpressBo.getAcceptRemark();
int createTime = erpExpressBo.getCreateTime();
int state = erpExpressBo.getState();
long orderCode = erpExpressBo.getOrderCode();
int uid = erpExpressBo.getUid();
if (uid == 0) {
LOGGER.info("handle express info update message, not give me a uid, message is {}.", message);
return;
}
long orderCode = jsonMsg.getLongValue("orderCode");
String waybillCode = jsonMsg.getString("waybillCode");
int logisticsType = jsonMsg.getIntValue("logisticsType");
int createTime = jsonMsg.getIntValue("createTime");
int state = jsonMsg.getIntValue("state");
String acceptAddress = jsonMsg.getString("acceptAddress");
String acceptRemark = jsonMsg.getString("acceptRemark");
/*
BuyerOrder buyerOrder = buyerOrderMapper.selectOnlyByOrderCode(orderCode);
if (buyerOrder == null){
LOGGER.warn("handle express info update message,getOrderInfo order not exist, orderCode is {}", orderCode);
//遇到这种情况,也记录物流信息
//throw new ServiceException(ServiceError.ORDER_NULL);
}
*/
//根据uid,orderCode,waybillCode查状态expressType
//初始的expressType
Byte initExpressType=0;
ExpressRecord firstExpressRecord = expressRecordMapper.queryExpressRecord(uid,orderCode,waybillCode);
... ... @@ -110,7 +95,7 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
// 正常订单,签收消息
if (state == ExpressInfoConstant.EXPRESS_STATUS_SIGN) {
handleAcceptExpress(jsonMsg,initExpressType.intValue());
handleAcceptExpress(erpExpressBo,initExpressType.intValue());
return;
}
... ... @@ -135,19 +120,40 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
expressInfoMapper.insert(expressInfo);
}
private boolean checkValidMessage(JSONObject jsonMsg) {
private ErpExpressBo convertErpJsonToObject(Object message) {
try{
JSONObject jsonMsg = JSONObject.parseObject(message.toString());
ErpExpressBo bo=new ErpExpressBo();
bo.setBusinessType(jsonMsg.getIntValue("businessType"));
bo.setWaybillCode(jsonMsg.getString("waybillCode"));
bo.setLogisticsType(jsonMsg.getIntValue("logisticsType"));
bo.setAcceptAddress(jsonMsg.getString("acceptAddress"));
bo.setAcceptRemark(jsonMsg.getString("acceptRemark"));
bo.setCreateTime(jsonMsg.getIntValue("createTime"));
bo.setState(jsonMsg.getIntValue("state"));
bo.setUid(jsonMsg.getIntValue("uid"));
bo.setOrderCode(jsonMsg.getLongValue("orderCode"));
return bo;
}catch (Exception e){
LOGGER.warn("convertErpJsonToObject express info message error,message is {}.", message);
return null;
}
}
private boolean checkValidMessage(ErpExpressBo erpExpressBo) {
boolean flag = true;
int smsType = jsonMsg.getIntValue("businessType");
int logisticsType = jsonMsg.getIntValue("logisticsType");
int state = jsonMsg.getIntValue("state");
long orderCode = jsonMsg.getLongValue("orderCode");
String waybillCode = jsonMsg.getString("waybillCode");
if (smsType < 1 || state < 0 || logisticsType < 0 || orderCode < 0) {
LOGGER.warn("invalid express info message,message is {}.", jsonMsg);
int businessType = erpExpressBo.getBusinessType();
int logisticsType = erpExpressBo.getLogisticsType();
int state = erpExpressBo.getState();
long orderCode = erpExpressBo.getOrderCode();
String waybillCode = erpExpressBo.getWaybillCode();
if (businessType < 1 || state < 0 || logisticsType < 0 || orderCode < 0) {
LOGGER.warn("invalid express info message,message is {}.", erpExpressBo);
flag = false;
}
if (logisticsType > 0 && StringUtils.isBlank(waybillCode)) {
LOGGER.warn("invalid express info message,message is {}.", jsonMsg);
LOGGER.warn("invalid express info message,message is {}.", erpExpressBo);
flag = false;
}
return flag;
... ... @@ -156,14 +162,15 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
/**
* 确认收货处理
*/
private void handleAcceptExpress(JSONObject jsonMsg,Integer expressType) {
int state = jsonMsg.getIntValue("state");
long orderCode = jsonMsg.getLongValue("orderCode");
int logisticsType = jsonMsg.getIntValue("logisticsType");
String waybillCode = jsonMsg.getString("waybillCode");
String acceptAddress = jsonMsg.getString("acceptAddress");
String acceptRemark = jsonMsg.getString("acceptRemark");
int uid = jsonMsg.getIntValue("uid");
private void handleAcceptExpress(ErpExpressBo erpExpressBo,Integer expressType) {
String waybillCode = erpExpressBo.getWaybillCode();
int logisticsType = erpExpressBo.getLogisticsType();
String acceptAddress = erpExpressBo.getAcceptAddress();
String acceptRemark = erpExpressBo.getAcceptRemark();
int state = erpExpressBo.getState();
long orderCode = erpExpressBo.getOrderCode();
int uid = erpExpressBo.getUid();
int createTime = DateUtil.getCurrentTimeSecond();
List<ExpressInfo> expressInfos = expressInfoMapper.selectByOrderCodeAndStatesAndUidAndExpressType(uid, orderCode, Lists.newArrayList(ExpressInfoConstant.EXPRESS_STATUS_SIGN), expressType);
... ...