|
@@ -9,17 +9,18 @@ import com.usky.cdi.service.util.SnowflakeIdGenerator;
|
|
|
import com.usky.cdi.service.vo.base.*;
|
|
import com.usky.cdi.service.vo.base.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.time.Instant;
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
import java.time.ZoneId;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Random;
|
|
|
|
|
|
|
+import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- *
|
|
|
|
|
* @author fyc
|
|
* @author fyc
|
|
|
* @email yuchuan.fu@chinausky.com
|
|
* @email yuchuan.fu@chinausky.com
|
|
|
* @date 2025/11/20
|
|
* @date 2025/11/20
|
|
@@ -37,10 +38,13 @@ public class IotDataTransferService {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DeviceDataQuery deviceDataQuery;
|
|
private DeviceDataQuery deviceDataQuery;
|
|
|
|
|
|
|
|
|
|
+ @Value("${config.engineeringID}")
|
|
|
|
|
+ private Long engineeringID;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public IotDataTransferService() {
|
|
public IotDataTransferService() {
|
|
|
// 使用默认的workerId和datacenterId,实际项目中可以从配置读取
|
|
// 使用默认的workerId和datacenterId,实际项目中可以从配置读取
|
|
|
- this.idGenerator = new SnowflakeIdGenerator(1L, 1L);
|
|
|
|
|
|
|
+ this.idGenerator = new SnowflakeIdGenerator(2L, 2L);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -63,28 +67,46 @@ public class IotDataTransferService {
|
|
|
*
|
|
*
|
|
|
* @return 是否发送成功
|
|
* @return 是否发送成功
|
|
|
*/
|
|
*/
|
|
|
- public boolean sendWaterLeak() {
|
|
|
|
|
|
|
+ public boolean sendWaterLeak(WaterLeakVO waterLeakVO) {
|
|
|
if (mqttGateway == null) {
|
|
if (mqttGateway == null) {
|
|
|
log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- List<JSONObject> deviceData = deviceDataQuery.getDeviceData(702);
|
|
|
|
|
|
|
+ String deviceUuid = waterLeakVO.getDeviceUuid() == null ? "" : waterLeakVO.getDeviceUuid();
|
|
|
|
|
+ List<JSONObject> deviceData = deviceDataQuery.getDeviceData(702, deviceUuid);
|
|
|
|
|
|
|
|
if (deviceData.isEmpty()) {
|
|
if (deviceData.isEmpty()) {
|
|
|
- log.warn("没有获取到水浸数据!");
|
|
|
|
|
|
|
+ log.warn("没有获取到水浸数据!deviceUuid:{}", deviceUuid);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (JSONObject deviceDataItem : deviceData) {
|
|
for (JSONObject deviceDataItem : deviceData) {
|
|
|
- Integer leachStatus = Integer.valueOf(deviceDataItem.getString("leach_status"));
|
|
|
|
|
|
|
+ // 增加空值判断
|
|
|
|
|
+ String leachStatusStr = deviceDataItem.getString("leach_status");
|
|
|
|
|
+ if (leachStatusStr == null || leachStatusStr.isEmpty()) {
|
|
|
|
|
+ log.warn("设备{}的leach_status为空", deviceDataItem.getString("device_id"));
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ Integer leachStatus;
|
|
|
|
|
+ try {
|
|
|
|
|
+ leachStatus = Integer.valueOf(leachStatusStr);
|
|
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
|
|
+ log.error("leach_status转换失败:{}", leachStatusStr, e);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
Long dataTime = deviceDataItem.getLong("time");
|
|
Long dataTime = deviceDataItem.getLong("time");
|
|
|
|
|
+ if (dataTime == null) {
|
|
|
|
|
+ log.warn("设备{}的time为空", deviceDataItem.getString("device_id"));
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
LocalDateTime dataEndTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(dataTime), ZoneId.systemDefault());
|
|
LocalDateTime dataEndTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(dataTime), ZoneId.systemDefault());
|
|
|
|
|
|
|
|
WaterLeakVO vo = new WaterLeakVO();
|
|
WaterLeakVO vo = new WaterLeakVO();
|
|
|
vo.setDataPacketID(generateDataPacketID());
|
|
vo.setDataPacketID(generateDataPacketID());
|
|
|
- vo.setSensorID(4399L);
|
|
|
|
|
- vo.setEngineeringID(9527L);
|
|
|
|
|
|
|
+ vo.setSensorID(deviceDataItem.getIntValue("device_id"));
|
|
|
|
|
+ vo.setEngineeringID(engineeringID);
|
|
|
vo.setPublishTime(getCurrentTime());
|
|
vo.setPublishTime(getCurrentTime());
|
|
|
vo.setSensorValue(leachStatus);
|
|
vo.setSensorValue(leachStatus);
|
|
|
vo.setDataEndTime(dataEndTime);
|
|
vo.setDataEndTime(dataEndTime);
|
|
@@ -104,89 +126,69 @@ public class IotDataTransferService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 发送温湿度及气体浓度数据(设备类型:701)
|
|
|
|
|
|
|
+ * 发送温湿度及气体浓度数据(设备类型:701,707-711)
|
|
|
* 包含: wd(温度), sd(湿度), o2(氧气), co(一氧化碳), co2(二氧化碳)
|
|
* 包含: wd(温度), sd(湿度), o2(氧气), co(一氧化碳), co2(二氧化碳)
|
|
|
*
|
|
*
|
|
|
* @return 是否发送成功
|
|
* @return 是否发送成功
|
|
|
*/
|
|
*/
|
|
|
- public boolean sendEnvData() {
|
|
|
|
|
|
|
+ public boolean sendEnvData(JSONObject jsonObject) {
|
|
|
if (mqttGateway == null) {
|
|
if (mqttGateway == null) {
|
|
|
log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- List<JSONObject> deviceData = deviceDataQuery.getDeviceData(701);
|
|
|
|
|
|
|
+ Integer deviceType = jsonObject.getInteger("deviceType");
|
|
|
|
|
+ String deviceUuid = jsonObject.getString("deviceUuid");
|
|
|
|
|
+
|
|
|
|
|
+ if (deviceType == null) {
|
|
|
|
|
+ log.error("deviceType不能为空");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<JSONObject> deviceData = deviceDataQuery.getDeviceData(deviceType, deviceUuid);
|
|
|
|
|
|
|
|
if (deviceData.isEmpty()) {
|
|
if (deviceData.isEmpty()) {
|
|
|
- log.warn("没有获取到空气质量数据!");
|
|
|
|
|
|
|
+ log.warn("没有获取到空气质量数据!deviceType:{}, deviceUuid:{}", deviceType, deviceUuid);
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (JSONObject deviceDataItem : deviceData) {
|
|
for (JSONObject deviceDataItem : deviceData) {
|
|
|
Long dataTime = deviceDataItem.getLong("time");
|
|
Long dataTime = deviceDataItem.getLong("time");
|
|
|
|
|
+ if (dataTime == null) {
|
|
|
|
|
+ log.warn("设备{}的time为空", deviceDataItem.getString("device_id"));
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
LocalDateTime dataEndTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(dataTime), ZoneId.systemDefault());
|
|
LocalDateTime dataEndTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(dataTime), ZoneId.systemDefault());
|
|
|
-
|
|
|
|
|
- // 发送温度
|
|
|
|
|
- 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);
|
|
|
|
|
|
|
+ Integer deviceId = deviceDataItem.getIntValue("device_id");
|
|
|
|
|
+
|
|
|
|
|
+ // 提取公共方法,减少代码冗余
|
|
|
|
|
+ switch (deviceType) {
|
|
|
|
|
+ case 701:
|
|
|
|
|
+ sendTempData(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ sendHumidityData(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ sendOxygenData(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ sendCoData(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ sendCo2Data(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 707:
|
|
|
|
|
+ sendTempData(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 708:
|
|
|
|
|
+ sendHumidityData(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 709:
|
|
|
|
|
+ sendOxygenData(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 710:
|
|
|
|
|
+ sendCo2Data(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 711:
|
|
|
|
|
+ sendCoData(deviceId, dataEndTime, deviceDataItem);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ log.warn("不支持的设备类型:{}", deviceType);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
return true;
|
|
return true;
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("发送环境数据失败", e);
|
|
log.error("发送环境数据失败", e);
|
|
@@ -205,6 +207,10 @@ public class IotDataTransferService {
|
|
|
log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
log.warn("MQTT Gateway未初始化,无法发送消息");
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (vo == null) {
|
|
|
|
|
+ log.error("PersonPresenceVO不能为空");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
try {
|
|
try {
|
|
|
if (vo.getDataPacketID() == null) {
|
|
if (vo.getDataPacketID() == null) {
|
|
|
vo.setDataPacketID(generateDataPacketID());
|
|
vo.setDataPacketID(generateDataPacketID());
|
|
@@ -212,6 +218,7 @@ public class IotDataTransferService {
|
|
|
if (vo.getPublishTime() == null) {
|
|
if (vo.getPublishTime() == null) {
|
|
|
vo.setPublishTime(getCurrentTime());
|
|
vo.setPublishTime(getCurrentTime());
|
|
|
}
|
|
}
|
|
|
|
|
+ vo.setEngineeringID(engineeringID); // 确保工程ID被设置
|
|
|
|
|
|
|
|
String json = JSON.toJSONString(vo);
|
|
String json = JSON.toJSONString(vo);
|
|
|
String topic = EnvMonitorMqttTopic.PERSON_PRESENCE.getTopic();
|
|
String topic = EnvMonitorMqttTopic.PERSON_PRESENCE.getTopic();
|
|
@@ -235,39 +242,34 @@ public class IotDataTransferService {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
try {
|
|
try {
|
|
|
- List<JSONObject> deviceData = deviceDataQuery.getDeviceData(704);
|
|
|
|
|
|
|
+ List<JSONObject> deviceData = deviceDataQuery.getDeviceData(704, "");
|
|
|
|
|
|
|
|
for (JSONObject deviceDataItem : deviceData) {
|
|
for (JSONObject deviceDataItem : deviceData) {
|
|
|
Long dataTime = deviceDataItem.getLong("time");
|
|
Long dataTime = deviceDataItem.getLong("time");
|
|
|
|
|
+ if (dataTime == null) {
|
|
|
|
|
+ log.warn("设备{}的time为空", deviceDataItem.getString("device_id"));
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
LocalDateTime dataEndTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(dataTime), ZoneId.systemDefault());
|
|
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();
|
|
ElectricityLoadVO vo = new ElectricityLoadVO();
|
|
|
vo.setDataPacketID(generateDataPacketID());
|
|
vo.setDataPacketID(generateDataPacketID());
|
|
|
- vo.setSensorID(new Random().nextLong());
|
|
|
|
|
- vo.setEngineeringID(new Random().nextLong());
|
|
|
|
|
|
|
+ vo.setSensorID(deviceDataItem.getIntValue("device_id"));
|
|
|
|
|
+ vo.setEngineeringID(engineeringID);
|
|
|
vo.setPublishTime(getCurrentTime());
|
|
vo.setPublishTime(getCurrentTime());
|
|
|
vo.setDataEndTime(dataEndTime);
|
|
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);
|
|
|
|
|
|
|
+ vo.setAVoltage(deviceDataItem.getFloat("voltage_a"));
|
|
|
|
|
+ vo.setBVoltage(deviceDataItem.getFloat("voltage_b"));
|
|
|
|
|
+ vo.setCVoltage(deviceDataItem.getFloat("voltage_c"));
|
|
|
|
|
+ vo.setAElectricity(deviceDataItem.getFloat("current_a"));
|
|
|
|
|
+ vo.setBElectricity(deviceDataItem.getFloat("current_b"));
|
|
|
|
|
+ vo.setCElectricity(deviceDataItem.getFloat("current_c"));
|
|
|
|
|
+ vo.setLine1TEMP(deviceDataItem.getFloat("temperature_a"));
|
|
|
|
|
+ vo.setLine2TEMP(deviceDataItem.getFloat("temperature_b"));
|
|
|
|
|
+ vo.setLine3TEMP(deviceDataItem.getFloat("temperature_c"));
|
|
|
|
|
+ vo.setLeakageCurrent(deviceDataItem.getFloat("current_residual"));
|
|
|
|
|
+ // 使用线程安全的随机数生成器
|
|
|
|
|
+ vo.setTotalPower(ThreadLocalRandom.current().nextFloat() * 10f);
|
|
|
|
|
|
|
|
String json = JSON.toJSONString(vo);
|
|
String json = JSON.toJSONString(vo);
|
|
|
String topic = EnvMonitorMqttTopic.ELECTRICITY_LOAD.getTopic();
|
|
String topic = EnvMonitorMqttTopic.ELECTRICITY_LOAD.getTopic();
|
|
@@ -281,5 +283,99 @@ public class IotDataTransferService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 提取公共发送方法,减少代码冗余
|
|
|
|
|
+ private void sendTempData(Integer deviceId, LocalDateTime dataEndTime, JSONObject deviceDataItem) {
|
|
|
|
|
+ Float value = deviceDataItem.getFloat("wd");
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ log.warn("设备{}的温度数据为空", deviceId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ TempVO tempVO = new TempVO();
|
|
|
|
|
+ tempVO.setDataPacketID(generateDataPacketID());
|
|
|
|
|
+ tempVO.setSensorID(deviceId);
|
|
|
|
|
+ tempVO.setEngineeringID(engineeringID);
|
|
|
|
|
+ tempVO.setPublishTime(getCurrentTime());
|
|
|
|
|
+ tempVO.setSensorValue(value);
|
|
|
|
|
+ tempVO.setDataEndTime(dataEndTime);
|
|
|
|
|
+ String json = JSON.toJSONString(tempVO);
|
|
|
|
|
+ String topic = EnvMonitorMqttTopic.TEMP.getTopic();
|
|
|
|
|
+ mqttGateway.sendToMqtt(topic, json);
|
|
|
|
|
+ log.info("发送温度信息,Topic: {}, Data: {}", topic, json);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ private void sendHumidityData(Integer deviceId, LocalDateTime dataEndTime, JSONObject deviceDataItem) {
|
|
|
|
|
+ Float value = deviceDataItem.getFloat("sd");
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ log.warn("设备{}的湿度数据为空", deviceId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ HumidityVO humidityVO = new HumidityVO();
|
|
|
|
|
+ humidityVO.setDataPacketID(generateDataPacketID());
|
|
|
|
|
+ humidityVO.setSensorID(deviceId);
|
|
|
|
|
+ humidityVO.setEngineeringID(engineeringID);
|
|
|
|
|
+ humidityVO.setPublishTime(getCurrentTime());
|
|
|
|
|
+ humidityVO.setSensorValue(value);
|
|
|
|
|
+ humidityVO.setDataEndTime(dataEndTime);
|
|
|
|
|
+ String json = JSON.toJSONString(humidityVO);
|
|
|
|
|
+ String topic = EnvMonitorMqttTopic.HUMIDITY.getTopic();
|
|
|
|
|
+ mqttGateway.sendToMqtt(topic, json);
|
|
|
|
|
+ log.info("发送湿度信息,Topic: {}, Data: {}", topic, json);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void sendOxygenData(Integer deviceId, LocalDateTime dataEndTime, JSONObject deviceDataItem) {
|
|
|
|
|
+ Float value = deviceDataItem.getFloat("o2");
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ log.warn("设备{}的氧气浓度数据为空", deviceId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ OxygenVO oxygenVO = new OxygenVO();
|
|
|
|
|
+ oxygenVO.setDataPacketID(generateDataPacketID());
|
|
|
|
|
+ oxygenVO.setSensorID(deviceId);
|
|
|
|
|
+ oxygenVO.setEngineeringID(engineeringID);
|
|
|
|
|
+ oxygenVO.setPublishTime(getCurrentTime());
|
|
|
|
|
+ oxygenVO.setSensorValue(value);
|
|
|
|
|
+ oxygenVO.setDataEndTime(dataEndTime);
|
|
|
|
|
+ String json = JSON.toJSONString(oxygenVO);
|
|
|
|
|
+ String topic = EnvMonitorMqttTopic.OXYGEN.getTopic();
|
|
|
|
|
+ mqttGateway.sendToMqtt(topic, json);
|
|
|
|
|
+ log.info("发送氧气浓度信息,Topic: {}, Data: {}", topic, json);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void sendCoData(Integer deviceId, LocalDateTime dataEndTime, JSONObject deviceDataItem) {
|
|
|
|
|
+ Float value = deviceDataItem.getFloat("co");
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ log.warn("设备{}的一氧化碳浓度数据为空", deviceId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ CoVO coVO = new CoVO();
|
|
|
|
|
+ coVO.setDataPacketID(generateDataPacketID());
|
|
|
|
|
+ coVO.setSensorID(deviceId);
|
|
|
|
|
+ coVO.setEngineeringID(engineeringID);
|
|
|
|
|
+ coVO.setPublishTime(getCurrentTime());
|
|
|
|
|
+ coVO.setSensorValue(value);
|
|
|
|
|
+ coVO.setDataEndTime(dataEndTime);
|
|
|
|
|
+ String json = JSON.toJSONString(coVO);
|
|
|
|
|
+ String topic = EnvMonitorMqttTopic.CO.getTopic();
|
|
|
|
|
+ mqttGateway.sendToMqtt(topic, json);
|
|
|
|
|
+ log.info("发送一氧化碳浓度信息,Topic: {}, Data: {}", topic, json);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void sendCo2Data(Integer deviceId, LocalDateTime dataEndTime, JSONObject deviceDataItem) {
|
|
|
|
|
+ Float value = deviceDataItem.getFloat("co2");
|
|
|
|
|
+ if (value == null) {
|
|
|
|
|
+ log.warn("设备{}的二氧化碳浓度数据为空", deviceId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ Co2VO co2VO = new Co2VO();
|
|
|
|
|
+ co2VO.setDataPacketID(generateDataPacketID());
|
|
|
|
|
+ co2VO.setSensorID(deviceId);
|
|
|
|
|
+ co2VO.setEngineeringID(engineeringID);
|
|
|
|
|
+ co2VO.setPublishTime(getCurrentTime());
|
|
|
|
|
+ co2VO.setSensorValue(value);
|
|
|
|
|
+ co2VO.setDataEndTime(dataEndTime);
|
|
|
|
|
+ String json = JSON.toJSONString(co2VO);
|
|
|
|
|
+ String topic = EnvMonitorMqttTopic.CO2.getTopic();
|
|
|
|
|
+ mqttGateway.sendToMqtt(topic, json);
|
|
|
|
|
+ log.info("发送二氧化碳浓度信息,Topic: {}, Data: {}", topic, json);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|