|
|
package com.yohoufo.order.mq.consumer;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.core.rabbitmq.YhConsumer;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.message.sdk.service.ufo.UFOBidMessageService;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderStatus;
|
|
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.BuyerOrderMapper;
|
|
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrder;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.dal.product.ProductMapper;
|
|
|
import com.yohoufo.dal.product.model.Product;
|
|
|
import com.yohoufo.order.event.BuyerOrderUnpaidDelayReminderEvent;
|
|
|
import com.yohoufo.order.mq.TopicConstants;
|
|
|
import com.yohoufo.order.utils.LoggerUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static com.yoho.message.sdk.service.ufo.UFOBidMessageService.Scene.*;
|
|
|
|
|
|
@Component
|
|
|
public class BuyerOrderUnpaidReminderDelayMsgConsumer implements YhConsumer {
|
|
|
|
|
|
private Logger logger = LoggerUtils.getMqConsumerLogger();
|
|
|
|
|
|
@Autowired
|
|
|
private BuyerOrderMapper buyerOrderMapper;
|
|
|
|
|
|
@Autowired
|
|
|
protected BuyerOrderGoodsMapper buyerOrderGoodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
protected SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
protected ProductMapper productMapper;
|
|
|
|
|
|
@Autowired
|
|
|
protected UFOBidMessageService ufoBidMessageService;
|
|
|
|
|
|
|
|
|
public String getTopic() {
|
|
|
return TopicConstants.BUYER_ORDER_UNPAID_REMINDER;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void handleMessage(Object message) throws Exception {
|
|
|
logger.info("handle {} message, message is {}.", getTopic(), message);
|
|
|
try {
|
|
|
BuyerOrderUnpaidDelayReminderEvent event = JSONObject.parseObject(message.toString(), BuyerOrderUnpaidDelayReminderEvent.class);
|
|
|
BuyerOrder buyerOrder = findWaitingPayBuyerOrder(event.getUid(), event.getOrderCode());
|
|
|
if (buyerOrder != null) {
|
|
|
messageNotice(event.getRemainingHour(),buyerOrder);
|
|
|
}
|
|
|
logger.info("handle {} message success, message is {}.", getTopic(), message);
|
|
|
} catch (Exception ex) {
|
|
|
logger.warn("handle {} message fail, message is {} ", getTopic(), message, ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private BuyerOrder findWaitingPayBuyerOrder(int uid, long orderCode) {
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode, uid);
|
|
|
if (buyerOrder == null) {
|
|
|
logger.warn("check orderCode exist, uid is {}, orderCode is {}", uid, orderCode);
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
OrderStatus expectStatus = OrderStatus.getOrderStatus(buyerOrder.getStatus());
|
|
|
if (expectStatus != OrderStatus.WAITING_PAY) {
|
|
|
logger.info("[{}] order status is {}, not waiting_pay", expectStatus, orderCode);
|
|
|
return null;
|
|
|
}
|
|
|
return buyerOrder;
|
|
|
}
|
|
|
|
|
|
|
|
|
public void messageNotice(int remainingHour,BuyerOrder buyerOrder) {
|
|
|
SellerOrderGoods sellerOrderGoods = findSellerOrderGoods(buyerOrder);
|
|
|
String prdName = sellerOrderGoods.getProductName();
|
|
|
String sizeName = sellerOrderGoods.getSizeName();
|
|
|
Product product = findProduct(sellerOrderGoods);
|
|
|
String productCode = product.getProductCode();
|
|
|
|
|
|
Map<String, Object> parameters = new HashMap<>();
|
|
|
parameters.put("productName", prdName);
|
|
|
parameters.put("sizeName", sizeName);
|
|
|
parameters.put("productCode", productCode);
|
|
|
parameters.put("remainingHour", remainingHour);
|
|
|
parameters.put("orderCode", buyerOrder.getOrderCode());
|
|
|
ufoBidMessageService.sendMessage(String.valueOf(buyerOrder.getUid()), UFO_BUYER_BID_PAY_REMINDER, parameters);
|
|
|
}
|
|
|
|
|
|
protected SellerOrderGoods findSellerOrderGoods(BuyerOrder buyerOrder) {
|
|
|
BuyerOrderGoods buyerOrderGoods = buyerOrderGoodsMapper.selectByOrderCode(buyerOrder.getUid(), buyerOrder.getOrderCode());
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(buyerOrderGoods.getSkup());
|
|
|
return sellerOrderGoods;
|
|
|
}
|
|
|
|
|
|
protected Product findProduct(SellerOrderGoods sellerOrderGoods) {
|
|
|
Product product = productMapper.selectByPrimaryKey(sellerOrderGoods.getProductId());
|
|
|
return product;
|
|
|
}
|
|
|
} |
...
|
...
|
|