|
|
@@ -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();
|
|
|
}
|
|
|
|