Selaa lähdekoodia

Merge branch 'fyc-cdi' of uskycloud/usky-modules into master

fuyuchuan 6 päivää sitten
vanhempi
commit
fd9c1dd954

+ 2 - 0
service-cdi/service-cdi-biz/src/main/java/com/usky/cdi/service/enums/MqttTopics.java

@@ -148,6 +148,8 @@ public final class MqttTopics {
                 return IotInfo.WATER_LEAK;
             case 714:
                 return IotInfo.DEVIATION;
+            case 719:
+                return IotInfo.PERSON;
             default:
                 return IotInfo.MONITORING_DATA;
         }

+ 8 - 3
service-cdi/service-cdi-biz/src/main/java/com/usky/cdi/service/impl/BaseDataTransferService.java

@@ -171,7 +171,7 @@ public class BaseDataTransferService {
                 vo.setPublishTime(getCurrentTime());
             }
 
-            String imagePath = "D://k2-04.jpg";
+            String imagePath = "D://BSP0-0103.jpg";
             // 将图片文件读取为字节数组
             byte[] imageBytes = Files.readAllBytes(Paths.get(imagePath));
 
@@ -210,7 +210,9 @@ public class BaseDataTransferService {
             log.info("发送楼层平面图信息,Topic: {}, FileID: {}, FileSize: {} bytes",
                     topic, vo.getFloorFileID(),
                     vo.getFloorFile() != null ? vo.getFloorFile().length : 0);
-            mqttGateway.sendToMqtt(topic, gson.toJson(map));
+
+            MqttConnectionTool.MqttGateway gateway = mqttConnectionTool.connectOrRefresh(vo.getUserName(), vo.getPassword());
+            gateway.sendToMqtt(topic, gson.toJson(map));
 
             return true;
         } catch (Exception e) {
@@ -245,9 +247,12 @@ public class BaseDataTransferService {
         try {
             Map<Integer, Integer> userIdToName = new HashMap<>();
             userIdToName.put(702, 31);
+            // 30:网络监控摄像机(可兼用平时摄像机)
+            // userIdToName.put(717, 30);
             // 20:人员统计-掩蔽人数双目统计摄像机
+            // userIdToName.put(719, 20);
             // 33:人员闯入-人员闯入监测传感器
-            userIdToName.put(703, 20);
+            userIdToName.put(703, 33);
             userIdToName.put(704, 11);
             userIdToName.put(705, 11);
             userIdToName.put(707, 19);

+ 21 - 5
service-cdi/service-cdi-biz/src/main/java/com/usky/cdi/service/impl/IotDataTransferService.java

@@ -2,6 +2,7 @@ package com.usky.cdi.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.nacos.shaded.com.google.gson.Gson;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.usky.cdi.domain.*;
@@ -387,7 +388,7 @@ public class IotDataTransferService {
     }
 
     /**
-     * 发送人员统计情况(703)
+     * 发送人员统计情况(703)-掩蔽人数
      *
      * @return 推送结果,包含成功数和失败数
      **/
@@ -425,8 +426,14 @@ public class IotDataTransferService {
                 headcountVO.setEngineeringID(transferVO.getEngineeringId());
                 headcountVO.setSensorValue(peopleCount);
                 // headcountVO.setSensorID(buildUnit.getId());
-                headcountVO.setDataEndTime(now.minusMinutes(ThreadLocalRandom.current().nextInt(1, 2)));
-                headcountVO.setPublishTime(now);
+
+                // 为每条数据生成秒级微差的时间
+                int secondsOffset = ThreadLocalRandom.current().nextInt(0, 60);
+                LocalDateTime dataEndTimeWithOffset = now.minusMinutes(ThreadLocalRandom.current().nextInt(1, 3)).plusSeconds(secondsOffset);
+                LocalDateTime publishTimeWithOffset = now.plusSeconds(ThreadLocalRandom.current().nextInt(0, 30));
+
+                headcountVO.setDataEndTime(dataEndTimeWithOffset);
+                headcountVO.setPublishTime(publishTimeWithOffset);
                 headcountVO.setUnitName(buildUnit.getUnitName());
                 headcountVO.setFloor(buildUnit.getFloor());
 
@@ -437,6 +444,8 @@ public class IotDataTransferService {
                             MqttTopics.IotInfo.PERSON.getDesc(),
                             transferVO.getUsername()
                     );
+                    // 添加2S延时
+                    Thread.sleep(2000);
                     result.put("successCount", result.get("successCount") + 1);
                     log.info("【人员统计】推送成功,单元:{},人数:{}", buildUnit.getUnitName(), peopleCount);
                 } catch (Exception e) {
@@ -1229,6 +1238,9 @@ public class IotDataTransferService {
                 case 716:
                     result = sendWaterLevel(transferVO);
                     break;
+                case 719:
+                    result = sendPersonCount(transferVO);
+                    break;
                 default:
                     log.debug("不支持的设备类型:{}", deviceType);
                     continue;
@@ -1346,7 +1358,10 @@ public class IotDataTransferService {
         } else if (raw instanceof Number) {
             dataTime = ((Number) raw).longValue();
         } else if (raw instanceof String) {
-            try { dataTime = Long.parseLong((String) raw); } catch (Exception ignored) {}
+            try {
+                dataTime = Long.parseLong((String) raw);
+            } catch (Exception ignored) {
+            }
         }
         if (dataTime == null) return null;
         return LocalDateTime.ofInstant(Instant.ofEpochMilli(dataTime), ZoneId.systemDefault());
@@ -1406,7 +1421,8 @@ public class IotDataTransferService {
             log.warn("平面图文件为空,FileID: {}", vo.getFloorFileID());
         }
 
-        return jsonObject.toJSONString();
+        Gson gson = new Gson();
+        return gson.toJson(jsonObject);
     }
 
     public void allData(Long engineeringId, String username, String password) {