|
|
@@ -8,17 +8,15 @@ import com.usky.cdi.service.util.DeviceDataQuery;
|
|
|
import com.usky.cdi.service.util.SnowflakeIdGenerator;
|
|
|
import com.usky.cdi.service.vo.base.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.tomcat.jni.Local;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
-import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
@@ -60,7 +58,7 @@ public class IotDataTransferService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 发送水浸状态
|
|
|
+ * 发送水浸状态(deviceType:702)
|
|
|
* Topic: iotInfo/flooded
|
|
|
*
|
|
|
* @return 是否发送成功
|
|
|
@@ -106,158 +104,92 @@ public class IotDataTransferService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 发送温度
|
|
|
- * Topic: iotInfo/temp
|
|
|
+ * 发送温湿度及气体浓度数据(设备类型:701)
|
|
|
+ * 包含: wd(温度), sd(湿度), o2(氧气), co(一氧化碳), co2(二氧化碳)
|
|
|
*
|
|
|
- * @param vo 温度信息
|
|
|
* @return 是否发送成功
|
|
|
*/
|
|
|
- public boolean sendTemp(TempVO vo) {
|
|
|
+ public boolean sendEnvData() {
|
|
|
if (mqttGateway == null) {
|
|
|
log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
return false;
|
|
|
}
|
|
|
try {
|
|
|
- if (vo.getDataPacketID() == null) {
|
|
|
- vo.setDataPacketID(generateDataPacketID());
|
|
|
- }
|
|
|
- if (vo.getPublishTime() == null) {
|
|
|
- vo.setPublishTime(getCurrentTime());
|
|
|
- }
|
|
|
-
|
|
|
- String json = JSON.toJSONString(vo);
|
|
|
- String topic = EnvMonitorMqttTopic.TEMP.getTopic();
|
|
|
-
|
|
|
- log.info("发送温度信息,Topic: {}, Data: {}", topic, json);
|
|
|
- mqttGateway.sendToMqtt(topic, json);
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("发送温度信息失败", e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送湿度
|
|
|
- * Topic: iotInfo/rh
|
|
|
- *
|
|
|
- * @param vo 湿度信息
|
|
|
- * @return 是否发送成功
|
|
|
- */
|
|
|
- public boolean batchSendHumidity(HumidityVO vo) {
|
|
|
- if (mqttGateway == null) {
|
|
|
- log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
- return false;
|
|
|
- }
|
|
|
- try {
|
|
|
- if (vo.getDataPacketID() == null) {
|
|
|
- vo.setDataPacketID(generateDataPacketID());
|
|
|
- }
|
|
|
- if (vo.getPublishTime() == null) {
|
|
|
- vo.setPublishTime(getCurrentTime());
|
|
|
- }
|
|
|
+ List<JSONObject> deviceData = deviceDataQuery.getDeviceData(701);
|
|
|
|
|
|
- String json = JSON.toJSONString(vo);
|
|
|
- String topic = EnvMonitorMqttTopic.HUMIDITY.getTopic();
|
|
|
- log.info("发送湿度信息,Topic: {}, Data: {}", topic, json);
|
|
|
- mqttGateway.sendToMqtt(topic, json);
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("发送湿度信息失败", e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送氧气浓度信息
|
|
|
- * Topic: iotInfo/o2
|
|
|
- *
|
|
|
- * @param vo 氧气浓度
|
|
|
- * @return 是否发送成功
|
|
|
- */
|
|
|
- public boolean sendOxygen(OxygenVO vo) {
|
|
|
- if (mqttGateway == null) {
|
|
|
- log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
- return false;
|
|
|
- }
|
|
|
- try {
|
|
|
- if (vo.getDataPacketID() == null) {
|
|
|
- vo.setDataPacketID(generateDataPacketID());
|
|
|
- }
|
|
|
- if (vo.getPublishTime() == null) {
|
|
|
- vo.setPublishTime(getCurrentTime());
|
|
|
- }
|
|
|
-
|
|
|
- String json = JSON.toJSONString(vo);
|
|
|
- String topic = EnvMonitorMqttTopic.OXYGEN.getTopic();
|
|
|
- log.info("发送氧气浓度信息,Topic: {}, Data: {}", topic, json);
|
|
|
- mqttGateway.sendToMqtt(topic, json);
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("发送氧气浓度信息失败", e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送二氧化碳浓度信息
|
|
|
- * Topic: iotInfo/co2
|
|
|
- *
|
|
|
- * @param vo 二氧化碳浓度
|
|
|
- * @return 是否发送成功
|
|
|
- */
|
|
|
- public boolean sendCarbonDioxide(Co2VO vo) {
|
|
|
- if (mqttGateway == null) {
|
|
|
- log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
- return false;
|
|
|
- }
|
|
|
- try {
|
|
|
- if (vo.getDataPacketID() == null) {
|
|
|
- vo.setDataPacketID(generateDataPacketID());
|
|
|
- }
|
|
|
- if (vo.getPublishTime() == null) {
|
|
|
- vo.setPublishTime(getCurrentTime());
|
|
|
+ if (deviceData.isEmpty()) {
|
|
|
+ log.warn("没有获取到空气质量数据!");
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- String json = JSON.toJSONString(vo);
|
|
|
- String topic = EnvMonitorMqttTopic.CO2.getTopic();
|
|
|
- log.info("发送二氧化碳浓度信息,Topic: {}, Data: {}", topic, json);
|
|
|
-
|
|
|
- mqttGateway.sendToMqtt(topic, json);
|
|
|
- return true;
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("发送二氧化碳浓度信息失败", e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
+ for (JSONObject deviceDataItem : deviceData) {
|
|
|
+ Long dataTime = deviceDataItem.getLong("time");
|
|
|
+ LocalDateTime dataEndTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(dataTime), ZoneId.systemDefault());
|
|
|
|
|
|
- /**
|
|
|
- * 发送一氧化碳浓度信息
|
|
|
- * Topic: iotInfo/co
|
|
|
- *
|
|
|
- * @param vo 一氧化碳浓度
|
|
|
- * @return 是否发送成功
|
|
|
- */
|
|
|
- public boolean sendCarbonMonoxide(CoVO vo) {
|
|
|
- if (mqttGateway == null) {
|
|
|
- log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
- return false;
|
|
|
- }
|
|
|
- try {
|
|
|
- if (vo.getDataPacketID() == null) {
|
|
|
- vo.setDataPacketID(generateDataPacketID());
|
|
|
- }
|
|
|
- if (vo.getPublishTime() == null) {
|
|
|
- vo.setPublishTime(getCurrentTime());
|
|
|
+ // 发送温度
|
|
|
+ TempVO tempVO = new TempVO();
|
|
|
+ tempVO.setDataPacketID(generateDataPacketID());
|
|
|
+ tempVO.setSensorID(4399L);
|
|
|
+ tempVO.setEngineeringID(9527L);
|
|
|
+ tempVO.setPublishTime(getCurrentTime());
|
|
|
+ tempVO.setSensorValue(deviceDataItem.getFloat("wd"));
|
|
|
+ tempVO.setDataEndTime(dataEndTime);
|
|
|
+ String tempJson = JSON.toJSONString(tempVO);
|
|
|
+ mqttGateway.sendToMqtt(EnvMonitorMqttTopic.TEMP.getTopic(), tempJson);
|
|
|
+ log.info("发送温度信息,Topic: {}, Data: {}", EnvMonitorMqttTopic.TEMP.getTopic(), tempJson);
|
|
|
+
|
|
|
+ // 发送湿度
|
|
|
+ HumidityVO humidityVO = new HumidityVO();
|
|
|
+ humidityVO.setDataPacketID(generateDataPacketID());
|
|
|
+ humidityVO.setSensorID(4399L);
|
|
|
+ humidityVO.setEngineeringID(9527L);
|
|
|
+ humidityVO.setPublishTime(getCurrentTime());
|
|
|
+ humidityVO.setSensorValue(deviceDataItem.getFloat("sd"));
|
|
|
+ humidityVO.setDataEndTime(dataEndTime);
|
|
|
+ String humidityJson = JSON.toJSONString(humidityVO);
|
|
|
+ mqttGateway.sendToMqtt(EnvMonitorMqttTopic.HUMIDITY.getTopic(), humidityJson);
|
|
|
+ log.info("发送湿度信息,Topic: {}, Data: {}", EnvMonitorMqttTopic.HUMIDITY.getTopic(), humidityJson);
|
|
|
+
|
|
|
+ // 发送氧气浓度
|
|
|
+ OxygenVO oxygenVO = new OxygenVO();
|
|
|
+ oxygenVO.setDataPacketID(generateDataPacketID());
|
|
|
+ oxygenVO.setSensorID(4399L);
|
|
|
+ oxygenVO.setEngineeringID(9527L);
|
|
|
+ oxygenVO.setPublishTime(getCurrentTime());
|
|
|
+ oxygenVO.setSensorValue(deviceDataItem.getFloat("o2"));
|
|
|
+ oxygenVO.setDataEndTime(dataEndTime);
|
|
|
+ String oxygenJson = JSON.toJSONString(oxygenVO);
|
|
|
+ mqttGateway.sendToMqtt(EnvMonitorMqttTopic.OXYGEN.getTopic(), oxygenJson);
|
|
|
+ log.info("发送氧气浓度信息,Topic: {}, Data: {}", EnvMonitorMqttTopic.OXYGEN.getTopic(), oxygenJson);
|
|
|
+
|
|
|
+ // 发送一氧化碳浓度
|
|
|
+ CoVO coVO = new CoVO();
|
|
|
+ coVO.setDataPacketID(generateDataPacketID());
|
|
|
+ coVO.setSensorID(4399L);
|
|
|
+ coVO.setEngineeringID(9527L);
|
|
|
+ coVO.setPublishTime(getCurrentTime());
|
|
|
+ coVO.setSensorValue(deviceDataItem.getFloat("co"));
|
|
|
+ coVO.setDataEndTime(dataEndTime);
|
|
|
+ String coJson = JSON.toJSONString(coVO);
|
|
|
+ mqttGateway.sendToMqtt(EnvMonitorMqttTopic.CO.getTopic(), coJson);
|
|
|
+ log.info("发送一氧化碳浓度信息,Topic: {}, Data: {}", EnvMonitorMqttTopic.CO.getTopic(), coJson);
|
|
|
+
|
|
|
+ // 发送二氧化碳浓度
|
|
|
+ Co2VO co2VO = new Co2VO();
|
|
|
+ co2VO.setDataPacketID(generateDataPacketID());
|
|
|
+ co2VO.setSensorID(4399L);
|
|
|
+ co2VO.setEngineeringID(9527L);
|
|
|
+ co2VO.setPublishTime(getCurrentTime());
|
|
|
+ co2VO.setSensorValue(deviceDataItem.getFloat("co2"));
|
|
|
+ co2VO.setDataEndTime(dataEndTime);
|
|
|
+ String co2Json = JSON.toJSONString(co2VO);
|
|
|
+ mqttGateway.sendToMqtt(EnvMonitorMqttTopic.CO2.getTopic(), co2Json);
|
|
|
+ log.info("发送二氧化碳浓度信息,Topic: {}, Data: {}", EnvMonitorMqttTopic.CO2.getTopic(), co2Json);
|
|
|
}
|
|
|
|
|
|
- String json = JSON.toJSONString(vo);
|
|
|
- String topic = EnvMonitorMqttTopic.CO.getTopic();
|
|
|
- log.info("发送一氧化碳浓度信息,Topic: {}, Data: {}", topic, json);
|
|
|
- mqttGateway.sendToMqtt(topic, json);
|
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("发送一氧化碳浓度信息失败", e);
|
|
|
+ log.error("发送环境数据失败", e);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -295,28 +227,54 @@ public class IotDataTransferService {
|
|
|
/**
|
|
|
* 发送人防用电负荷情况
|
|
|
*
|
|
|
- * @param vo 防人电用负荷
|
|
|
* @return 是否发送成功
|
|
|
**/
|
|
|
- public boolean sendElectricityLoad(ElectricityLoadVO vo) {
|
|
|
+ public boolean sendElectricityLoad() {
|
|
|
if (mqttGateway == null) {
|
|
|
log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
return false;
|
|
|
}
|
|
|
try {
|
|
|
- if (vo.getDataPacketID() == null) {
|
|
|
+ List<JSONObject> deviceData = deviceDataQuery.getDeviceData(704);
|
|
|
+
|
|
|
+ for (JSONObject deviceDataItem : deviceData) {
|
|
|
+ Long dataTime = deviceDataItem.getLong("time");
|
|
|
+ LocalDateTime dataEndTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(dataTime), ZoneId.systemDefault());
|
|
|
+ Integer voltageA = deviceDataItem.getInteger("voltage_a");
|
|
|
+ Integer voltageB = deviceDataItem.getInteger("voltage_b");
|
|
|
+ Integer voltageC = deviceDataItem.getInteger("voltage_c");
|
|
|
+ Integer currentA = deviceDataItem.getInteger("current_a");
|
|
|
+ Integer currentB = deviceDataItem.getInteger("current_b");
|
|
|
+ Integer currentC = deviceDataItem.getInteger("current_c");
|
|
|
+ Integer temperatureA = deviceDataItem.getInteger("temperature_a");
|
|
|
+ Integer temperatureB = deviceDataItem.getInteger("temperature_b");
|
|
|
+ Integer temperatureC = deviceDataItem.getInteger("temperature_c");
|
|
|
+ Integer currentResidual = deviceDataItem.getInteger("current_residual");
|
|
|
+
|
|
|
+ ElectricityLoadVO vo = new ElectricityLoadVO();
|
|
|
vo.setDataPacketID(generateDataPacketID());
|
|
|
- }
|
|
|
- if (vo.getPublishTime() == null) {
|
|
|
+ vo.setSensorID(new Random().nextLong());
|
|
|
+ vo.setEngineeringID(new Random().nextLong());
|
|
|
vo.setPublishTime(getCurrentTime());
|
|
|
- }
|
|
|
+ vo.setDataEndTime(dataEndTime);
|
|
|
+ vo.setAVoltage(Float.valueOf(voltageA));
|
|
|
+ vo.setBVoltage(Float.valueOf(voltageB));
|
|
|
+ vo.setCVoltage(Float.valueOf(voltageC));
|
|
|
+ vo.setAElectricity(Float.valueOf(currentA));
|
|
|
+ vo.setBElectricity(Float.valueOf(currentB));
|
|
|
+ vo.setCElectricity(Float.valueOf(currentC));
|
|
|
+ vo.setLine1TEMP(Float.valueOf(temperatureA));
|
|
|
+ vo.setLine2TEMP(Float.valueOf(temperatureB));
|
|
|
+ vo.setLine3TEMP(Float.valueOf(temperatureC));
|
|
|
+ vo.setLeakageCurrent(Float.valueOf(currentResidual));
|
|
|
+ vo.setTotalPower(new Random().nextFloat() * 1000F);
|
|
|
|
|
|
- String json = JSON.toJSONString(vo);
|
|
|
- String topic = EnvMonitorMqttTopic.ELECTRICITY_LOAD.getTopic();
|
|
|
- log.info("发送人防用电负荷情况,Topic: {}, Data: {}", topic, json);
|
|
|
- mqttGateway.sendToMqtt(topic, json);
|
|
|
+ String json = JSON.toJSONString(vo);
|
|
|
+ String topic = EnvMonitorMqttTopic.ELECTRICITY_LOAD.getTopic();
|
|
|
+ log.info("发送人防用电负荷情况,Topic: {}, Data: {}", topic, json);
|
|
|
+ mqttGateway.sendToMqtt(topic, json);
|
|
|
+ }
|
|
|
return true;
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
log.error("发送人防用电负荷情况失败", e);
|
|
|
return false;
|