package com.fdkankan.ucenter.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.fdkankan.ucenter.httpClient.vo.PayOrderVo;
import com.fdkankan.ucenter.mq.vo.ScenePayStatusVo;
import com.fdkankan.ucenter.pay.strategy.impl.DownloadOrderImpl;
import com.fdkankan.ucenter.pay.strategy.impl.EntityOrderImpl;
import com.fdkankan.ucenter.pay.strategy.impl.IncrementOrderImpl;
import com.fdkankan.ucenter.service.ISceneProService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringEscapeUtils;
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;
import java.util.Arrays;

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


    @Autowired
    ISceneProService sceneProService;

    @RabbitListener(
            queuesToDeclare = @Queue("${queue.scene.pay-status:scene-pay-status}")
            ,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("scene-pay-status-mq--messageId:{},msg:{}",messageId,msg);

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

            ScenePayStatusVo vo = JSONObject.parseObject(msg, ScenePayStatusVo.class);
            if(vo == null){
                return;
            }
            if(vo.getCameraId() != null){
                sceneProService.lockOrUnLockBySpace(vo.getCameraId());
            }

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

        }

    }

}
