TRX 1 éve
szülő
commit
7c3b6ea9cc

+ 2 - 0
OneCardIotClient/src/main/java/com/zhongshu/iot/client/type/OperationLogBusType.java

@@ -7,6 +7,8 @@ import lombok.Getter;
  */
 public enum OperationLogBusType {
     Device("设备管理"),
+    Project("分组管理"),
+    GateWayUser("MQTT账号管理"),
     IotTemple("产品管理"),
     IotThing("物模型相关"),
     Common("通用"),

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

@@ -4,6 +4,7 @@ import com.github.microservice.busInfoModel.device.DeviceInfoModel;
 import com.github.microservice.busInfoModel.device.DeviceInfoMoreModel;
 import com.github.microservice.busInfoModel.device.DeviceInfoSimpleModel;
 import com.github.microservice.busInfoModel.device.IotTemplateSimpleModel;
+import com.github.microservice.models.device.DeviceIdsParam;
 import com.github.microservice.net.ResultContent;
 import com.github.microservice.net.ResultMessage;
 import com.github.microservice.types.FunctionType;
@@ -366,6 +367,9 @@ public class DeviceInfoService {
         // 设备信息改变时,更新 对应的物模型数据
         iotThingService.updateThingByDevice(deviceInfo);
 
+        // 同步删除设备信息
+        deviceSyncFullCardService.syncDeleteDeviceInfo(DeviceIdsParam.builder().deviceIds(List.of(deviceInfo.getDeviceId())).build());
+
         return ResultContent.buildSuccess();
     }
 

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

@@ -4,7 +4,7 @@ import com.github.microservice.net.ResultContent;
 import com.github.microservice.types.deviceUse.DeviceCategory;
 import com.zhongshu.card.client.model.base.IDParam;
 import com.zhongshu.iot.client.model.mqtt.*;
-import com.zhongshu.iot.client.type.type.LogsLevel;
+import com.zhongshu.iot.client.type.OperationLogBusType;
 import com.zhongshu.iot.client.type.type.MqttUserState;
 import com.zhongshu.iot.server.core.dao.mqtt.*;
 import com.zhongshu.iot.server.core.dataConfig.MqttConfig;
@@ -151,6 +151,7 @@ public class GateWayUserInfoService extends SuperService {
         if (ObjectUtils.isNotEmpty(ids)) {
             List<GateWayUserInfo> list = gateWayUserInfoDao.findByIdIn(ids);
             jmxSyncService.syncUserToMQTTService(list);
+
         }
         return ResultContent.buildSuccess();
     }
@@ -255,6 +256,8 @@ public class GateWayUserInfoService extends SuperService {
         }
         BeanUtils.copyProperties(param, entity);
         gateWayUserInfoDao.save(entity);
+
+        operationLogsService.addLogs(String.format("添加了账号:%s", entity.getUserName()), OperationLogBusType.GateWayUser, entity);
         return ResultContent.buildSuccess();
     }
 
@@ -270,9 +273,7 @@ public class GateWayUserInfoService extends SuperService {
         // 同步用户
         jmxSyncService.syncUserToMQTTService(entity);
 
-        // 添加日志
-        String userId = getCurrentUserId();
-        operationLogsService.addLogs(String.format("%s重置了 %s mqtt账号的密码", userId, entity.getUserName()), LogsLevel.High);
+        operationLogsService.addLogs(String.format("重置了【%s】mqtt账号的密码", entity.getUserName()), OperationLogBusType.GateWayUser);
         return ResultContent.buildSuccess();
     }
 
@@ -318,7 +319,7 @@ public class GateWayUserInfoService extends SuperService {
             return ResultContent.buildFail(String.format("账号不存在: %s", param.getUserName()));
         }
         if (param.getState() == entity.getState()) {
-            return ResultContent.buildFail(String.format("当前用户状态以为:%s", param.getState()));
+            return ResultContent.buildFail(String.format("当前账号状态已为:%s", param.getState()));
         }
         entity.setState(param.getState());
         gateWayUserInfoDao.save(entity);
@@ -327,9 +328,11 @@ public class GateWayUserInfoService extends SuperService {
         if (entity.getState() == MqttUserState.Disable) {
             // 不过不可用,则删除QMTT服务上的用户信息
             jmxSyncService.removeUserToMQTTService(entity);
+            operationLogsService.addLogs(String.format("停用了账号:%s", entity.getUserName()), OperationLogBusType.GateWayUser, entity);
         } else {
             // 添加用户
             jmxSyncService.syncUserToMQTTService(entity);
+            operationLogsService.addLogs(String.format("启用了账号:%s", entity.getUserName()), OperationLogBusType.GateWayUser, entity);
         }
         return ResultContent.buildSuccess();
     }
@@ -386,6 +389,8 @@ public class GateWayUserInfoService extends SuperService {
 
         // 删除服务文件上的用户
         jmxSyncService.removeUserToMQTTService(entity);
+
+        operationLogsService.addLogs(String.format("删除了连接账号:%s", entity.getUserName()), OperationLogBusType.GateWayUser, entity);
         return ResultContent.buildSuccess();
     }
 

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

@@ -7,10 +7,12 @@ import com.github.microservice.types.common.CommonState;
 import com.github.microservice.types.deviceUse.DeviceCategory;
 import com.zhongshu.iot.client.model.mqtt.ProjectInfoAddParam;
 import com.zhongshu.iot.client.model.mqtt.ProjectInfoSearchParam;
+import com.zhongshu.iot.client.type.OperationLogBusType;
 import com.zhongshu.iot.server.core.dao.mqtt.DeviceInfoDao;
 import com.zhongshu.iot.server.core.dao.mqtt.ProjectInfoDao;
 import com.zhongshu.iot.server.core.domain.iot.device.ProjectInfo;
 import com.zhongshu.iot.server.core.service.base.SuperService;
+import com.zhongshu.iot.server.core.service.user.OperationLogsService;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;
 import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
 import lombok.extern.slf4j.Slf4j;
@@ -34,11 +36,14 @@ import java.util.stream.Collectors;
 public class ProjectInfoService extends SuperService {
 
     @Autowired
-    ProjectInfoDao projectInfoDao;
+    private ProjectInfoDao projectInfoDao;
 
     @Autowired
     private DeviceInfoDao deviceInfoDao;
 
+    @Autowired
+    private OperationLogsService operationLogsService;
+
     /**
      * 添加项目
      *
@@ -58,6 +63,7 @@ public class ProjectInfoService extends SuperService {
             BeanUtils.copyProperties(param, projectInfo, "id", "createTime", "updateTime", "isDelete");
         }
         projectInfoDao.save(projectInfo);
+        operationLogsService.addLogs(String.format("编辑/添加了分组:%s", projectInfo.getCode()), OperationLogBusType.Project, projectInfo);
         return ResultContent.buildSuccess(projectInfo);
     }
 
@@ -93,6 +99,7 @@ public class ProjectInfoService extends SuperService {
             return ResultContent.buildFail(String.format("数据ID不存在: %s", id));
         }
         projectInfoDao.delete(projectInfo);
+        operationLogsService.addLogs(String.format("删除了分组:%s", projectInfo.getCode()), OperationLogBusType.Project, projectInfo);
         return ResultContent.buildSuccess();
     }
 

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

@@ -11,6 +11,7 @@ import com.github.microservice.types.deviceUse.DeviceSpecType;
 import com.github.microservice.types.deviceUse.ThingType;
 import com.zhongshu.iot.client.model.iot.*;
 import com.zhongshu.iot.client.type.IotDataType;
+import com.zhongshu.iot.client.type.OperationLogBusType;
 import com.zhongshu.iot.server.core.dao.UserDao;
 import com.zhongshu.iot.server.core.dao.iot.IotMainDao;
 import com.zhongshu.iot.server.core.dao.iot.IotTemplateDao;
@@ -23,6 +24,7 @@ import com.zhongshu.iot.server.core.domain.iot.device.DeviceInfo;
 import com.zhongshu.iot.server.core.domain.iot.device.GateWay2Device;
 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.user.OperationLogsService;
 import com.zhongshu.iot.server.core.util.CommonUtil;
 import com.zhongshu.iot.server.core.util.bean.BeanUtils;
 import com.zhongshu.iot.server.core.util.page.PageEntityUtil;
@@ -87,6 +89,9 @@ public class IotServiceImpl extends SuperService {
     @Autowired
     private IotThing2DeviceService iotThing2DeviceService;
 
+    @Autowired
+    private OperationLogsService operationLogsService;
+
     //----------------------------- 产品 start----------------------------
 
     /**
@@ -154,6 +159,8 @@ public class IotServiceImpl extends SuperService {
         }
         template.setProductCode(productCode);
         iotTemplateDao.save(template);
+
+        operationLogsService.addLogs(String.format("添加/编辑了产品:%s", template.getProductCode()), OperationLogBusType.IotTemple, template);
         return ResultContent.buildSuccess();
     }
 
@@ -196,6 +203,7 @@ public class IotServiceImpl extends SuperService {
         // 删除对应的  物模型 数据
         iotMainDao.deleteByIotTemplate(template);
 
+        operationLogsService.addLogs(String.format("删除了产品及其关联的物模型:%s", template.getProductCode()), OperationLogBusType.IotTemple, template);
         return ResultContent.buildSuccess();
     }
 

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

@@ -1,6 +1,7 @@
 package com.zhongshu.iot.server.core.service.sync;
 
 import com.github.microservice.http.APIResponseModel;
+import com.github.microservice.models.device.DeviceIdsParam;
 import com.github.microservice.models.device.DeviceInfoSyncParam;
 import com.github.microservice.models.device.DeviceSyncListParam;
 import com.github.microservice.models.hxz.DevicePingInfoParam;
@@ -152,6 +153,15 @@ public class DeviceSyncFullCardService extends SuperService {
         log.info("同步设备情况:{} {}", api.isSuccess(), api.getMsg());
     }
 
+    @Async
+    @SneakyThrows
+    public void syncDeleteDeviceInfo(DeviceIdsParam param) {
+        List<String> deviceIds = param.getDeviceIds();
+        log.info("event syncDeleteDeviceInfo: {}", deviceIds);
+        APIResponseModel api = apiRequestService.sendFullCardAPI(FullCardAPIConfig.deleteDevice, param);
+        log.info("同步删除设备情况:{} {}", api.isSuccess(), api.getMsg());
+    }
+
     public ResultContent noticeSyncDeviceOnlineStateChange(String deviceId) {
         if (ObjectUtils.isNotEmpty(deviceId)) {
             DeviceStateChangeEvent event = new DeviceStateChangeEvent(this, deviceId);