增加移除离线设备的功能

This commit is contained in:
panlinlin
2021-04-16 10:59:26 +08:00
parent 937e591430
commit f1fae7aac6
7 changed files with 70 additions and 8 deletions

View File

@@ -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];

View File

@@ -104,4 +104,9 @@ public interface IRedisCatchStorage {
*/
boolean isChannelSendingRTP(String channelId);
/**
* 清空某个设备的所有缓存
* @param deviceId 设备ID
*/
void clearCatchByDeviceId(String deviceId);
}

View File

@@ -37,6 +37,11 @@ public interface PlatformChannelMapper {
"</script>")
int delChannelForGB(String platformId, List<ChannelReduce> channelReducesToDel);
@Delete("<script> "+
"DELETE FROM platform_gb_channel WHERE deviceId='${deviceId}' " +
"</script>")
int delChannelForDeviceId(String deviceId);
@Delete("<script> "+
"DELETE FROM platform_gb_channel WHERE platformId='${platformId}'" +
"</script>")

View File

@@ -259,4 +259,22 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
}
}
@Override
public void clearCatchByDeviceId(String deviceId) {
List<Object> playLeys = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAYER_PREFIX,
deviceId));
if (playLeys.size() > 0) {
for (Object key : playLeys) {
redis.del(key.toString());
}
}
List<Object> playBackers = redis.scan(String.format("%S_*_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX,
deviceId));
if (playBackers.size() > 0) {
for (Object key : playBackers) {
redis.del(key.toString());
}
}
}
}

View File

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

View File

@@ -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<String>("不允许删除在线设备!", 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);