package com.tzy.listener.mq;

import com.rabbitmq.client.Channel;
import com.tzy.common.constant.MqConstans;
import com.tzy.sportcard.group.service.ICardGroupGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;


@Slf4j
@Component
public class GoodsSyncConsumer {

	@Autowired
	private ICardGroupGoodsService cardGroupGoodsService;

	@RabbitHandler
	@RabbitListener(queuesToDeclare = @Queue(MqConstans.QUEUE_GROUP_GOODS_SYNC))
	public void groupFullConsumer(Long groupInfoId, Channel channel, Message message) throws IOException {
		log.info("同步组团中卡卡密,id:{}", groupInfoId);
		try {
			cardGroupGoodsService.syncGoods(groupInfoId);
		} catch (Exception e) {
			log.info("中卡记录同步异常,组团id:{}", groupInfoId, e);
		}
		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
	}


}
