Bladeren bron

更新!

TRX 1 jaar geleden
bovenliggende
commit
83a90229fa

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

@@ -2,14 +2,15 @@ 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.github.microservice.types.FunctionType;
 import com.zhongshu.iot.client.model.iot.IotMainModel;
 import com.zhongshu.iot.client.model.mqtt.DeviceInfoAddParam;
 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.client.openApi.base.DeviceIdParam;
 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;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -53,13 +54,19 @@ public class DeviceController {
     public ResultContent<Page<DeviceInfoModel>> pageActivity(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) DeviceInfoSearchParam param) {
         return deviceInfoService.pageDevice(pageable, param);
     }
+
     @ResourceAuth(value = "user", type = AuthType.User)
     @Operation(summary = "删除设备")
-    @RequestMapping(value = "deleteDeviceInfo", method = {RequestMethod.GET})
-    public ResultContent deleteDeviceInfo(
-            @Parameter(name = "deviceId", description = "数据ID", example = "")
-            @RequestParam("deviceId") String deviceId) {
-        return deviceInfoService.deleteDeviceInfo(deviceId);
+    @RequestMapping(value = "deleteDeviceInfo", method = {RequestMethod.POST})
+    public ResultContent deleteDeviceInfo(@RequestBody DeviceIdParam param) {
+        return deviceInfoService.deleteDeviceInfo(param.getDeviceId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "注销设备")
+    @RequestMapping(value = "cancelDeviceInfo", method = {RequestMethod.POST})
+    public ResultContent cancelDeviceInfo(@RequestBody DeviceIdParam param) {
+        return deviceInfoService.cancelDeviceInfo(param.getDeviceId());
     }
 
     @ResourceAuth(value = "user", type = AuthType.User)

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

@@ -19,6 +19,6 @@ public interface DeviceInfoDao extends DeviceInfoDaoExtend, org.springframework.
 
     List<DeviceInfo> findByDeviceIdIn(List<String> deviceIds);
 
-    long countByMqttUserName(String mqttUserName);
+    long countByMqttUserNameAndIsDelete(String mqttUserName, Boolean isDelete);
 
 }

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

@@ -17,5 +17,5 @@ public interface GateWayInfoDao extends GateWayInfoDaoExtend, org.springframewor
 
     List<GateWayInfo> findByGateWayIdIn(List<String> gateWayIds);
 
-    long countByMqttUserName(String mqttUserName);
+    long countByMqttUserNameAndIsDelete(String mqttUserName, Boolean isDelete);
 }

+ 1 - 0
OneCardIotServer/src/main/java/com/zhongshu/iot/server/core/dao/mqtt/impl/DeviceInfoDaoImpl.java

@@ -66,6 +66,7 @@ public class DeviceInfoDaoImpl extends BaseImpl implements DeviceInfoDaoExtend {
             criteria.andOperator(criterias.toArray(new Criteria[]{}));
         }
         criteria.and("isDelete").is(Boolean.FALSE);
+
         Sort sort = buildSort(param);
         Query query = Query.query(criteria);
         query.with(sort);

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

@@ -47,4 +47,7 @@ public class GateWayUserInfo extends SuperEntity {
 
     @Schema(description = "是否显示")
     private Boolean isShow = Boolean.TRUE;
+
+    @Schema(description = "最后修改密码时间")
+    private String lastUpdatePassWord;
 }

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

@@ -1,5 +1,6 @@
 package com.zhongshu.iot.server.core.service.device;
 
+import com.github.microservice.models.type.DeviceState;
 import com.github.microservice.models.type.OnLineState;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.FunctionType;
@@ -85,10 +86,13 @@ public class DeviceInfoService {
         DeviceInfo deviceInfo = new DeviceInfo();
         DeviceInfo temp = deviceInfoDao.findTopByDeviceId(param.getDeviceId());
         if (ObjectUtils.isNotEmpty(temp)) {
+            // 编辑
             deviceInfo = temp;
             param.setId(null);
         } else {
+            // 添加
             deviceInfo.setActivityTime(System.currentTimeMillis());
+            deviceInfo.setState(DeviceState.Enable);
         }
         BeanUtils.copyProperties(param, deviceInfo, "id");
         deviceInfo.setLastOnlineTime(System.currentTimeMillis());
@@ -103,11 +107,11 @@ public class DeviceInfoService {
         deviceInfo.setLastOnlineTime(System.currentTimeMillis());
         deviceInfoDao.save(deviceInfo);
 
-
         DeviceInfo finalDeviceInfo = deviceInfo;
         CompletableFuture.runAsync(() -> {
             // 日志
             operationLogsService.addLogs(String.format("添加了设备;%s", finalDeviceInfo.getDeviceName()), LogsLevel.Middle, finalDeviceInfo);
+
             // 跟新账号的绑定设备数量
             gateWayUserInfoService.updateBindNumber(finalDeviceInfo.getMqttUserName());
 
@@ -213,7 +217,16 @@ public class DeviceInfoService {
         }
         deviceInfo.setState(param.getState());
         deviceInfoDao.save(deviceInfo);
+
+        // 通知设备在线状态变化
         deviceSyncFullCardService.noticeSyncDeviceOnlineStateChange(deviceInfo.getDeviceId());
+
+        // 更新设备权限
+        jmxSyncService.syncDevicesSecurity(List.of(deviceInfo));
+
+        // 同步显示信息
+        deviceSyncFullCardService.noticeSyncDevice(List.of(deviceInfo));
+
         return ResultContent.buildSuccess();
     }
 
@@ -260,8 +273,45 @@ public class DeviceInfoService {
         if (ObjectUtils.isEmpty(deviceInfo)) {
             return ResultContent.buildFail(String.format("设备ID不存在:%s", deviceId));
         }
-        deviceInfoDao.delete(deviceInfo);
+        deviceInfo.setIsDelete(Boolean.TRUE);
+        deviceInfoDao.save(deviceInfo);
+
         operationLogsService.addLogs(String.format("删除了设备;%s", deviceInfo.getDeviceName()), LogsLevel.High, deviceInfo);
+
+        // 更新设备信息
+        deviceSyncFullCardService.noticeSyncDevice(List.of(deviceInfo));
+
+        // 更新账号的绑定设备数量
+        gateWayUserInfoService.updateBindNumber(deviceInfo.getMqttUserName());
+
+        // 更新设备权限
+        jmxSyncService.syncDevicesSecurity(List.of(deviceInfo));
+
+        return ResultContent.buildSuccess();
+    }
+
+    /**
+     * 注销设备
+     *
+     * @param deviceId
+     * @return
+     */
+    public ResultContent cancelDeviceInfo(String deviceId) {
+        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
+        if (ObjectUtils.isEmpty(deviceInfo)) {
+            return ResultContent.buildFail(String.format("设备ID不存在:%s", deviceId));
+        }
+        deviceInfo.setState(DeviceState.Cancel);
+        deviceInfoDao.save(deviceInfo);
+
+        // 更新设备信息
+        deviceSyncFullCardService.noticeSyncDevice(List.of(deviceInfo));
+
+        // 更新设备权限
+        jmxSyncService.syncDevicesSecurity(List.of(deviceInfo));
+
+        operationLogsService.addLogs(String.format("注销了设备;%s", deviceInfo.getDeviceName()), LogsLevel.High, deviceInfo);
+        // 回收权限
         return ResultContent.buildSuccess();
     }
 

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

@@ -244,6 +244,7 @@ public class GateWayUserInfoService {
             return ResultContent.buildFail("数据不存在");
         }
         entity.setPassWord(CommonUtil.generateRandomString(16));
+        entity.setLastUpdatePassWord(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
         gateWayUserInfoDao.save(entity);
 
         // 同步用户
@@ -318,9 +319,10 @@ public class GateWayUserInfoService {
     public ResultContent updateBindNumber(GateWayUserInfo entity) {
         if (ObjectUtils.isNotEmpty(entity)) {
             // 网关数量
-            long gatewayNumber = gateWayInfoDao.countByMqttUserName(entity.getUserName());
+            long gatewayNumber = gateWayInfoDao.countByMqttUserNameAndIsDelete(entity.getUserName(), Boolean.FALSE);
             // 设备数量
-            long deviceNumber = deviceInfoDao.countByMqttUserName(entity.getUserName());
+            long deviceNumber = deviceInfoDao.countByMqttUserNameAndIsDelete(entity.getUserName(), Boolean.FALSE);
+
             long bindNumber = gatewayNumber + deviceNumber;
             entity.setGatewayNumber(gatewayNumber);
             entity.setDeviceNumber(deviceNumber);

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

@@ -1,5 +1,6 @@
 package com.zhongshu.iot.server.core.service.device;
 
+import com.github.microservice.models.type.DeviceState;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.iot.server.core.dao.mqtt.*;
 import com.zhongshu.iot.server.core.dataConfig.MqttConfig;
@@ -454,7 +455,11 @@ public class JMXSyncService {
                         roleName = JMXUtil.buildSecurityRoleName(roleName);
                         for (String addressMatch : addressMatchs) {
                             try {
-                                addressControl.addSecuritySettings(addressMatch, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName);
+                                if (deviceInfo.getState() == DeviceState.Enable) {
+                                    addressControl.addSecuritySettings(addressMatch, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName, roleName);
+                                } else {
+                                    addressControl.removeSecuritySettings(addressMatch);
+                                }
                             } catch (Exception e) {
                                 e.printStackTrace();
                             }