package com.fdkankan.ucenter.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.fdkankan.ucenter.entity.ScenePlus;
import com.fdkankan.ucenter.service.IScenePlusService;
import com.fdkankan.ucenter.service.ISceneProService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * 场景封存解封 mq
 */
@Slf4j
@Component
public class DeleteSceneConsumer {

    @Autowired
    ISceneProService sceneProService;
    @RabbitListener(
            queuesToDeclare = @Queue("${queue.scene.delete:delete-scene}")
            ,concurrency = "1"
    )
    public void consumerQueue(Channel channel, Message message)  {
        try {
            String messageId = message.getMessageProperties().getMessageId();
            String msg = new String(message.getBody(), StandardCharsets.UTF_8);
            log.info("delete-scene--messageId:{},msg:{}",messageId,msg);

            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

            JSONObject jsonObject = JSONObject.parseObject(msg);
            String num = jsonObject.getString("sceneNum");
            if(StringUtils.isNotBlank(num)){
                sceneProService.delete(num,null, null);
            }

        }catch (Exception e){
            log.info("delete-scene---消费失败",e);
        }

    }

}
