package com.fdkankan.ucenter.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.fdkankan.ucenter.common.RedisKeyUtil;
import com.fdkankan.ucenter.entity.*;
import com.fdkankan.ucenter.mq.vo.ScenePayStatusVo;
import com.fdkankan.ucenter.service.*;
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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

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



    @Autowired
    SceneCommonService sceneCommonService;

    @RabbitListener(
            queuesToDeclare = @Queue("${queue.scene.copy.result:ucenter-copy-scene-result}")
            ,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("copy-scene-result--messageId:{},msg:{}",messageId,msg);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);

            JSONObject jsonObject = JSONObject.parseObject(msg);
            String oldNum = jsonObject.getString("oldNum");
            String newNum = jsonObject.getString("newNum");

            sceneCommonService.copyResult(newNum);

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

    }

}
