package com.tuoheng.admin.service.mqttpush.impl;

import com.alibaba.fastjson.JSONObject;
import com.tuoheng.admin.enums.AlarmTypeEnum;
import com.tuoheng.admin.service.mqttpush.IMqttPushService;
import com.tuoheng.admin.service.mqttService.send.MqttProviderConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: 吴彬
 * @CreateTime: 2023-06-12  11:22
 * @Description: MQTT 消息请求服务实现类
 * @Version: 1.0
 */
@Service
@Slf4j
public class MqttPushServiceImpl implements IMqttPushService {
    @Autowired
    private MqttProviderConfig client;

    @Override
    public void alarmSend(String edgId, int command,long time) {
        JSONObject message = new JSONObject();
        message.put("DeviceID",edgId);
        message.put("logID",time);
        message.put("type", AlarmTypeEnum.ALARM_CRITICAL.getType());
        message.put("Result",1);
        log.info("告警数据：{}，控制面板ID:{}，告警处理已回复",time,edgId);
        client.publish(2,false,"/v1/"+edgId+"/log",message.toJSONString());
    }
}
