|
@@ -1091,7 +1091,7 @@ public class IotDataTransferService {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
|
|
|
|
- log.info("开始推送集水井水位数据,设备类型:{},设备数量:{},获取到的数据条数:{}",
|
|
|
|
|
|
|
+ log.info("开始推送【集水井水位】数据,设备类型:{},设备数量:{},获取到的数据条数:{}",
|
|
|
deviceType, totalDevices, deviceData.size());
|
|
deviceType, totalDevices, deviceData.size());
|
|
|
|
|
|
|
|
if (deviceData.isEmpty()) {
|
|
if (deviceData.isEmpty()) {
|
|
@@ -1154,6 +1154,92 @@ public class IotDataTransferService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 发送发电机蓄电池监测数据(720)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return 推送结果,包含成功数和失败数
|
|
|
|
|
+ **/
|
|
|
|
|
+ public Map<String, Integer> sendGeneratorMonitoring(IotDataTransferVO transferVO) {
|
|
|
|
|
+ Map<String, Integer> result = new HashMap<>();
|
|
|
|
|
+ result.put("successCount", 0);
|
|
|
|
|
+ result.put("failureCount", 0);
|
|
|
|
|
+
|
|
|
|
|
+ if (!validateMqttGateway(transferVO.getUsername())) {
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
|
|
+ long endTime;
|
|
|
|
|
+
|
|
|
|
|
+ List<JSONObject> deviceData = deviceDataQuery.getDeviceData(transferVO);
|
|
|
|
|
+ Integer deviceType = transferVO.getDeviceType();
|
|
|
|
|
+ Integer totalDevices = transferVO.getDevices().size();
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ log.info("开始推送【战时柴油发电机每日启动时长】数据,设备类型:{},设备数量:{},获取到的数据条数:{}",
|
|
|
|
|
+ deviceType, totalDevices, deviceData.size());
|
|
|
|
|
+
|
|
|
|
|
+ if (deviceData.isEmpty()) {
|
|
|
|
|
+ log.warn("没有获取到战时柴油发电机每日启动时长数据!设备类型:{}", deviceType);
|
|
|
|
|
+ result.put("failureCount", totalDevices);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Long engineeringId = transferVO.getEngineeringId();
|
|
|
|
|
+ for (JSONObject deviceDataItem : deviceData) {
|
|
|
|
|
+ LocalDateTime dataEndTime = parseDataTime(deviceDataItem);
|
|
|
|
|
+ if (dataEndTime == null) {
|
|
|
|
|
+ result.put("failureCount", result.get("failureCount") + 1);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ dataEndTime = addTimeOffset(dataEndTime);
|
|
|
|
|
+
|
|
|
|
|
+ Integer deviceId = deviceDataItem.getIntValue("device_id");
|
|
|
|
|
+ Integer startDuration = deviceDataItem.get("startDuration") == null ? 0 : deviceDataItem.getIntValue("startDuration");
|
|
|
|
|
+
|
|
|
|
|
+ GeneratorMonitoringVO vo = new GeneratorMonitoringVO();
|
|
|
|
|
+ vo.setDataPacketID(generateDataPacketID());
|
|
|
|
|
+ vo.setSensorID(deviceId);
|
|
|
|
|
+ vo.setEngineeringID(engineeringId);
|
|
|
|
|
+ vo.setPublishTime(getCurrentTime());
|
|
|
|
|
+ vo.setDataEndTime(dataEndTime);
|
|
|
|
|
+ vo.setSensorDate(dataEndTime.toLocalDate());
|
|
|
|
|
+ vo.setStartDuration(startDuration);
|
|
|
|
|
+ if (deviceDataItem.containsKey("batteryVoltage")) {
|
|
|
|
|
+ vo.setBatteryVoltage(deviceDataItem.getDouble("batteryVoltage"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ log.info("【战时柴油发电机每日启动时长】开始推送,设备ID:{},数据:{}", deviceId, JSON.toJSONString(vo));
|
|
|
|
|
+ sendMqttMessage(MqttTopics.IotInfo.ALTERNATOR_STARTUP_TIME.getTopic(), vo, MqttTopics.IotInfo.ALTERNATOR_STARTUP_TIME.getDesc(), transferVO.getUsername());
|
|
|
|
|
+ result.put("successCount", result.get("successCount") + 1);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.warn("设备{}的战时柴油发电机每日启动时长数据推送失败:{}", deviceId, e.getMessage());
|
|
|
|
|
+ result.put("failureCount", result.get("failureCount") + 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("战时柴油发电机每日启动时长数据推送完成,设备类型:{},成功:{},失败:{}",
|
|
|
|
|
+ deviceType, result.get("successCount"), result.get("failureCount"));
|
|
|
|
|
+
|
|
|
|
|
+ endTime = System.currentTimeMillis();
|
|
|
|
|
+ saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
|
|
+ result.get("successCount"), result.get("failureCount"),
|
|
|
|
|
+ totalDevices - result.get("successCount") - result.get("failureCount"), 1, SecurityUtils.getUsername());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("战时柴油发电机每日启动时长数据推送发生异常", e);
|
|
|
|
|
+ result.put("failureCount", transferVO.getDevices().size());
|
|
|
|
|
+ endTime = System.currentTimeMillis();
|
|
|
|
|
+ saveLog(transferVO, now, startTime, endTime, totalDevices,
|
|
|
|
|
+ result.get("successCount"), result.get("failureCount"),
|
|
|
|
|
+ totalDevices - result.get("successCount") - result.get("failureCount"), 0, SecurityUtils.getUsername());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 同步设备数据
|
|
* 同步设备数据
|
|
|
* @param tenantId 租户ID
|
|
* @param tenantId 租户ID
|
|
@@ -1247,6 +1333,7 @@ public class IotDataTransferService {
|
|
|
}
|
|
}
|
|
|
result = sendPersonPresence(transferVO);
|
|
result = sendPersonPresence(transferVO);
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case 705:
|
|
|
case 704:
|
|
case 704:
|
|
|
if (tenantId == 1205) {
|
|
if (tenantId == 1205) {
|
|
|
// 设置默认值,避免空指针
|
|
// 设置默认值,避免空指针
|
|
@@ -1271,6 +1358,9 @@ public class IotDataTransferService {
|
|
|
case 719:
|
|
case 719:
|
|
|
result = sendPersonCount(transferVO);
|
|
result = sendPersonCount(transferVO);
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case 720:
|
|
|
|
|
+ result = sendGeneratorMonitoring(transferVO);
|
|
|
|
|
+ break;
|
|
|
default:
|
|
default:
|
|
|
log.debug("不支持的设备类型:{}", deviceType);
|
|
log.debug("不支持的设备类型:{}", deviceType);
|
|
|
continue;
|
|
continue;
|
|
@@ -1428,8 +1518,7 @@ public class IotDataTransferService {
|
|
|
* 序列化楼层平面图VO(将 floorFile byte[] 转为 Base64 字符串)
|
|
* 序列化楼层平面图VO(将 floorFile byte[] 转为 Base64 字符串)
|
|
|
*/
|
|
*/
|
|
|
private String serializeFloorPlaneVO(com.usky.cdi.service.vo.info.FloorPlaneVO vo) {
|
|
private String serializeFloorPlaneVO(com.usky.cdi.service.vo.info.FloorPlaneVO vo) {
|
|
|
- com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ Map<String, Object> jsonObject = new HashMap<>();
|
|
|
jsonObject.put("dataPacketID", vo.getDataPacketID());
|
|
jsonObject.put("dataPacketID", vo.getDataPacketID());
|
|
|
jsonObject.put("engineeringID", vo.getEngineeringID());
|
|
jsonObject.put("engineeringID", vo.getEngineeringID());
|
|
|
jsonObject.put("floor", vo.getFloor());
|
|
jsonObject.put("floor", vo.getFloor());
|
|
@@ -1439,18 +1528,7 @@ public class IotDataTransferService {
|
|
|
jsonObject.put("filePixWidth", vo.getFilePixWidth());
|
|
jsonObject.put("filePixWidth", vo.getFilePixWidth());
|
|
|
jsonObject.put("filePixHeight", vo.getFilePixHeight());
|
|
jsonObject.put("filePixHeight", vo.getFilePixHeight());
|
|
|
jsonObject.put("publishTime", vo.getPublishTime());
|
|
jsonObject.put("publishTime", vo.getPublishTime());
|
|
|
-
|
|
|
|
|
- // 关键:将 byte[] 转为 Base64 字符串
|
|
|
|
|
- if (vo.getFloorFile() != null) {
|
|
|
|
|
- String base64File = java.util.Base64.getEncoder().encodeToString(vo.getFloorFile());
|
|
|
|
|
- jsonObject.put("floorFile", base64File);
|
|
|
|
|
- log.info("平面图文件转换Base64成功,FileID: {}, 原始大小: {} bytes, Base64长度: {}",
|
|
|
|
|
- vo.getFloorFileID(), vo.getFloorFile().length, base64File.length());
|
|
|
|
|
- } else {
|
|
|
|
|
- jsonObject.put("floorFile", "");
|
|
|
|
|
- log.warn("平面图文件为空,FileID: {}", vo.getFloorFileID());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ jsonObject.put("floorFile", vo.getFloorFile());
|
|
|
Gson gson = new Gson();
|
|
Gson gson = new Gson();
|
|
|
return gson.toJson(jsonObject);
|
|
return gson.toJson(jsonObject);
|
|
|
}
|
|
}
|