TRX 1 рік тому
батько
коміт
3be3658542
34 змінених файлів з 223 додано та 58 видалено
  1. 3 0
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/GateWayUserInfoAddParam.java
  2. 21 0
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/GateWayUserInfoModel.java
  3. 20 0
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/GateWayUserInfoParam.java
  4. 18 0
      OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/GateWayUserInfoUpdateParam.java
  5. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/TestController.java
  6. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/free/GateWayFreeController.java
  7. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/DeviceController.java
  8. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/GateWayController.java
  9. 15 9
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/GateWayUserInfoController.java
  10. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/MqttInfoController.java
  11. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/hardware/OperationMessageController.java
  12. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/user/ProjectInfoController.java
  13. 2 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/extend/GateWayUserInfoDaoExtend.java
  14. 7 9
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/impl/GateWayUserInfoDaoImpl.java
  15. 6 0
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/mqtt/GateWayUserInfo.java
  16. 0 2
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/mqtt/Mqtt2User.java
  17. 2 3
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/init/MqttInfoInit.java
  18. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/listener/MongodbAutoEvent.java
  19. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/listener/RedisKeyExpirationListener.java
  20. 2 2
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/artemis/OperationMessageService.java
  21. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/base/InitService.java
  22. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DeviceInfoService.java
  23. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DevicePingInfoService.java
  24. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayInfoService.java
  25. 93 12
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayUserInfoService.java
  26. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/MqttInfoService.java
  27. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/ProjectInfoService.java
  28. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/ServerTimeService.java
  29. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotTemplate2DeviceService.java
  30. 5 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/sync/DeviceSyncFullCardService.java
  31. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/sync/ProjectFromFullCardService.java
  32. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/user/impl/UserManagerServiceImpl.java
  33. 1 1
      OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/timers/CheckDeviceStateWork.java
  34. 9 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/GateWayUserInfoAddParam.java

@@ -18,4 +18,7 @@ public class GateWayUserInfoAddParam extends SuperParam {
 
     @Schema(description = "mqtt角色信息")
     private String roleName;
+
+    @Schema(description = "最大的可绑定的设备数")
+    private Long number;
 }

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

@@ -1,6 +1,8 @@
 package com.zhongshu.iot.client.model.mqtt;
 
 import com.zhongshu.iot.client.model.baseParam.SuperModel;
+import com.zhongshu.iot.client.type.type.MqttUserState;
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
 /**
@@ -9,4 +11,23 @@ import lombok.Data;
  */
 @Data
 public class GateWayUserInfoModel extends SuperModel {
+
+    @Schema(description = "mqtt连接账号")
+    private String userName;
+
+    @Schema(description = "mqtt连接密码")
+    private String passWord;
+
+    @Schema(description = "用户权限角色名称,一般和 userName 相同")
+    private String roleName;
+
+    @Schema(description = "用户状态:可用不可用")
+    private MqttUserState state;
+
+    @Schema(description = "最大设备数量(网关也算一个设备)")
+    private Long number = 0L;
+
+    @Schema(description = "已绑定的设备数量")
+    private Long bindNumber = 0L;
+
 }

+ 20 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/GateWayUserInfoParam.java

@@ -0,0 +1,20 @@
+package com.zhongshu.iot.client.model.mqtt;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2025/1/8
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class GateWayUserInfoParam {
+
+    @Schema(description = "最大的可绑定的设备数")
+    private Long number;
+
+}

+ 18 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/GateWayUserInfoUpdateParam.java

@@ -0,0 +1,18 @@
+package com.zhongshu.iot.client.model.mqtt;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2025/1/8
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class GateWayUserInfoUpdateParam extends GateWayUserInfoParam {
+    @Schema(description = "数据ID")
+    private String id;
+}

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/TestController.java

@@ -5,7 +5,7 @@ import com.zhongshu.iot.client.model.mqtt.SendMessageModel;
 import com.zhongshu.iot.server.core.service.artemis.OperationMessageService;
 import com.zhongshu.iot.server.core.service.groovy.GroovySupport;
 import com.zhongshu.iot.server.core.service.iot.IotServiceImpl;
-import com.zhongshu.iot.server.core.service.mqtt.DeviceInfoService;
+import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
 import com.zhongshu.iot.server.core.service.openApi.OpenAPIRegisterService;
 import com.zhongshu.iot.server.core.service.other.ScanExecuteService;
 import com.github.microservice.net.ResultContent;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/free/GateWayFreeController.java

@@ -5,7 +5,7 @@ import com.zhongshu.iot.client.model.mqtt.GateWayBindDeviceParam;
 import com.zhongshu.iot.client.model.mqtt.GateWayInfoAddParam;
 import com.zhongshu.iot.client.model.mqtt.MqttInfoReturnModel;
 import com.zhongshu.iot.server.core.service.base.AkSignService;
-import com.zhongshu.iot.server.core.service.mqtt.GateWayInfoService;
+import com.zhongshu.iot.server.core.service.device.GateWayInfoService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.extern.slf4j.Slf4j;

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

@@ -8,7 +8,7 @@ import com.zhongshu.iot.client.model.mqtt.DeviceInfoModel;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoSearchParam;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoUpdateRemark;
 import com.github.microservice.types.FunctionType;
-import com.zhongshu.iot.server.core.service.mqtt.DeviceInfoService;
+import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
 import com.github.microservice.net.ResultContent;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;

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

@@ -6,7 +6,7 @@ import com.zhongshu.iot.client.model.mqtt.GateWayBindDeviceParam;
 import com.zhongshu.iot.client.model.mqtt.GateWayInfoAddParam;
 import com.zhongshu.iot.client.model.mqtt.GateWayInfoModel;
 import com.zhongshu.iot.client.model.mqtt.GateWayInfoSearchParam;
-import com.zhongshu.iot.server.core.service.mqtt.GateWayInfoService;
+import com.zhongshu.iot.server.core.service.device.GateWayInfoService;
 import com.github.microservice.net.ResultContent;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;

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

@@ -2,12 +2,12 @@ package com.zhongshu.iot.server.core.controller.hardware;
 
 import com.github.microservice.auth.security.annotations.ResourceAuth;
 import com.github.microservice.auth.security.type.AuthType;
-import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoAddParam;
+import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoModel;
 import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoNameParam;
+import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoParam;
 import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoSearchParam;
-import com.zhongshu.iot.server.core.service.mqtt.GateWayUserInfoService;
-import com.github.microservice.net.ResultContent;
+import com.zhongshu.iot.server.core.service.device.GateWayUserInfoService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -39,13 +39,20 @@ public class GateWayUserInfoController {
 
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "添加连接用户")
-    @RequestMapping(value = "addDeviceInfo", method = {RequestMethod.POST})
-    public ResultContent addDeviceInfo(@RequestBody GateWayUserInfoAddParam param) {
-        Assert.hasText(param.getUserName(), "连接账号不能为空");
-        Assert.hasText(param.getPassWord(), "连接密码不能为空");
-        return gateWayUserInfoService.addGateWayUser(param);
+    @RequestMapping(value = "createUser", method = {RequestMethod.POST})
+    public ResultContent createUser(@RequestBody GateWayUserInfoParam param) {
+        return gateWayUserInfoService.createUser(param);
     }
 
+//    @ResourceAuth(value = "user", type = AuthType.User)
+//    @Operation(summary = "添加连接用户")
+//    @RequestMapping(value = "addDeviceInfo", method = {RequestMethod.POST})
+//    public ResultContent addDeviceInfo(@RequestBody GateWayUserInfoAddParam param) {
+//        Assert.hasText(param.getUserName(), "连接账号不能为空");
+//        Assert.hasText(param.getPassWord(), "连接密码不能为空");
+//        return gateWayUserInfoService.addGateWayUser(param);
+//    }
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "连接用户列表-分页查询")
     @RequestMapping(value = {"pageGateWayUser"}, method = {RequestMethod.POST})
@@ -58,7 +65,6 @@ public class GateWayUserInfoController {
     @Operation(summary = "删除连接用户")
     @RequestMapping(value = "deleteMqttUser", method = {RequestMethod.POST})
     public ResultContent deleteMqttUser(GateWayUserInfoNameParam param) {
-        Assert.hasText(param.getUserName(), "连接账号不能为空");
         return gateWayUserInfoService.deleteMqttUser(param);
     }
 

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

@@ -5,7 +5,7 @@ import com.github.microservice.auth.security.type.AuthType;
 import com.zhongshu.iot.client.model.mqtt.MqttInfoAddParam;
 import com.zhongshu.iot.client.model.mqtt.MqttInfoModel;
 import com.zhongshu.iot.client.model.mqtt.MqttInfoSimpleModel;
-import com.zhongshu.iot.server.core.service.mqtt.MqttInfoService;
+import com.zhongshu.iot.server.core.service.device.MqttInfoService;
 import com.github.microservice.net.ResultContent;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;

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

@@ -7,7 +7,7 @@ import com.zhongshu.iot.client.model.artemis.OperationMessageResultModel;
 import com.zhongshu.iot.client.model.artemis.OperationMessageResultSearch;
 import com.zhongshu.iot.client.model.artemis.OperationMessageSearchParam;
 import com.zhongshu.iot.server.core.service.artemis.OperationMessageService;
-import com.zhongshu.iot.server.core.service.mqtt.DeviceInfoService;
+import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
 import com.github.microservice.net.ResultContent;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/controller/user/ProjectInfoController.java

@@ -4,7 +4,7 @@ import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.client.model.mqtt.ProjectInfoAddParam;
 import com.zhongshu.iot.client.model.mqtt.ProjectInfoModel;
 import com.zhongshu.iot.client.model.mqtt.ProjectInfoSearchParam;
-import com.zhongshu.iot.server.core.service.mqtt.ProjectInfoService;
+import com.zhongshu.iot.server.core.service.device.ProjectInfoService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;

+ 2 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/extend/GateWayUserInfoDaoExtend.java

@@ -11,5 +11,7 @@ import org.springframework.data.domain.Pageable;
  * @Version: 1.0
  */
 public interface GateWayUserInfoDaoExtend {
+
     Page<GateWayUserInfo> page(Pageable pageable, GateWayUserInfoSearchParam param);
+
 }

+ 7 - 9
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/impl/GateWayUserInfoDaoImpl.java

@@ -1,10 +1,10 @@
 package com.zhongshu.iot.server.core.dao.mqtt.impl;
 
+import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
+import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoSearchParam;
 import com.zhongshu.iot.server.core.dao.base.BaseImpl;
 import com.zhongshu.iot.server.core.dao.mqtt.extend.GateWayUserInfoDaoExtend;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWayUserInfo;
-import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
-import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoSearchParam;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
@@ -34,7 +34,7 @@ public class GateWayUserInfoDaoImpl extends BaseImpl implements GateWayUserInfoD
 
     @Override
     public Page<GateWayUserInfo> page(Pageable pageable, GateWayUserInfoSearchParam param) {
-        Criteria criteria = new Criteria();
+        Criteria criteria = buildCriteriaAboutTime(param);
 
         if (StringUtils.isNotEmpty(param.getId())) {
             criteria.and("id").is(param.getId());
@@ -44,23 +44,21 @@ public class GateWayUserInfoDaoImpl extends BaseImpl implements GateWayUserInfoD
             criteria.and("state").is(param.getState());
         }
 
-        if (StringUtils.isNotEmpty(param.getEpId())) {
-            criteria.and("epId").is(param.getEpId());
-        }
-
         // 模糊搜索
         List<Criteria> criterias = new ArrayList<>();
         if (StringUtils.isNotEmpty(param.getUserName())) {
             Pattern pattern = Pattern.compile("^.*" + param.getUserName() + ".*$");
             criterias.add(Criteria.where("userName").is(pattern));
         }
+        if (StringUtils.isNotEmpty(param.getRoleName())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getRoleName() + ".*$");
+            criterias.add(Criteria.where("roleName").is(pattern));
+        }
         if (!CollectionUtils.isEmpty(criterias)) {
             criteria.andOperator(criterias.toArray(new Criteria[]{}));
         }
 
-        criteria.and("isDelete").is(Boolean.FALSE);
         Sort sort = buildSort(param);
-
         Query query = Query.query(criteria);
         query.with(sort);
         return dbHelper.pages(query, pageable, GateWayUserInfo.class);

+ 6 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/mqtt/GateWayUserInfo.java

@@ -29,4 +29,10 @@ public class GateWayUserInfo extends SuperEntity {
 
     @Schema(description = "用户状态:可用不可用")
     private MqttUserState state;
+
+    @Schema(description = "最大设备数量(网关也算一个设备)")
+    private Long number = 0L;
+
+    @Schema(description = "已绑定的设备数量")
+    private Long bindNumber = 0L;
 }

+ 0 - 2
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/domain/iot/mqtt/Mqtt2User.java

@@ -45,6 +45,4 @@ public class Mqtt2User extends SuperEntity {
 
     private String msg = "";
 
-    @Schema(description = "设备数量(网关也算一个设备)")
-    private Long number = 0L;
 }

+ 2 - 3
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/init/MqttInfoInit.java

@@ -1,8 +1,7 @@
 package com.zhongshu.iot.server.core.init;
 
-import com.zhongshu.iot.server.core.service.base.InitService;
-import com.zhongshu.iot.server.core.service.mqtt.GateWayUserInfoService;
-import com.zhongshu.iot.server.core.service.mqtt.MqttInfoService;
+import com.zhongshu.iot.server.core.service.device.GateWayUserInfoService;
+import com.zhongshu.iot.server.core.service.device.MqttInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.CommandLineRunner;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/listener/MongodbAutoEvent.java

@@ -1,7 +1,7 @@
 package com.zhongshu.iot.server.core.listener;
 
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceOnLineInfo;
-import com.zhongshu.iot.server.core.service.mqtt.DevicePingInfoService;
+import com.zhongshu.iot.server.core.service.device.DevicePingInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.bson.Document;
 import org.springframework.beans.factory.annotation.Autowired;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/listener/RedisKeyExpirationListener.java

@@ -1,6 +1,6 @@
 package com.zhongshu.iot.server.core.listener;
 
-import com.zhongshu.iot.server.core.service.mqtt.DevicePingInfoService;
+import com.zhongshu.iot.server.core.service.device.DevicePingInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.connection.Message;

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

@@ -27,8 +27,8 @@ 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.mqtt.DeviceInfoService;
-import com.zhongshu.iot.server.core.service.mqtt.GateWayInfoService;
+import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
+import com.zhongshu.iot.server.core.service.device.GateWayInfoService;
 import com.zhongshu.iot.server.core.util.CommonUtil;
 import com.zhongshu.iot.server.core.util.DateUtils;
 import com.zhongshu.iot.server.core.util.TokenUtil;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/base/InitService.java

@@ -1,7 +1,7 @@
 package com.zhongshu.iot.server.core.service.base;
 
 import com.github.microservice.net.ResultContent;
-import com.zhongshu.iot.server.core.service.mqtt.GateWayUserInfoService;
+import com.zhongshu.iot.server.core.service.device.GateWayUserInfoService;
 import com.zhongshu.iot.server.core.service.user.impl.UserServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/DeviceInfoService.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DeviceInfoService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.service.mqtt;
+package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.models.type.DeviceType;
 import com.github.microservice.models.type.OnLineState;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/DevicePingInfoService.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/DevicePingInfoService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.service.mqtt;
+package com.zhongshu.iot.server.core.service.device;
 
 import cn.hutool.json.JSONUtil;
 import com.github.microservice.models.hxz.DevicePingInfoParam;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/GateWayInfoService.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayInfoService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.service.mqtt;
+package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.http.APIResponseModel;
 import com.github.microservice.models.project.ProjectConfigQueryParam;

+ 93 - 12
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/GateWayUserInfoService.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/GateWayUserInfoService.java

@@ -1,10 +1,7 @@
-package com.zhongshu.iot.server.core.service.mqtt;
+package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.net.ResultContent;
-import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoAddParam;
-import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoModel;
-import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoNameParam;
-import com.zhongshu.iot.client.model.mqtt.GateWayUserInfoSearchParam;
+import com.zhongshu.iot.client.model.mqtt.*;
 import com.zhongshu.iot.client.type.type.MqttUserState;
 import com.zhongshu.iot.server.core.dao.mqtt.*;
 import com.zhongshu.iot.server.core.dataConfig.MqttConfig;
@@ -36,6 +33,8 @@ import java.util.List;
 import java.util.stream.Collectors;
 
 /**
+ * 账号管理
+ *
  * @author TRX
  * @date 2024/5/17
  */
@@ -69,11 +68,9 @@ public class GateWayUserInfoService {
      */
     public void initData() {
         log.info("GateWayUserInfoService initData");
-
         initDefaultUser();
 
         refreshAllGateWayUser();
-
         refreshAllGateWaySecurity();
     }
 
@@ -114,7 +111,7 @@ public class GateWayUserInfoService {
                 ResultContent<GateWayUserInfo> resultContent = addGateWayUser(userParam);
                 if (resultContent.isSuccess()) {
                     gateWayUserInfo = resultContent.getContent();
-                    if(ObjectUtils.isEmpty(gateWay2User)) {
+                    if (ObjectUtils.isEmpty(gateWay2User)) {
                         gateWay2User = new GateWay2User();
                     }
 
@@ -135,6 +132,32 @@ public class GateWayUserInfoService {
         return gateWayUserInfo;
     }
 
+    /**
+     * 添加 连接账号
+     *
+     * @param param
+     * @return
+     */
+    public ResultContent createUser(GateWayUserInfoParam param) {
+        Long number = param.getNumber();
+        if (number == null || number == 0) {
+            return ResultContent.buildFail("number不符合要求");
+        }
+
+        GateWayUserInfoAddParam userParam = new GateWayUserInfoAddParam();
+        String userName = CommonUtil.generateRandomString(8);
+        String roleName = userName;
+        userParam.setUserName(userName);
+        userParam.setPassWord(CommonUtil.generateRandomString(16));
+        userParam.setRoleName(roleName);
+        userParam.setNumber(number);
+        ResultContent<GateWayUserInfo> resultContent = addGateWayUser(userParam);
+        if (resultContent.isFailed()) {
+            return ResultContent.buildFail(resultContent.getMsg());
+        }
+        return ResultContent.buildSuccess();
+    }
+
     /**
      * 添加用户 (从网关注册开始)
      *
@@ -153,6 +176,7 @@ public class GateWayUserInfoService {
         BeanUtils.copyProperties(param, entity);
         entity.setState(MqttUserState.Enable);
         gateWayUserInfoDao.save(entity);
+
         // 同步用户
         syncUserToMQTTService(entity);
         return ResultContent.buildSuccess(entity);
@@ -184,7 +208,7 @@ public class GateWayUserInfoService {
         // 同步
         if (param.getState() == MqttUserState.Disable) {
             // 不过不可用,则删除QMTT服务上的用户信息
-            deleteGateWayUser(entity);
+            removeUserToMQTTService(entity);
         } else {
             // 添加用户
             syncUserToMQTTService(entity);
@@ -204,8 +228,9 @@ public class GateWayUserInfoService {
             return ResultContent.buildFail(String.format("%s 账号不存在", param.getUserName()));
         }
         gateWayUserInfoDao.delete(entity);
+
         // 删除服务文件上的用户
-        deleteGateWayUser(entity);
+        removeUserToMQTTService(entity);
         return ResultContent.buildSuccess();
     }
 
@@ -297,6 +322,15 @@ public class GateWayUserInfoService {
                             addressControl.removeUser(gateWayUserInfo.getUserName());
                         }
                         addressControl.addUser(gateWayUserInfo.getUserName(), gateWayUserInfo.getPassWord(), gateWayUserInfo.getRoleName(), false);
+                        // 添加用户的默认权限
+                        List<String> security = JMXUtil.buildGateWayUserDefault(gateWayUserInfo);
+                        if (ObjectUtils.isNotEmpty(security)) {
+                            String roleName = gateWayUserInfo.getRoleName();
+                            for (String addressMatch : security) {
+                                addressControl.addSecuritySettings(addressMatch, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName);
+                            }
+                        }
+
                         mqtt2User.setGateWayUserInfo(gateWayUserInfo);
                         mqtt2User.setUserName(gateWayUserInfo.getUserName());
 
@@ -321,6 +355,47 @@ public class GateWayUserInfoService {
         }
     }
 
+    public ResultContent removeUserToMQTTService(GateWayUserInfo gateWayUserInfo) {
+        //todo删除用户
+        List<MqttInfo> list = mqttInfoDao.findAll();
+        log.info("removeUserToMQTTService {}", list.size());
+        if (ObjectUtils.isNotEmpty(list)) {
+            for (MqttInfo mqttInfo : list) {
+                removeMqttUsers(mqttInfo, List.of(gateWayUserInfo));
+            }
+        }
+        return ResultContent.buildSuccess();
+    }
+
+    private void removeMqttUsers(MqttInfo mqttInfo, List<GateWayUserInfo> gateWayUserInfoList) {
+        if (ObjectUtils.isNotEmpty(mqttInfo) && ObjectUtils.isNotEmpty(gateWayUserInfoList)) {
+            try {
+                String urlStr = JMXUtil.buildServiceURL(mqttInfo);
+                JMXServiceURL url = new JMXServiceURL(urlStr);
+                @Cleanup JMXConnector connector = JMXConnectorFactory.connect(url, null);
+                connector.connect();
+                log.info("JMX removeMqttUsers {}:{} 连接成功...", mqttInfo.getJmxHost(), mqttInfo.getJmxPort());
+                MBeanServerConnection connection = connector.getMBeanServerConnection();
+                ObjectName addressObjectName = ObjectNameBuilder.create("org.apache.activemq.artemis", mqttInfo.getBrokerName()).getActiveMQServerObjectName();
+                ActiveMQServerControl addressControl = MBeanServerInvocationHandler.newProxyInstance(connection, addressObjectName, ActiveMQServerControl.class, false);
+
+                for (GateWayUserInfo gateWayUserInfo : gateWayUserInfoList) {
+                    try {
+                        String oldUserStr = addressControl.listUser(gateWayUserInfo.getUserName());
+                        if (JMXUtil.mqttUserIsExit(oldUserStr)) {
+                            addressControl.removeUser(gateWayUserInfo.getUserName());
+                        }
+                    } catch (Exception e) {
+                        log.error("removeMqttUsers: {}", e.getMessage());
+                    }
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                return;
+            }
+        }
+    }
+
     /**
      * 删除mqtt用户
      *
@@ -384,6 +459,13 @@ public class GateWayUserInfoService {
         return ResultContent.buildSuccess();
     }
 
+    public ResultContent syncSecurityToMQTTService(GateWayUserInfo gateWayUserInfo) {
+        if (ObjectUtils.isNotEmpty(gateWayUserInfo)) {
+
+        }
+        return ResultContent.buildSuccess();
+    }
+
     public ResultContent syncSecurityToMQTTService(List<GateWayInfo> gateWayInfos) {
         //todo同步权限
         List<MqttInfo> list = mqttInfoDao.findAll();
@@ -459,8 +541,7 @@ public class GateWayUserInfoService {
                             gateWayMqttSecurity.setMqttName(mqttInfo.getName());
                             gateWayMqttSecurity.setAddressMatch(addressMatch);
                             try {
-                                addressControl.addSecuritySettings(addressMatch, roleName, roleName, roleName,
-                                        roleName, roleName, roleName, roleName, roleName, roleName, roleName);
+                                addressControl.addSecuritySettings(addressMatch, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName);
 
                                 gateWayMqttSecurity.setIsSync(Boolean.TRUE);
                                 gateWayMqttSecurity.setMsg("同步成功");

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/MqttInfoService.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/MqttInfoService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.service.mqtt;
+package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.models.type.CommonState;
 import com.github.microservice.net.ResultContent;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/ProjectInfoService.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/ProjectInfoService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.service.mqtt;
+package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.models.type.CommonState;
 import com.zhongshu.iot.client.model.mqtt.ProjectInfoAddParam;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/mqtt/ServerTimeService.java → OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/device/ServerTimeService.java

@@ -1,4 +1,4 @@
-package com.zhongshu.iot.server.core.service.mqtt;
+package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.models.hxz.ServerTimeResult;
 import com.zhongshu.iot.server.core.domain.ExecuteAnnotationService;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/iot/IotTemplate2DeviceService.java

@@ -11,7 +11,7 @@ import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
 import com.zhongshu.iot.server.core.domain.iot.IotTemplate;
 import com.zhongshu.iot.server.core.domain.iot.IotTemplate2Device;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceInfo;
-import com.zhongshu.iot.server.core.service.mqtt.DeviceInfoService;
+import com.zhongshu.iot.server.core.service.device.DeviceInfoService;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;
 import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
 import lombok.extern.slf4j.Slf4j;

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

@@ -129,16 +129,20 @@ public class DeviceSyncFullCardService extends SuperService {
                 // 设备绑定的网关
                 List<GateWay2Device> gateWay2Devices = new ArrayList<>();
 
-                // 最新的
+                // 设备最新绑定 网关信息
                 GateWay2Device gateWay2Device = gateWay2DeviceDao.findTopByDeviceInfoOrderByUpdateTimeDesc(it);
                 gateWay2Devices.add(gateWay2Device);
 
                 List<String> gateWayIds = gateWay2Devices.stream().map(it2 -> {
                     return it2.getGateWayInfo().getGateWayId();
                 }).collect(Collectors.toList());
+                // 所属网关ID结合
                 syncParam.setGateWayId(String.join(",", gateWayIds));
                 // 项目code
                 syncParam.setProjectInfoCode(it.getProjectInfoCode());
+
+                // 封装设备关联物模型数据
+
                 return syncParam;
             }).collect(Collectors.toList());
         }

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/sync/ProjectFromFullCardService.java

@@ -2,7 +2,7 @@ package com.zhongshu.iot.server.core.service.sync;
 
 import com.github.microservice.models.project.ProjectSyncParam;
 import com.zhongshu.iot.client.model.mqtt.ProjectInfoAddParam;
-import com.zhongshu.iot.server.core.service.mqtt.ProjectInfoService;
+import com.zhongshu.iot.server.core.service.device.ProjectInfoService;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;
 import com.github.microservice.net.ResultContent;
 import lombok.extern.slf4j.Slf4j;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/service/user/impl/UserManagerServiceImpl.java

@@ -14,7 +14,7 @@ import com.zhongshu.iot.server.core.domain.user.Department;
 import com.zhongshu.iot.server.core.domain.user.Role;
 import com.zhongshu.iot.server.core.domain.user.User;
 import com.zhongshu.iot.server.core.service.base.SuperService;
-import com.zhongshu.iot.server.core.service.mqtt.ProjectInfoService;
+import com.zhongshu.iot.server.core.service.device.ProjectInfoService;
 import com.zhongshu.iot.server.core.util.ValidateResult;
 import com.zhongshu.iot.server.core.util.ValidateUtils;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;

+ 1 - 1
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/timers/CheckDeviceStateWork.java

@@ -1,6 +1,6 @@
 package com.zhongshu.iot.server.core.timers;
 
-import com.zhongshu.iot.server.core.service.mqtt.DevicePingInfoService;
+import com.zhongshu.iot.server.core.service.device.DevicePingInfoService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;

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

@@ -4,6 +4,7 @@ import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.DeviceInfo;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWayInfo;
+import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWayUserInfo;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.MqttInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.ObjectUtils;
@@ -78,4 +79,12 @@ public class JMXUtil {
         return list;
     }
 
+    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()));
+        }
+        return list;
+    }
+
 }