Authored by chenchao

fix consumer bug

... ... @@ -32,7 +32,11 @@ public class DeliverNoticeEvent extends Event{
* 剩余发货时间
*/
private Integer minutesOfLeft;
/**
* 延时时间
* 分钟:为了契合延时队列的延时时间单位
*/
private Integer minutesOfDelay;
private Integer times;
... ...
package com.yohoufo.order.mq.consumer;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yoho.core.rabbitmq.YhConsumer;
import com.yohobuy.ufo.model.order.bo.IntervalBo;
import com.yohobuy.ufo.model.order.bo.TimeResult;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
... ... @@ -14,6 +17,7 @@ import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.event.DeliverNoticeEvent;
import com.yohoufo.order.model.dto.DTNode;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.service.impl.BuyerOrderAssistant;
import com.yohoufo.order.service.proxy.DeliveryMinutesService;
import com.yohoufo.order.service.proxy.SellerNoticeFacade;
import com.yohoufo.order.utils.LoggerUtils;
... ... @@ -21,6 +25,7 @@ import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects;
/**
... ... @@ -43,7 +48,7 @@ public class NotDeliverNoticeDelayMsgConsumer implements YhConsumer {
/**
* 当前通知的次数
*/
private static final int defaultTimes = 2;
private static final int defaultTimes = OrderConstant.SellerDeliverNotice.SECOND_TIME;
/**
* 单位 : 小时
*/
... ... @@ -54,8 +59,36 @@ public class NotDeliverNoticeDelayMsgConsumer implements YhConsumer {
@Autowired
private DeliveryMinutesService deliveryMinutesService;
@Autowired
private BuyerOrderAssistant buyerOrderAssistant;
/**
* 现货
* 预售
* 二手 全新瑕疵
* 现货寄存
* 寄存转现货
*/
private static final List<Integer> supportOrderAttributes = Lists.newArrayList(
OrderAttributes.COMMON_IN_STOCK.getCode(),
OrderAttributes.ADVANCE_SALE.getCode(),
OrderAttributes.FLAW.getCode(),
OrderAttributes.SECOND_HAND.getCode()
);
/**
*
* @param preparedData
* @return
*/
private boolean doNoticeAsLastTimeNecessary(BuyerOrderAssistant.PreparedData preparedData){
BuyerOrder pbo;
boolean isInstockDepositOrder = buyerOrderAssistant.isInstockDepositOrder(pbo=preparedData.getBuyerOrder(), preparedData.getSellerOrderGoods());
return supportOrderAttributes.contains(pbo.getAttributes()) || isInstockDepositOrder;
}
@Override
public void handleMessage(Object o) throws Exception {
public void handleMessage(Object o) {
final String topic = TopicConstants.ORDER_NOT_DELIVER_NOTICE;
LOGGER.info("in topic {}, msg {}", topic, o);
if (Objects.isNull(o)){
... ... @@ -69,7 +102,8 @@ public class NotDeliverNoticeDelayMsgConsumer implements YhConsumer {
LOGGER.warn("fail in {}, msg {}", topic, msg);
return;
}
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, buyerUid);
BuyerOrderAssistant.PreparedData preparedData = buyerOrderAssistant.prepare(orderCode);
final BuyerOrder buyerOrder = preparedData.getBuyerOrder();
if(OrderStatus.HAS_PAYED.getCode() == buyerOrder.getStatus().intValue()){
//之前没有这个属性,兼容老数据
final Integer currentTimes = msg.getTimes() == null ? defaultTimes : msg.getTimes();
... ... @@ -81,7 +115,7 @@ public class NotDeliverNoticeDelayMsgConsumer implements YhConsumer {
}
int leftMinutes = msg.getMinutesOfLeft() == null ? defaultLeftTime*60 : msg.getMinutesOfLeft();
//
if (intervalBo != null){
if (intervalBo != null && doNoticeAsLastTimeNecessary(preparedData)){
//
//离发货截止12小时提醒
DeliverNoticeEvent deliverNoticeEvent = DeliverNoticeEvent.builder()
... ... @@ -94,6 +128,7 @@ public class NotDeliverNoticeDelayMsgConsumer implements YhConsumer {
.orderCode(orderCode)
//important properties
.minutesOfLeft(intervalBo.getMinutesOfLeft())
.minutesOfDelay(intervalBo.getMinutesofDelay())
.times(intervalBo.getTimes())
.build();
EventBusPublisher.publishEvent(deliverNoticeEvent);
... ...
... ... @@ -9,6 +9,7 @@ import com.yoho.message.sdk.utils.DateUtils;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.common.*;
import com.yohobuy.ufo.model.order.constants.DepotType;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.order.req.SellerDeliverToDepotReq;
import com.yohoufo.common.alarm.EventBusPublisher;
... ... @@ -331,7 +332,10 @@ public class BuyerOrderPaymentService extends AbstractOrderPaymentService {
DeliverNoticeEvent deliverNoticeEvent = DeliverNoticeEvent.builder().skup(sellerOrderGoods.getId())
.sellerOrderGoods(sellerOrderGoods)
.orderAttributes(orderInfo.getAttributes())
.sellerUid(sellerUid).buyerUid(uid).prdName(sellerOrderGoods.getProductName()).orderCode(orderCode).build();
.sellerUid(sellerUid).buyerUid(uid)
.prdName(sellerOrderGoods.getProductName())
.times(OrderConstant.SellerDeliverNotice.SECOND_TIME)
.orderCode(orderCode).build();
EventBusPublisher.publishEvent(deliverNoticeEvent);
//香港仓->卖家21天不发货取消;
... ...
... ... @@ -2,19 +2,20 @@ package com.yohoufo.order.service.handler;
import com.google.common.eventbus.Subscribe;
import com.yohobuy.ufo.model.order.common.OrderAttributes;
import com.yohobuy.ufo.model.order.constants.OrderConstant;
import com.yohoufo.common.alarm.IEventHandler;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.order.event.DeliverNoticeEvent;
import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.mq.producer.TradeMqSender;
import com.yohoufo.order.service.proxy.DeliveryMinutesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* Created by chenchao on 2018/10/15.
*/
... ... @@ -43,9 +44,18 @@ public class DeliverNoticeAsyncHandler implements IEventHandler<DeliverNoticeEve
if (event.getOrderAttributes() == OrderAttributes.OVERSEAS_IN_STOCK.getCode()){
minutes = deliveryMinutesService.getDeliverOverSeasNoticeMinutes();
}else{
minutes = event.getMinutesOfLeft() == null
? deliveryMinutesService.getDeliverMinutesSecond(ts)
: event.getMinutesOfLeft();
int times = event.getTimes() == null ? OrderConstant.SellerDeliverNotice.SECOND_TIME : event.getTimes().intValue();
switch (times){
case OrderConstant.SellerDeliverNotice.SECOND_TIME:
minutes = deliveryMinutesService.getDeliverMinutesSecond(ts);
break;
case OrderConstant.SellerDeliverNotice.LAST_TIME:
minutes = Objects.isNull(event.getMinutesOfDelay()) ? deliveryMinutesService.getDeliverMinutesOfLastTime() :
event.getMinutesOfDelay();
break;
}
}
String topic = TopicConstants.ORDER_NOT_DELIVER_NOTICE;
... ...
... ... @@ -83,6 +83,11 @@ public class DeliveryMinutesService {
return (Integer) value;
}
public int getDeliverMinutesOfLastTime(){
return MINUTES_SELLER_DELIVERNOTICE_LASTTIME;
}
public int getDeliverMinutesSecond(int ts){
if(ts<getOnlineTime()){
return minutes_deliverNotice_second_old;
... ...