增加移除离线设备的功能

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

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