|
|
@@ -24,6 +24,7 @@ import com.xunmei.host.server.service.IotServerInfoService;
|
|
|
import com.xunmei.host.websocket.constant.WebSocketConstants;
|
|
|
import com.xunmei.host.websocket.dto.DeviceStatusInfo;
|
|
|
import com.xunmei.host.websocket.dto.WebsocketExecuteReq;
|
|
|
+import com.xunmei.host.websocket.dto.WebsocketResult;
|
|
|
import com.xunmei.host.websocket.dto.dvs.DvsBaseInfo;
|
|
|
import com.xunmei.host.websocket.dto.dvs.SubDeviceInfo;
|
|
|
import com.xunmei.host.websocket.enums.DeviceCacheEnum;
|
|
|
@@ -255,6 +256,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void deviceStatusChange(List<DeviceStatusInfo> statusInfos,IotServerInfo serverInfo) {
|
|
|
if (ObjectUtil.isEmpty(statusInfos)) {
|
|
|
return;
|
|
|
@@ -281,7 +283,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
public String routerKey() {
|
|
|
StringJoiner result = new StringJoiner(",");
|
|
|
//设备基础数据
|
|
|
- result.add(WebSocketConstants.GET_DEVICES);
|
|
|
+ result.add(WebSocketConstants.GET_DEVICES_SERVICES);
|
|
|
result.add(WebSocketConstants.DEVICES_EVENT);
|
|
|
//设备状态数据
|
|
|
result.add(WebSocketConstants.DEVICES_STATUS_EVENT);
|
|
|
@@ -301,7 +303,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
Object data = req.getData();
|
|
|
JSONArray dataArray = (JSONArray) data;
|
|
|
if (ObjectUtil.isEmpty(dataArray)) {
|
|
|
- return "";
|
|
|
+ return WebsocketResult.replySuccess(req.getTopic(),req.getId(), req.getProductName(), req.getDeviceName());
|
|
|
}
|
|
|
String token = req.getToken();
|
|
|
IotServerInfo serverInfo = iotServerInfoService.selectByToken(token);
|
|
|
@@ -312,14 +314,15 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
String event = req.getEvent();
|
|
|
switch (event) {
|
|
|
case WebSocketConstants.DEVICES_EVENT:
|
|
|
- case WebSocketConstants.GET_DEVICES:
|
|
|
+ case WebSocketConstants.GET_DEVICES_SERVICES:
|
|
|
List<DvsBaseInfo> dataList = dataArray.toJavaList(DvsBaseInfo.class);
|
|
|
String lockKey = LOCK_DEVICE_BASE_INFO + token;
|
|
|
String key = LOCK_ALARM_HOST_BASE_INFO + token;
|
|
|
-
|
|
|
- lockAndExecute(lockKey, () -> handleDvsAndFSUDeviceInfo(dataList, serverInfo));
|
|
|
- lockAndExecute(key, () -> handleAlarmHostDeviceInfo(dataList, serverInfo));
|
|
|
- break;
|
|
|
+ handleDvsAndFSUDeviceInfo(dataList, serverInfo);
|
|
|
+ handleAlarmHostDeviceInfo(dataList, serverInfo);
|
|
|
+ /*lockAndExecute(lockKey, () -> handleDvsAndFSUDeviceInfo(dataList, serverInfo));
|
|
|
+ lockAndExecute(key, () -> handleAlarmHostDeviceInfo(dataList, serverInfo));*/
|
|
|
+ return WebsocketResult.replySuccess(req.getTopic(),req.getId(), req.getProductName(), req.getDeviceName());
|
|
|
case WebSocketConstants.DEVICES_STATUS_EVENT:
|
|
|
List<DeviceStatusInfo> statusInfos = dataArray.toJavaList(DeviceStatusInfo.class);
|
|
|
deviceStatusChange(statusInfos,serverInfo);
|
|
|
@@ -331,7 +334,8 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private void handleAlarmHostDeviceInfo(List<DvsBaseInfo> dataList, IotServerInfo serverInfo) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void handleAlarmHostDeviceInfo(List<DvsBaseInfo> dataList, IotServerInfo serverInfo) {
|
|
|
List<DvsBaseInfo> alarmHostList = dataList.stream().filter(r -> ObjectUtil.equal(r.getType(), BaseDeviceTypeEnum.AlarmHost.name())).collect(Collectors.toList());
|
|
|
if (ObjectUtil.isEmpty(alarmHostList)) {
|
|
|
return;
|
|
|
@@ -422,7 +426,7 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
saveOrUpdateBatches(addSubSystemList, updateSubSystemList, addDefenceAreaList, updateDefenceAreaList, addExtendList, updateExtendList);
|
|
|
}
|
|
|
|
|
|
- private void lockAndExecute(String lockKey, Runnable action) {
|
|
|
+ public void lockAndExecute(String lockKey, Runnable action) {
|
|
|
//String lockKey = LOCK_ACCPET_KEY_PREFIX + token;
|
|
|
RLock lock = RedisUtils.getClient().getLock(lockKey);
|
|
|
try {
|
|
|
@@ -444,7 +448,8 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void handleDvsAndFSUDeviceInfo(List<DvsBaseInfo> dataList, IotServerInfo serverInfo) {
|
|
|
+ @Transactional
|
|
|
+ public void handleDvsAndFSUDeviceInfo(List<DvsBaseInfo> dataList, IotServerInfo serverInfo) {
|
|
|
|
|
|
//逻辑删除所有设备
|
|
|
deleteDeviceByToken(serverInfo.getIotCode());
|