From 7ba2f3c529ee0e34caa94f478e7de636930bf122 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Fri, 16 Apr 2021 10:59:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=BB=E9=99=A4=E7=A6=BB?= =?UTF-8?q?=E7=BA=BF=E8=AE=BE=E5=A4=87=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmp/media/zlm/ZLMHttpHookListener.java | 2 +- .../iot/vmp/storager/IRedisCatchStorage.java | 5 +++++ .../storager/dao/PlatformChannelMapper.java | 5 +++++ .../storager/impl/RedisCatchStorageImpl.java | 18 ++++++++++++++++ .../impl/VideoManagerStoragerImpl.java | 21 ++++++++++++++++--- .../vmanager/gb28181/device/DeviceQuery.java | 6 ++++++ web_src/src/components/DeviceList.vue | 21 +++++++++++++++---- 7 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 7db57148..2a76f26a 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -340,7 +340,7 @@ public class ZLMHttpHookListener { String app = json.getString("app"); String streamId = json.getString("stream"); StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); - if ("rtp".equals(app) && streamId.indexOf("gb_play") > -1 && streamInfo == null) { + if ("rtp".equals(app) && streamId.contains("gb_play") && streamInfo == null) { String[] s = streamId.split("_"); if (s.length == 4) { String deviceId = s[2]; diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java index c1b42bca..d0d07f79 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java @@ -104,4 +104,9 @@ public interface IRedisCatchStorage { */ boolean isChannelSendingRTP(String channelId); + /** + * 清空某个设备的所有缓存 + * @param deviceId 设备ID + */ + void clearCatchByDeviceId(String deviceId); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java index db2bb777..1781a4af 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java @@ -37,6 +37,11 @@ public interface PlatformChannelMapper { "") int delChannelForGB(String platformId, List channelReducesToDel); + @Delete("") + int delChannelForDeviceId(String deviceId); + @Delete("") diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java index d1d6d202..3417acf8 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java @@ -259,4 +259,22 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { } } + @Override + public void clearCatchByDeviceId(String deviceId) { + List playLeys = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, + deviceId)); + if (playLeys.size() > 0) { + for (Object key : playLeys) { + redis.del(key.toString()); + } + } + + List playBackers = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, + deviceId)); + if (playBackers.size() > 0) { + for (Object key : playBackers) { + redis.del(key.toString()); + } + } + } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java index 472c7fda..770fa5ae 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java @@ -195,9 +195,22 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { */ @Override public boolean delete(String deviceId) { - int result = deviceMapper.del(deviceId); - - return result > 0; + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); + boolean result = false; + try { + if (platformChannelMapper.delChannelForDeviceId(deviceId) <0 // 删除与国标平台的关联 + || deviceChannelMapper.cleanChannelsByDeviceId(deviceId) < 0 // 删除他的通道 + || deviceMapper.del(deviceId) < 0 // 移除设备信息 + ) { + //事务回滚 + dataSourceTransactionManager.rollback(transactionStatus); + } + result = true; + dataSourceTransactionManager.commit(transactionStatus); //手动提交 + }catch (Exception e) { + dataSourceTransactionManager.rollback(transactionStatus); + } + return result; } /** @@ -550,4 +563,6 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { public void mediaOutline(String app, String streamId) { gbStreamMapper.setStatus(app, streamId, false); } + + } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java index e243d23e..c40a493e 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.github.pagehelper.PageInfo; import io.swagger.annotations.*; import org.slf4j.Logger; @@ -33,6 +34,9 @@ public class DeviceQuery { @Autowired private IVideoManagerStorager storager; + + @Autowired + private IRedisCatchStorage redisCatchStorage; @Autowired private SIPCommander cmder; @@ -177,8 +181,10 @@ public class DeviceQuery { if (offLineDetector.isOnline(deviceId)) { return new ResponseEntity("不允许删除在线设备!", HttpStatus.NOT_ACCEPTABLE); } + // 清除redis记录 boolean isSuccess = storager.delete(deviceId); if (isSuccess) { + redisCatchStorage.clearCatchByDeviceId(deviceId); JSONObject json = new JSONObject(); json.put("deviceId", deviceId); return new ResponseEntity<>(json.toString(),HttpStatus.OK); diff --git a/web_src/src/components/DeviceList.vue b/web_src/src/components/DeviceList.vue index cdc25bcb..38a063e9 100644 --- a/web_src/src/components/DeviceList.vue +++ b/web_src/src/components/DeviceList.vue @@ -51,11 +51,12 @@ @@ -155,6 +156,18 @@ }); }, + deleteDevice: function(row) { + let that = this; + this.$axios({ + method: 'delete', + url:`/api/device/query/devices/${row.deviceId}/delete` + }).then((res)=>{ + this.getDeviceList(); + }).catch((error) =>{ + console.log(error); + }); + + }, showChannelList: function(row) { console.log(JSON.stringify(row)) this.$router.push(`/channelList/${row.deviceId}/0/15/1`);