package com.fdkankan.ucenter.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.fdkankan.redis.util.RedisUtil;
import com.fdkankan.ucenter.common.RedisKeyUtil;
import com.fdkankan.ucenter.mq.vo.ScenePayStatusVo;
import com.fdkankan.ucenter.service.ISceneProService;
import com.fdkankan.ucenter.service.impl.SceneCommonService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
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 LaserSceneStatusConsumer {


    @Autowired
    SceneCommonService sceneCommonService;
    @RabbitListener(
            queuesToDeclare = @Queue("${queue.scene.laser.status:update-scene-status-ucent}")
            ,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("update-scene-status-ucent--messageId:{},msg:{}",messageId,msg);

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

            JSONObject jsonObject = JSONObject.parseObject(msg);
            String num = jsonObject.getString("num");
            Integer status = jsonObject.getInteger("status");
            if(status == 1){
                sceneCommonService.copyResult(num);
            }

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

    }

}
