TRX 1 rok temu
rodzic
commit
395c043f76

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

@@ -24,6 +24,12 @@ public class GateWayUserInfoModel extends SuperModel {
     @Schema(description = "用户状态:可用不可用")
     private MqttUserState state;
 
+    @Schema(description = "分组code")
+    private String projectCode;
+
+    @Schema(description = "项目名称")
+    private String projectName;
+
     @Schema(description = "最大设备数量(网关也算一个设备)")
     private Long number = 0L;
 

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

@@ -17,4 +17,6 @@ public class GateWayUserInfoParam {
     @Schema(description = "最大的可绑定的设备数")
     private Long number;
 
+    @Schema(description = "分组code")
+    private String projectCode;
 }

+ 19 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/model/mqtt/GateWayUserInfoResetPasswordParam.java

@@ -0,0 +1,19 @@
+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 GateWayUserInfoResetPasswordParam {
+    @Schema(description = "数据ID")
+    private String id;
+
+}

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

@@ -3,6 +3,7 @@ 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.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.base.IDParam;
 import com.zhongshu.iot.client.model.mqtt.*;
 import com.zhongshu.iot.server.core.service.device.GateWayUserInfoService;
 import io.swagger.v3.oas.annotations.Operation;
@@ -35,7 +36,7 @@ public class GateWayUserInfoController {
     GateWayUserInfoService gateWayUserInfoService;
 
     @ResourceAuth(value = "user", type = AuthType.User)
-    @Operation(summary = "添加连接用户")
+    @Operation(summary = "创建连接用户")
     @RequestMapping(value = "createUser", method = {RequestMethod.POST})
     public ResultContent createUser(@RequestBody GateWayUserInfoParam param) {
         return gateWayUserInfoService.createUser(param);
@@ -48,20 +49,17 @@ public class GateWayUserInfoController {
         return gateWayUserInfoService.update(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 = "resetPassWord", method = {RequestMethod.POST})
+    public ResultContent resetPassWord(@RequestBody IDParam param) {
+        return gateWayUserInfoService.resetPassWord(param);
+    }
 
     @ResourceAuth(value = "user", type = AuthType.User)
     @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, sort = "") Pageable pageable, @Parameter(required = false) GateWayUserInfoSearchParam param) {
         return gateWayUserInfoService.pageGateWayUser(pageable, param);
     }
 

+ 3 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/DeviceInfoDao.java

@@ -18,4 +18,7 @@ public interface DeviceInfoDao extends DeviceInfoDaoExtend, org.springframework.
     DeviceInfo findTopByDeviceIdAndProjectInfoCode(String deviceId, String projectInfoCode);
 
     List<DeviceInfo> findByDeviceIdIn(List<String> deviceIds);
+
+    long countByMqttUserName(String mqttUserName);
+
 }

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

@@ -16,4 +16,6 @@ public interface GateWayInfoDao extends GateWayInfoDaoExtend, org.springframewor
     GateWayInfo findTopByGateWayId(String gateWayId);
 
     List<GateWayInfo> findByGateWayIdIn(List<String> gateWayIds);
+
+    long countByMqttUserName(String mqttUserName);
 }

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

@@ -27,6 +27,9 @@ public class GateWayUserInfo extends SuperEntity {
     @Schema(description = "用户权限角色名称,一般和 userName 相同")
     private String roleName;
 
+    @Schema(description = "分组code")
+    private String projectCode;
+
     @Schema(description = "用户状态:可用不可用")
     private MqttUserState state;
 

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

@@ -409,8 +409,8 @@ public class OperationMessageService {
                 String methodName = executeMethodInfo.getMethodName();
                 Class c = applicationContext.getBean(beanName).getClass();
                 SuperService t = (SuperService) applicationContext.getBean(beanName);
-                Method method = c.getMethod(methodName, String.class);
-                ResultContent<Object> resultContent = (ResultContent<Object>) method.invoke(t, dataStr);
+                Method method = c.getMethod(methodName, String.class, String.class);
+                ResultContent<Object> resultContent = (ResultContent<Object>) method.invoke(t, entity.getDataId(), dataStr);
                 if (resultContent.isSuccess()) {
                     isHandleSuccess = true;
                     handleMsg = "处理成功";

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

@@ -81,6 +81,9 @@ public class GateWayInfoService extends SuperService {
     @Autowired
     private JMXSyncService jmxSyncService;
 
+    @Autowired
+    private OperationMessageDao operationMessageDao;
+
     /**
      * 注册 网关
      *
@@ -89,7 +92,10 @@ public class GateWayInfoService extends SuperService {
      */
     public ResultContent<Object> gateWayRegister(String dataId, String dataStr) {
         CommonResult commonResult = new CommonResult();
-
+        OperationMessage operationMessage = operationMessageDao.findTopByDataId(dataId);
+        if (ObjectUtils.isEmpty(operationMessage)) {
+            return ResultContent.buildFail("数据不存在");
+        }
 
         return ResultContent.buildSuccess(commonResult);
     }

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

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.server.core.service.device;
 
 import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.base.IDParam;
 import com.zhongshu.iot.client.model.mqtt.*;
 import com.zhongshu.iot.client.type.type.MqttUserState;
 import com.zhongshu.iot.server.core.dao.mqtt.*;
@@ -8,6 +9,7 @@ import com.zhongshu.iot.server.core.dataConfig.MqttConfig;
 import com.zhongshu.iot.server.core.domain.iot.mqtt.GateWay2User;
 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.ProjectInfo;
 import com.zhongshu.iot.server.core.util.CommonUtil;
 import com.zhongshu.iot.server.core.util.DateUtils;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;
@@ -54,6 +56,12 @@ public class GateWayUserInfoService {
     @Autowired
     private JMXSyncService jmxSyncService;
 
+    @Autowired
+    private ProjectInfoDao projectInfoDao;
+
+    @Autowired
+    private DeviceInfoDao deviceInfoDao;
+
     /**
      * 刷新系统所有的用户 和 用户权限数据
      */
@@ -163,7 +171,16 @@ public class GateWayUserInfoService {
         }
         BeanUtils.copyProperties(param, entity);
         gateWayUserInfoDao.save(entity);
+        return ResultContent.buildSuccess();
+    }
 
+    public ResultContent resetPassWord(IDParam param) {
+        GateWayUserInfo entity = gateWayUserInfoDao.findTopById(param.getId());
+        if (ObjectUtils.isEmpty(entity)) {
+            return ResultContent.buildFail("数据不存在");
+        }
+        entity.setPassWord(CommonUtil.generateRandomString(16));
+        gateWayUserInfoDao.save(entity);
         return ResultContent.buildSuccess();
     }
 
@@ -233,11 +250,22 @@ public class GateWayUserInfoService {
      */
     public ResultContent updateBindNumber(GateWayUserInfo entity) {
         if (ObjectUtils.isNotEmpty(entity)) {
-
+            entity.setBindNumber(countBindNumber(entity));
         }
         return ResultContent.buildSuccess();
     }
 
+    public long countBindNumber(GateWayUserInfo entity) {
+        if (ObjectUtils.isNotEmpty(entity) && StringUtils.isNotEmpty(entity.getUserName())) {
+            // 网关数量
+            long gatewayNumber = gateWayInfoDao.countByMqttUserName(entity.getUserName());
+            // 设备数量
+            long deviceNumber = deviceInfoDao.countByMqttUserName(entity.getUserName());
+            return gatewayNumber + deviceNumber;
+        }
+        return 0;
+    }
+
     /**
      * 删除mqtt用户信息
      *
@@ -287,6 +315,14 @@ public class GateWayUserInfoService {
         GateWayUserInfoModel model = new GateWayUserInfoModel();
         if (ObjectUtils.isNotEmpty(entity)) {
             BeanUtils.copyProperties(entity, model);
+            String projectName = "";
+            if (StringUtils.isNotEmpty(entity.getProjectCode())) {
+                ProjectInfo projectInfo = projectInfoDao.findTopByCode(entity.getProjectCode());
+                if (ObjectUtils.isNotEmpty(projectInfo)) {
+                    projectName = projectInfo.getName();
+                }
+            }
+            model.setProjectName(projectName);
         }
         return model;
     }