
package com.tmerclub.cloud.group.listener;

import com.tmerclub.cloud.common.order.bo.PayNotifyBO;
import com.tmerclub.cloud.common.order.constant.OrderType;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.group.service.GroupOrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 团购订单支付监听
 *
 * @author tmerclub
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.ORDER_NOTIFY_SERVICE_TOPIC, consumerGroup = RocketMqConstant.ORDER_NOTIFY_GROUP_GROUP)
public class OrderNotifyGroupConsumer implements RocketMQListener<PayNotifyBO> {

    private static final Logger LOG = LoggerFactory.getLogger(OrderNotifyGroupConsumer.class);

    @Autowired
    private GroupOrderService groupOrderService;

    /**
     * 通知团购订单已经支付
     */
    @Override
    public void onMessage(PayNotifyBO message) {
        if (!Objects.equals(message.getOrderType(), OrderType.GROUP.value())) {
            return;
        }
        LOG.info("通知团购订单已经支付... message: {}", Json.toJsonString(message));
        groupOrderService.payNotifyGroupOrder(message);
    }
}
