package com.bz.rmcp.dap.mq;

import com.alibaba.fastjson.JSON;
import com.bz.rmcp.dap.config.RabbitMqConfig;
import com.bz.rmcp.dap.model.OfflineData;
import com.zcxk.rmcp.api.dto.product.MeasureDataDto;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author linqingwei
 * @date 2021-08-09 17:29
 */
@Component
public class MqMessageSender {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /*
     * @description 发送设备离线延时消息
     * @param msg
     * @return
     * @author linqingwei
     **/
    public void sendDelayMsg(OfflineData data){
        rabbitTemplate.convertAndSend(RabbitMqConfig.DELAY_EXCHANGE_NAME, RabbitMqConfig.DELAY_QUEUE_ROUTING_KEY, JSON.toJSONString(data));
    }

    /*
     * @description 向告警服务发送消息
     * @param data
     * @return
     * @author linqingwei
     **/
    public void sendDeviceDataMsg(MeasureDataDto data){
        rabbitTemplate.convertAndSend(RabbitMqConfig.DEVICE_DATA_EXCHANGE_NAME, RabbitMqConfig.DEVICE_DATA_QUEUE_NAME, JSON.toJSONString(data));
    }
}
