TRX преди 1 година
родител
ревизия
6d6015922a

+ 9 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/GateWayUserInfoModel.java

@@ -24,6 +24,15 @@ public class GateWayUserInfoModel extends SuperModel {
     @Schema(description = "用户状态:可用不可用")
     private MqttUserState state;
 
+    private String stateStr;
+
+    public String getStateStr() {
+        if (state != null) {
+            return state.getRemark();
+        }
+        return "";
+    }
+
     @Schema(description = "分组code")
     private String projectCode;
 

+ 4 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/GateWayUserInfoController.java

@@ -57,9 +57,11 @@ public class GateWayUserInfoController {
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "连接用户列表-分页查询")
+    @Operation(summary = "项目列表-分页查询")
     @RequestMapping(value = {"pageGateWayUser"}, method = {RequestMethod.POST})
-    public ResultContent<Page<GateWayUserInfoModel>> pageGateWayUser(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10, sort = "") Pageable pageable, @Parameter(required = false) GateWayUserInfoSearchParam param) {
+    public ResultContent<Page<GateWayUserInfoModel>> pageGateWayUser(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            GateWayUserInfoSearchParam param) {
         return gateWayUserInfoService.pageGateWayUser(pageable, param);
     }
 

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

@@ -13,6 +13,6 @@ public class MqttConfig {
 
     // 本地处理的事件名称
     public static final List<String> localHandelEvent = List.of("ping", "ServerTime",
-            "gateWayRegister", "deviceRegister");
+            "registGateway", "registDevice");
 
 }

+ 7 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/init/MqttInfoInit.java

@@ -2,6 +2,7 @@ package com.zhongshu.iot.server.core.init;
 
 import com.zhongshu.iot.server.core.service.device.GateWayUserInfoService;
 import com.zhongshu.iot.server.core.service.device.MqttInfoService;
+import com.zhongshu.iot.server.core.service.other.ScanExecuteService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;
@@ -24,6 +25,9 @@ public class MqttInfoInit implements CommandLineRunner {
     @Autowired
     private GateWayUserInfoService gateWayUserInfoService;
 
+    @Autowired
+    private ScanExecuteService scanExecuteService;
+
     @Override
     public void run(String... args) throws Exception {
         CompletableFuture.runAsync(() -> {
@@ -35,6 +39,9 @@ public class MqttInfoInit implements CommandLineRunner {
 
                 // 刷新所有用户和用户权限数据
                 gateWayUserInfoService.initData();
+
+                // 扫描执行方法
+                scanExecuteService.scanSystemExecuteMethod();
             } catch (Exception e) {
                 e.printStackTrace();
             }

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

@@ -30,6 +30,7 @@ import com.zhongshu.iot.server.core.service.base.SuperService;
 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.service.iotPlatform.PlatformTopic;
 import com.zhongshu.iot.server.core.util.CommonUtil;
 import com.zhongshu.iot.server.core.util.DateUtils;
 import com.zhongshu.iot.server.core.util.TokenUtil;
@@ -408,7 +409,7 @@ public class OperationMessageService {
                 String beanName = executeMethodInfo.getBeanName();
                 String methodName = executeMethodInfo.getMethodName();
                 Class c = applicationContext.getBean(beanName).getClass();
-                SuperService t = (SuperService) applicationContext.getBean(beanName);
+                PlatformTopic t = (PlatformTopic) applicationContext.getBean(beanName);
                 Method method = c.getMethod(methodName, String.class, String.class);
                 ResultContent<Object> resultContent = (ResultContent<Object>) method.invoke(t, entity.getDataId(), dataStr);
                 if (resultContent.isSuccess()) {

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

@@ -84,6 +84,9 @@ public class GateWayInfoService extends SuperService {
     @Autowired
     private OperationMessageDao operationMessageDao;
 
+    @Autowired
+    private GateWayUserInfoService gateWayUserInfoService;
+
     /**
      * 注册 网关
      *
@@ -91,11 +94,16 @@ public class GateWayInfoService extends SuperService {
      * @return
      */
     public ResultContent<Object> gateWayRegister(String dataId, String dataStr) {
+        log.info("gateWayRegister: {}", dataId);
         CommonResult commonResult = new CommonResult();
         OperationMessage operationMessage = operationMessageDao.findTopByDataId(dataId);
         if (ObjectUtils.isEmpty(operationMessage)) {
             return ResultContent.buildFail("数据不存在");
         }
+        ResultContent<GateWayUserInfo> resultContent = gateWayUserInfoService.verifyMqttUser(operationMessage.getTopic());
+        if (resultContent.isFailed()) {
+            return ResultContent.buildFail(resultContent.getMsg());
+        }
 
         return ResultContent.buildSuccess(commonResult);
     }

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

@@ -311,6 +311,23 @@ public class GateWayUserInfoService {
         return ResultContent.buildSuccess(model);
     }
 
+    public ResultContent<GateWayUserInfo> verifyMqttUser(String topic) {
+        // 找到 连接账号信息
+        String userName = "";
+        if (StringUtils.isNotEmpty(topic)) {
+            String[] arr = topic.split("/");
+            if (arr.length >= 2) {
+                userName = arr[1];
+            }
+        }
+        if (StringUtils.isEmpty(userName)) {
+            return ResultContent.buildFail("连接账号为空");
+        }
+        GateWayUserInfo entity = gateWayUserInfoDao.findTopByUserName(userName);
+
+        return ResultContent.buildSuccess(entity);
+    }
+
     public GateWayUserInfoModel toModel(GateWayUserInfo entity) {
         GateWayUserInfoModel model = new GateWayUserInfoModel();
         if (ObjectUtils.isNotEmpty(entity)) {

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

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.server.core.service.iotPlatform.impl;
 
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;
+import com.zhongshu.iot.server.core.service.base.SuperService;
 import com.zhongshu.iot.server.core.service.iotPlatform.PlatformTopic;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;