package com.sw.mes.config.rabbit;

import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.sw.mes.outside.dto.RunTimeDto;
import com.sw.mes.outside.service.EapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
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;


@Slf4j
@Component
public class MqConsumer {

    @Autowired
    private EapService eapService;


    @RabbitHandler
    @RabbitListener(queues = "delayedQueue")
    public void process(String value, Message message, Channel channel) throws Exception {
        RunTimeDto runTimeDto = JSONObject.parseObject(value, RunTimeDto.class);
        log.info("delayedQueue：" + value);
        if("12小时未等径".equals(runTimeDto.getStepName())) {
            eapService.delayedData(runTimeDto);
        }
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);

    }

}
