package com.huimv.eartag.producer;

import com.alibaba.fastjson.JSONObject;
import com.huimv.eartag.utils.Const;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Project : huimv.shiwan
 * @Package : com.huimv.biosafety.uface.controller
 * @Description : TODO
 * @Version : 1.0
 * @Author : ZhuoNing
 * @Create : 2020-12-25
 **/
@Component
public class DeviceProducer {
    @Autowired
    RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法

    //处理心跳数据
    public String sendHeartbeat(JSONObject dataJo) {
        Map map = new HashMap();
        map.put("heartbeat",dataJo.toString());
        rabbitTemplate.convertAndSend(Const.EXCHANGE_DEVICE, Const.ROUTING_KEY_DEVICE_HEARTBEAT, map);
        System.out.println("处理心跳 >>"+dataJo);
        return "ok";
    }

    //处理环境温度数据
    public String sendDeviceTemp(JSONObject dataJo) {
        Map map = new HashMap();
        map.put("deviceTemp",dataJo);
        rabbitTemplate.convertAndSend(Const.EXCHANGE_DEVICE, Const.ROUTING_KEY_DEVICE_TEMP, map);
        System.out.println("处理环境温度 >>"+dataJo);
        return "ok";
    }

    //处理耳标数据
    public String sendEartag(JSONObject dataJo) {
        Map map = new HashMap();
        map.put("eartag",dataJo);
        rabbitTemplate.convertAndSend(Const.EXCHANGE_EARTAG, Const.ROUTING_KEY_EARTAG, map);
        System.out.println("处理耳标数据 >>"+dataJo);
        return "ok";
    }
}
