TRX 1 سال پیش
والد
کامیت
a45429988c
13فایلهای تغییر یافته به همراه40 افزوده شده و 14 حذف شده
  1. 3 0
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/DeviceInfoAddParam.java
  2. 3 0
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/DeviceInfoRegistParam.java
  3. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/DeviceController.java
  4. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/GateWayController.java
  5. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/GateWayUserInfoController.java
  6. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/MqttInfoController.java
  7. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/OperationLogsController.java
  8. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/OperationMessageController.java
  9. 1 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dataConfig/DeviceConfig.java
  10. 3 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DeviceInfoService.java
  11. 2 4
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayInfoService.java
  12. 10 4
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/sync/DeviceSyncFullCardService.java
  13. 12 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/util/JMXUtil.java

+ 3 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/DeviceInfoAddParam.java

@@ -47,4 +47,7 @@ public class DeviceInfoAddParam extends SuperParam {
 
     @Schema(description = "设备类型")
     private String deviceCate;
+
+    @Schema(description = "心跳间隔,单位:秒")
+    private Long hbInterval = 30l;
 }

+ 3 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/DeviceInfoRegistParam.java

@@ -46,4 +46,7 @@ public class DeviceInfoRegistParam {
 
     @Schema(description = "设备类型")
     private String deviceCate;
+
+    @Schema(description = "心跳间隔,单位:秒")
+    private Long hbInterval = 30l;
 }

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/DeviceController.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/DeviceController.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.controller.hardware;
+package com.zhongshu.iot.server.core.controller.devices;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/GateWayController.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/GateWayController.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.controller.hardware;
+package com.zhongshu.iot.server.core.controller.devices;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/GateWayUserInfoController.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/GateWayUserInfoController.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.controller.hardware;
+package com.zhongshu.iot.server.core.controller.devices;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/MqttInfoController.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/MqttInfoController.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.controller.hardware;
+package com.zhongshu.iot.server.core.controller.devices;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/OperationLogsController.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/OperationLogsController.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.controller.hardware;
+package com.zhongshu.iot.server.core.controller.devices;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/OperationMessageController.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/devices/OperationMessageController.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.controller.hardware;
+package com.zhongshu.iot.server.core.controller.devices;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;

+ 1 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dataConfig/DeviceConfig.java

@@ -12,4 +12,5 @@ public class DeviceConfig {
     // 设备deviceId或gatewayId的最小长度
     public static final int minDeviceIdLength = 6;
 
+    public static final int minDeviceNameLength = 2;
 }

+ 3 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DeviceInfoService.java

@@ -119,6 +119,9 @@ public class DeviceInfoService {
 
             // 同步设备权限
             jmxSyncService.syncDevicesSecurity(List.of(finalDeviceInfo));
+
+            // 同步设备
+            deviceSyncFullCardService.noticeSyncDevice(List.of(finalDeviceInfo));
         });
 
         return ResultContent.buildSuccess(deviceInfo);

+ 2 - 4
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayInfoService.java

@@ -163,7 +163,7 @@ public class GateWayInfoService extends SuperService {
         if (checkIdContent.isFailed()) {
             return ResultContent.buildFail(checkIdContent.getMsg());
         }
-        ResultContent checkNameContent = JMXUtil.checkDeviceIdLength(param.getGateWayName(), "gateWayName");
+        ResultContent checkNameContent = JMXUtil.checkDeviceNameLength(param.getGateWayName(), "gateWayName");
         if (checkNameContent.isFailed()) {
             return ResultContent.buildFail(checkNameContent.getMsg());
         }
@@ -277,7 +277,7 @@ public class GateWayInfoService extends SuperService {
         if (checkIdContent.isFailed()) {
             return ResultContent.buildFail(checkIdContent.getMsg());
         }
-        ResultContent checkNameContent = JMXUtil.checkDeviceIdLength(param.getDeviceName(), "deviceName");
+        ResultContent checkNameContent = JMXUtil.checkDeviceNameLength(param.getDeviceName(), "deviceName");
         if (checkNameContent.isFailed()) {
             return ResultContent.buildFail(checkNameContent.getMsg());
         }
@@ -361,8 +361,6 @@ public class GateWayInfoService extends SuperService {
             // 更新网关的权限
             jmxSyncService.syncSecurityToMQTTService(gateWayInfo);
             log.info("设备注册成功:{}", deviceInfos.size());
-            // 同步设备
-            deviceSyncFullCardService.noticeSyncDevice(deviceInfos);
         });
 
         return ResultContent.buildSuccess();

+ 10 - 4
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/sync/DeviceSyncFullCardService.java

@@ -126,16 +126,22 @@ public class DeviceSyncFullCardService extends SuperService {
                 DeviceInfoSyncParam syncParam = new DeviceInfoSyncParam();
 
                 BeanUtils.copyProperties(it, syncParam);
+
+                List<String> gateWayIds = new ArrayList<>();
                 // 设备绑定的网关
                 List<GateWay2Device> gateWay2Devices = new ArrayList<>();
 
                 // 设备最新绑定的 网关信息
                 GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByDeviceInfoOrderByUpdateTimeDesc(it);
-                gateWay2Devices.add(gateWay2Device);
+                if (ObjectUtils.isNotEmpty(gateWay2Device)) {
+                    gateWay2Devices.add(gateWay2Device);
+                }
 
-                List<String> gateWayIds = gateWay2Devices.stream().map(it2 -> {
-                    return it2.getGateWayInfo().getGateWayId();
-                }).collect(Collectors.toList());
+                if (ObjectUtils.isNotEmpty(gateWay2Devices)) {
+                    gateWayIds = gateWay2Devices.stream().map(it2 -> {
+                        return it2.getGateWayInfo().getGateWayId();
+                    }).collect(Collectors.toList());
+                }
                 // 所属网关ID结合
                 syncParam.setGateWayId(String.join(",", gateWayIds));
                 // 项目code

+ 12 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/util/JMXUtil.java

@@ -141,4 +141,16 @@ public class JMXUtil {
         return ResultContent.buildSuccess();
     }
 
+    public static ResultContent checkDeviceNameLength(String id, String key) {
+        if (StringUtils.isNotEmpty(id)) {
+            if (id.contains(" ")) {
+                return ResultContent.buildFail(String.format("%s含有空格,不符合规范"));
+            }
+            if (id.length() > DeviceConfig.maxDeviceIdLength || id.length() < DeviceConfig.minDeviceNameLength) {
+                return ResultContent.buildFail(String.format("%s长度不能大于:%d,小于:%d", key, DeviceConfig.maxDeviceIdLength, DeviceConfig.minDeviceIdLength));
+            }
+        }
+        return ResultContent.buildSuccess();
+    }
+
 }