|
|
@@ -6,6 +6,7 @@ import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
|
|
import com.usky.cdi.service.config.mqtt.MqttOutConfig;
|
|
|
import com.usky.cdi.service.util.SnowflakeIdGenerator;
|
|
|
import com.usky.cdi.service.vo.alarm.AlarmMessage1VO;
|
|
|
+import com.usky.cdi.service.vo.alarm.AlarmMessage2VO;
|
|
|
import com.usky.cdi.service.vo.alarm.AlarmMessageVO;
|
|
|
import com.usky.cdi.service.vo.base.FloorPlaneVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -41,6 +42,7 @@ public class AlarmDataTransferService {
|
|
|
// 使用默认的workerId和datacenterId,实际项目中可以从配置读取
|
|
|
this.idGenerator = new SnowflakeIdGenerator(1L, 1L);
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取当前时间字符串
|
|
|
*/
|
|
|
@@ -136,4 +138,26 @@ public class AlarmDataTransferService {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public boolean sendAlarmMessage2(AlarmMessage2VO vo) {
|
|
|
+ try {
|
|
|
+ if (vo.getDataPacketID() == null) {
|
|
|
+ vo.setDataPacketID(generateDataPacketID());
|
|
|
+ }
|
|
|
+ if (vo.getPublishTime() == null) {
|
|
|
+ vo.setPublishTime(getCurrentTime());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = (JSONObject) JSON.toJSON(vo);
|
|
|
+ String json = jsonObject.toJSONString();
|
|
|
+ System.out.println(json);
|
|
|
+ String topic = "alarm/message";
|
|
|
+ mqttGateway.sendToMqtt(topic, json);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送告警信息失败,AlarmID: {}", vo.getAlarmID(), e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|