package com.tzy.listener.mq;

import com.rabbitmq.client.Channel;
import com.tzy.common.constant.MqConstans;
import com.tzy.common.utils.bean.JSONTools;
import com.tzy.luckybag.dto.LuckyBagMQDTO;
import com.tzy.luckybag.service.IAppLiveLuckyBagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 超级福袋开奖
 */
@Slf4j
@Component
public class SuperLuckyBagConsumer {
    @Resource
    private IAppLiveLuckyBagService appLiveLuckyBagService;

    @RabbitHandler
    @RabbitListener(queues = MqConstans.QUEUE_SUPER_LUCK_BAG_EXPIRED)
    public void superBagConsumer(String content, Channel channel, Message message)throws IOException {
        log.info("超级福袋开奖 {}", content);
        LuckyBagMQDTO luckyBagMQDTO = JSONTools.jsonStr2obj(content, LuckyBagMQDTO.class);
        appLiveLuckyBagService.superBagLottery(luckyBagMQDTO);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
