TRX 1 anno fa
parent
commit
0e943d955d
18 ha cambiato i file con 294 aggiunte e 32 eliminazioni
  1. 13 1
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainModel.java
  2. 10 1
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainParam.java
  3. 7 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dataConfig/MqttConfig.java
  4. 17 3
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotMain.java
  5. 8 2
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/artemis/ArtemisListenerService.java
  6. 8 9
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/artemis/OperationMessageService.java
  7. 3 8
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DevicePingInfoService.java
  8. 14 3
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayInfoService.java
  9. 15 4
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/JMXSyncService.java
  10. 9 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java
  11. 9 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/PlatformTopic.java
  12. 26 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/OnLineTopic.java
  13. 33 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/PingTopic.java
  14. 29 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/RegisterDeviceTopic.java
  15. 34 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/RegisterGatewayTopic.java
  16. 27 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/SystemTimeTopic.java
  17. 27 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/UnLineTopic.java
  18. 5 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/util/JMXUtil.java

+ 13 - 1
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainModel.java

@@ -1,9 +1,9 @@
 package com.zhongshu.iot.client.model.iot;
 
+import com.github.microservice.types.FunctionType;
 import com.zhongshu.iot.client.model.baseParam.SuperModel;
 import com.zhongshu.iot.client.type.DataType;
 import com.zhongshu.iot.client.type.EventType;
-import com.github.microservice.types.FunctionType;
 import com.zhongshu.iot.client.type.OperationType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
@@ -37,6 +37,12 @@ public class IotMainModel extends SuperModel {
     @Schema(description = "真实的topic")
     private String realIotTopic;
 
+    @Schema(description = "响应的topic")
+    private String replyIotTopic;
+
+    @Schema(description = "响应的真实的topic")
+    private String replyRealIotTopic;
+
     @Schema(description = "是否返回数据")
     private Boolean isReturnData = Boolean.TRUE;
 
@@ -121,4 +127,10 @@ public class IotMainModel extends SuperModel {
     @Schema(description = "业务处理地址")
     private String remoteUrl;
 
+    @Schema(description = "业务访问ak")
+    private String ak;
+
+    @Schema(description = "业务访问sk")
+    private String sk;
+
 }

+ 10 - 1
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/iot/IotMainParam.java

@@ -1,9 +1,9 @@
 package com.zhongshu.iot.client.model.iot;
 
+import com.github.microservice.types.FunctionType;
 import com.zhongshu.iot.client.model.baseParam.SuperParam;
 import com.zhongshu.iot.client.type.DataType;
 import com.zhongshu.iot.client.type.EventType;
-import com.github.microservice.types.FunctionType;
 import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.AllArgsConstructor;
 import lombok.Data;
@@ -36,6 +36,9 @@ public class IotMainParam extends SuperParam {
     @Schema(description = "物模型Topic")
     private String iotTopic;
 
+    @Schema(description = "响应的topic")
+    private String replyIotTopic;
+
     @Schema(description = "数据类型,number、Boolean、String 等", required = true)
     private DataType dataType;
 
@@ -72,4 +75,10 @@ public class IotMainParam extends SuperParam {
     @Schema(description = "业务处理地址")
     private String remoteUrl;
 
+    @Schema(description = "业务访问ak")
+    private String ak;
+
+    @Schema(description = "业务访问sk")
+    private String sk;
+
 }

+ 7 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dataConfig/MqttConfig.java

@@ -1,11 +1,18 @@
 package com.zhongshu.iot.server.core.dataConfig;
 
+import java.util.List;
+
 /**
  * @author TRX
  * @date 2025/1/2
  */
 public class MqttConfig {
 
+    // mqtt 超管的角色
     public static final String adminRoleName = "amq";
 
+    // 本地处理的事件名称
+    public static final List<String> localHandelEvent = List.of("ping", "ServerTime",
+            "gateWayRegister", "deviceRegister");
+
 }

+ 17 - 3
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/IotMain.java

@@ -52,6 +52,12 @@ public class IotMain extends SuperEntity {
     @Schema(description = "真实的topic")
     private String realIotTopic;
 
+    @Schema(description = "响应的topic")
+    private String replyIotTopic;
+
+    @Schema(description = "响应的真实的topic")
+    private String replyRealIotTopic;
+
     @Schema(description = "所属模版、物模型")
     @DBRef(lazy = true)
     private IotTemplate iotTemplate;
@@ -59,6 +65,17 @@ public class IotMain extends SuperEntity {
     @Schema(description = "是否返回数据")
     private Boolean isReturnData = Boolean.TRUE;
 
+    //---------------------------------业务平台的地址 start ---------------------
+
+    @Schema(description = "业务处理地址")
+    private String remoteUrl;
+
+    @Schema(description = "业务访问ak")
+    private String ak;
+
+    @Schema(description = "业务访问sk")
+    private String sk;
+    
     //---------------------------------属性类型的  字段  start ------------------
     @Schema(description = "数据类型,number、Boolean、String 等")
     private DataType dataType;
@@ -106,9 +123,6 @@ public class IotMain extends SuperEntity {
     @Schema(description = "关联时间")
     private Long addTime;
 
-    @Schema(description = "业务处理地址")
-    private String remoteUrl;
-
     @Schema(description = "网关信息")
     private String gateWayId;
 }

+ 8 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/artemis/ArtemisListenerService.java

@@ -26,19 +26,25 @@ public class ArtemisListenerService {
     OperationMessageService operationMessageService;
 
     // 网关来的消息
-    @JmsListener(destination = "/v1/gateway/#", containerFactory = MQConstant.TopicListenerContainerFactory)
+    @JmsListener(destination = "/gateway/#", containerFactory = MQConstant.TopicListenerContainerFactory)
     @JmsListener(destination = ".v1.gateway.#", containerFactory = MQConstant.TopicListenerContainerFactory)
     public void receiveGateWayMessage(Message message) {
         operationMessageService.handlerGateWayMessage(message);
     }
 
     // 设备来的消息
-    @JmsListener(destination = "/v1/device/#", containerFactory = MQConstant.TopicListenerContainerFactory)
+    @JmsListener(destination = "/device/#", containerFactory = MQConstant.TopicListenerContainerFactory)
     @JmsListener(destination = ".v1.device.#", containerFactory = MQConstant.TopicListenerContainerFactory)
     public void receiveDeviceMessage(Message message) {
         operationMessageService.handlerGateWayMessage(message);
     }
 
+    // 平台消息
+    @JmsListener(destination = "/platform/#", containerFactory = MQConstant.TopicListenerContainerFactory)
+    public void receivePlatformMessage(Message message) {
+        operationMessageService.handlerGateWayMessage(message);
+    }
+
     // 终端连接的消息
     @JmsListener(destination = "$sys.mqtt.sessions", containerFactory = MQConstant.TopicListenerContainerFactory)
     public void receiveOnLineChangeMessage(Message message, Session session) {

+ 8 - 9
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/artemis/OperationMessageService.java

@@ -19,6 +19,7 @@ import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
 import com.zhongshu.iot.server.core.dao.mqtt.OperationMessageDao;
 import com.zhongshu.iot.server.core.dao.mqtt.OperationMessageResultDao;
 import com.zhongshu.iot.server.core.dao.other.ExecuteMethodInfoDao;
+import com.zhongshu.iot.server.core.dataConfig.MqttConfig;
 import com.zhongshu.iot.server.core.domain.iot.IotMain;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceInfo;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.OperationMessage;
@@ -26,9 +27,9 @@ import com.zhongshu.iot.server.core.domain.iot.mqtt.OperationMessageResult;
 import com.zhongshu.iot.server.core.domain.other.ExecuteMethodInfo;
 import com.zhongshu.iot.server.core.httpRequest.ApiRequestService;
 import com.zhongshu.iot.server.core.service.base.SuperService;
-import com.zhongshu.iot.server.core.service.iot.IotDataVerifyService;
 import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
 import com.zhongshu.iot.server.core.service.device.GateWayInfoService;
+import com.zhongshu.iot.server.core.service.iot.IotDataVerifyService;
 import com.zhongshu.iot.server.core.util.CommonUtil;
 import com.zhongshu.iot.server.core.util.DateUtils;
 import com.zhongshu.iot.server.core.util.TokenUtil;
@@ -358,8 +359,7 @@ public class OperationMessageService {
             List<IotMain> events = iotMainDao.findByRealIotTopicAndFunctionTypeOrderByCreateTimeAsc(entity.getTopic(), FunctionType.Event);
             if (ObjectUtils.isNotEmpty(events)) {
                 // 去重
-                events = events.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
-                        () -> new TreeSet<>(Comparator.comparing(IotMain::getRealIotTopic))), ArrayList::new));
+                events = events.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(IotMain::getRealIotTopic))), ArrayList::new));
                 for (IotMain iotMain : events) {
                     executeOperationMessage(entity, requestData, iotMain);
                 }
@@ -368,11 +368,10 @@ public class OperationMessageService {
                 handleMsg = "无对应物模型事件处理";
                 log.error("无对应物模型事件处理: {}", entity.getTopic());
             }
-            // 如果是ping,则平台也会处理
-            if (event != null && event.equals("ping")) {
-                pingHandler(entity, requestData);
-            } else if (event != null && event.equals("ServerTime")) {
-                pingHandler(entity, requestData);
+
+            // 本地处理的事件
+            if (event != null && MqttConfig.localHandelEvent.contains(event)) {
+                localHandler(entity, requestData);
             } else {
                 // 业务处理失败
                 entity.setIsHandleSuccess(isHandleSuccess);
@@ -392,7 +391,7 @@ public class OperationMessageService {
      * @param requestData
      * @return
      */
-    public ResultContent pingHandler(OperationMessage entity, JSONObject requestData) {
+    public ResultContent localHandler(OperationMessage entity, JSONObject requestData) {
         String event = entity.getEvent();
         Object result = null;
         StopWatch stopWatch = new StopWatch();

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

@@ -13,8 +13,6 @@ import com.zhongshu.iot.server.core.dao.mqtt.DeviceOnLineInfoDao;
 import com.zhongshu.iot.server.core.dao.mqtt.DevicePingInfoDao;
 import com.zhongshu.iot.server.core.dao.mqtt.GateWayInfoDao;
 import com.zhongshu.iot.server.core.dataConfig.CommonTTLTimeConfig;
-import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
-import com.zhongshu.iot.server.core.domain.ExecuteAnnotationServiceMethod;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.*;
 import com.zhongshu.iot.server.core.service.base.CommonService;
 import com.zhongshu.iot.server.core.service.base.RedisService;
@@ -38,7 +36,6 @@ import java.util.Map;
  */
 @Slf4j
 @Service
-@ExecuteAnnotationService
 public class DevicePingInfoService extends SuperService {
 
     @Autowired
@@ -62,8 +59,7 @@ public class DevicePingInfoService extends SuperService {
     @Autowired
     private RedisService redisService;
 
-    @ExecuteAnnotationServiceMethod(value = "devicePing", remark = "设备心跳")
-    public ResultContent<Object> devicePing(String dataStr) {
+    private ResultContent<Object> devicePing(String dataId, String dataStr) {
         DevicePingInfoParam param = JSONUtil.toBean(dataStr, DevicePingInfoParam.class);
         String deviceId = param.getDeviceId();
         log.info("devicePing 设备在线处理:{}", deviceId);
@@ -105,8 +101,7 @@ public class DevicePingInfoService extends SuperService {
         return ResultContent.buildSuccess();
     }
 
-    @ExecuteAnnotationServiceMethod(value = "ping", remark = "网关心跳")
-    public ResultContent<Object> ping(String dataStr) {
+    public ResultContent<Object> ping(String dataId, String dataStr) {
         PingResult pingResult = new PingResult();
         GateWayPingInfoParam param = JSONUtil.toBean(dataStr, GateWayPingInfoParam.class);
         if (StringUtils.isEmpty(param.getGateWayId())) {
@@ -114,7 +109,7 @@ public class DevicePingInfoService extends SuperService {
             return ResultContent.buildFail("GateWayId为空");
         }
         if (StringUtils.isNotEmpty(param.getDeviceId())) {
-            devicePing(dataStr);
+            devicePing(dataId, dataStr);
         } else {
             log.info("ping 网关在线处理:{}", param.getGateWayId());
             GateWayInfo gateWayInfo = gateWayInfoDao.findTopByGateWayId(param.getGateWayId());

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

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.http.APIResponseModel;
+import com.github.microservice.models.common.CommonResult;
 import com.github.microservice.models.project.ProjectConfigQueryParam;
 import com.github.microservice.models.type.OnLineState;
 import com.github.microservice.net.ResultContent;
@@ -80,6 +81,19 @@ public class GateWayInfoService extends SuperService {
     @Autowired
     private JMXSyncService jmxSyncService;
 
+    /**
+     * 注册 网关
+     *
+     * @param dataStr
+     * @return
+     */
+    public ResultContent<Object> gateWayRegister(String dataId, String dataStr) {
+        CommonResult commonResult = new CommonResult();
+
+
+        return ResultContent.buildSuccess(commonResult);
+    }
+
     /**
      * 添加网关
      *
@@ -105,9 +119,6 @@ public class GateWayInfoService extends SuperService {
         log.info("网关注册成功");
         // 通知同步 (网关信息)
         deviceSyncFullCardService.noticeSyncGateWay(gateWayInfo);
-
-        //todo 创建token
-        // akSignService.createAkSk();
         return ResultContent.buildSuccess(gateWayInfo);
     }
 

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

@@ -4,6 +4,7 @@ import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.server.core.dao.mqtt.*;
 import com.zhongshu.iot.server.core.dataConfig.MqttConfig;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.*;
+import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
 import com.zhongshu.iot.server.core.util.DateUtils;
 import com.zhongshu.iot.server.core.util.JMXUtil;
 import lombok.Cleanup;
@@ -12,6 +13,7 @@ import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl;
 import org.apache.activemq.artemis.api.core.management.ObjectNameBuilder;
 import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
 import org.springframework.stereotype.Service;
 
 import javax.management.MBeanServerConnection;
@@ -55,6 +57,10 @@ public class JMXSyncService {
     @Autowired
     private GateWayInfoDao gateWayInfoDao;
 
+    @Autowired
+    private ApplicationContext applicationContext;
+
+
     /**
      * 把用户同步到MQTT服务中
      *
@@ -113,14 +119,19 @@ public class JMXSyncService {
                         if (JMXUtil.mqttUserIsExit(oldUserStr)) {
                             addressControl.removeUser(gateWayUserInfo.getUserName());
                         }
+                        // 添加用户的默认权限
+                        List<String> security = new ArrayList<>();
+//                        List<String> security = JMXUtil.buildGateWayUserDefault(gateWayUserInfo);
                         // 添加用户
                         addressControl.addUser(gateWayUserInfo.getUserName(), gateWayUserInfo.getPassWord(), gateWayUserInfo.getRoleName(), false);
-
-                        // 添加用户的默认权限
-                        List<String> security = JMXUtil.buildGateWayUserDefault(gateWayUserInfo);
+                        String userName = gateWayUserInfo.getUserName();
+                        this.applicationContext.getBeansOfType(PlatformTopic.class).values().forEach((it) -> {
+                            security.add(String.format(it.topic(), userName));
+                        });
                         if (ObjectUtils.isNotEmpty(security)) {
+                            List<String> securites = security.stream().distinct().collect(Collectors.toList());
                             String roleName = gateWayUserInfo.getRoleName();
-                            for (String addressMatch : security) {
+                            for (String addressMatch : securites) {
                                 addressControl.addSecuritySettings(addressMatch, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName);
                             }
                         }

+ 9 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotServiceImpl.java

@@ -425,10 +425,16 @@ public class IotServiceImpl extends SuperService {
         if (iotMain != null && iotMain.getIotDataType() == IotDataType.Device) {
             // 把 topic有占位符的换为具体的值
             String deviceId = iotMain.getDeviceId();
+            // 发布的topic
             String iotTopic = iotMain.getIotTopic();
+            // 响应的topic
+            String replyIotTopic = iotMain.getReplyIotTopic();
+
             String realIotTopic = iotTopic;
+            String replyRealIotTopic = replyIotTopic;
             if (StringUtils.isNotEmpty(iotTopic)) {
                 realIotTopic = realIotTopic.replaceAll(Pattern.quote("${deviceId}"), deviceId);
+                replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${deviceId}"), deviceId);
             }
             DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
             if (ObjectUtils.isNotEmpty(deviceInfo)) {
@@ -436,10 +442,13 @@ public class IotServiceImpl extends SuperService {
                 if (ObjectUtils.isNotEmpty(gateWay2Device)) {
                     String gateWayId = gateWay2Device.getGateWayInfo().getGateWayId();
                     realIotTopic = realIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
+                    replyRealIotTopic = replyRealIotTopic.replaceAll(Pattern.quote("${gateWayId}"), gateWayId);
+
                     iotMain.setGateWayId(gateWayId);
                 }
             }
             iotMain.setRealIotTopic(realIotTopic);
+            iotMain.setReplyRealIotTopic(replyRealIotTopic);
         }
     }
 

+ 9 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/PlatformTopic.java

@@ -0,0 +1,9 @@
+package com.zhongshu.iot.server.core.service.iotPlatform;
+
+public interface PlatformTopic {
+
+    public String topic();
+
+    public void action(String dataId, String message);
+
+}

+ 26 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/OnLineTopic.java

@@ -0,0 +1,26 @@
+package com.zhongshu.iot.server.core.service.iotPlatform.impl;
+
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
+import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author TRX
+ * @date 2025/1/13
+ */
+@Component
+@ExecuteAnnotationService
+@Slf4j
+public class OnLineTopic implements PlatformTopic {
+
+    @Override
+    public String topic() {
+        return "/platform/%s/online";
+    }
+
+    @Override
+    public void action(String topic, String message) {
+
+    }
+}

+ 33 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/PingTopic.java

@@ -0,0 +1,33 @@
+package com.zhongshu.iot.server.core.service.iotPlatform.impl;
+
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationServiceMethod;
+import com.zhongshu.iot.server.core.service.device.DevicePingInfoService;
+import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author TRX
+ * @date 2025/1/13
+ */
+@ExecuteAnnotationService
+@Component
+@Slf4j
+public class PingTopic implements PlatformTopic {
+
+    @Autowired
+    private DevicePingInfoService devicePingInfoService;
+
+    @Override
+    public String topic() {
+        return "/platform/%s/ping";
+    }
+
+    @ExecuteAnnotationServiceMethod(value = "ping", remark = "ping心跳")
+    @Override
+    public void action(String dataId, String message) {
+        devicePingInfoService.ping(dataId, message);
+    }
+}

+ 29 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/RegisterDeviceTopic.java

@@ -0,0 +1,29 @@
+package com.zhongshu.iot.server.core.service.iotPlatform.impl;
+
+
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationServiceMethod;
+import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author TRX
+ * @date 2025/1/13
+ */
+@Component
+@ExecuteAnnotationService
+@Slf4j
+public class RegisterDeviceTopic implements PlatformTopic {
+
+    @Override
+    public String topic() {
+        return "/platform/%s/regist";
+    }
+
+    @ExecuteAnnotationServiceMethod(value = "registDevice", remark = "设备注册")
+    @Override
+    public void action(String dataId, String message) {
+
+    }
+}

+ 34 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/RegisterGatewayTopic.java

@@ -0,0 +1,34 @@
+package com.zhongshu.iot.server.core.service.iotPlatform.impl;
+
+
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationServiceMethod;
+import com.zhongshu.iot.server.core.service.device.GateWayInfoService;
+import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author TRX
+ * @date 2025/1/13
+ */
+@Component
+@ExecuteAnnotationService
+@Slf4j
+public class RegisterGatewayTopic implements PlatformTopic {
+
+    @Autowired
+    private GateWayInfoService gateWayInfoService;
+
+    @Override
+    public String topic() {
+        return "/platform/%s/regist";
+    }
+
+    @ExecuteAnnotationServiceMethod(value = "registGateway", remark = "网关注册")
+    @Override
+    public void action(String dataId, String message) {
+        gateWayInfoService.gateWayRegister(dataId, message);
+    }
+}

+ 27 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/SystemTimeTopic.java

@@ -0,0 +1,27 @@
+package com.zhongshu.iot.server.core.service.iotPlatform.impl;
+
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
+import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author TRX
+ * @date 2025/1/13
+ */
+@Component
+@ExecuteAnnotationService
+@Slf4j
+public class SystemTimeTopic implements PlatformTopic {
+
+    @Override
+    public String topic() {
+        return "/platform/%s/systemTime";
+    }
+
+    @Override
+    public void action(String topic, String message) {
+
+    }
+
+}

+ 27 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iotPlatform/impl/UnLineTopic.java

@@ -0,0 +1,27 @@
+package com.zhongshu.iot.server.core.service.iotPlatform.impl;
+
+import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
+import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author TRX
+ * @date 2025/1/13
+ */
+@Component
+@ExecuteAnnotationService
+@Slf4j
+public class UnLineTopic implements PlatformTopic {
+
+    @Override
+    public String topic() {
+        return "/platform/%s/offline";
+    }
+
+    @Override
+    public void action(String topic, String message) {
+
+    }
+
+}

+ 5 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/util/JMXUtil.java

@@ -82,7 +82,11 @@ public class JMXUtil {
     public static List<String> buildGateWayUserDefault(GateWayUserInfo gateWayUserInfo) {
         List<String> list = new ArrayList<>();
         if (ObjectUtils.isNotEmpty(gateWayUserInfo)) {
-            list.add(String.format("/device/register/%s/#", gateWayUserInfo.getUserName()));
+            list.add(String.format("/platform/%s/register", gateWayUserInfo.getUserName()));
+            list.add(String.format("/platform/%s/ping", gateWayUserInfo.getUserName()));
+            list.add(String.format("/platform/%s/onLine", gateWayUserInfo.getUserName()));
+            list.add(String.format("/platform/%s/unLine", gateWayUserInfo.getUserName()));
+            list.add(String.format("/platform/%s/systemTime", gateWayUserInfo.getUserName()));
         }
         return list;
     }