临时提交

This commit is contained in:
648540858
2025-05-28 22:32:14 +08:00
parent a40446e42b
commit 58e82ec185
4 changed files with 72 additions and 45 deletions

View File

@@ -223,7 +223,7 @@ public class DeviceQuery {
if (exist) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备编号已存在");
}
deviceService.addDevice(device);
deviceService.addCustomDevice(device);
}

View File

@@ -225,6 +225,7 @@ public interface DeviceMapper {
"on_line"+
" FROM wvp_device WHERE on_line = true")
List<Device> getOnlineDevices();
@Select("SELECT " +
"id, " +
"device_id, " +
@@ -414,4 +415,12 @@ public interface DeviceMapper {
" WHERE id=#{id}"+
" </script>"})
void updateSubscribeMobilePosition(Device device);
@Update(value = {" <script>" +
"UPDATE wvp_device " +
"SET on_line=false" +
" WHERE id in"+
"<foreach collection='offlineDevices' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
" </script>"})
void offlineByList(List<Device> offlineDevices);
}

View File

@@ -128,7 +128,7 @@ public interface IDeviceService {
* 添加设备
* @param device
*/
void addDevice(Device device);
void addCustomDevice(Device device);
/**
* 页面表单更新设备信息

View File

@@ -142,19 +142,23 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
// 除了记录的设备以外, 其他设备全部离线
List<Device> onlineDevice = getAllOnlineDevice(userSetting.getServerId());
if (!onlineDevice.isEmpty()) {
List<Device> offlineDevices = new ArrayList<>();
for (Device device : onlineDevice) {
if (!onlineDeviceIds.contains(device.getDeviceId())) {
// 此设备需要离线
// 清理订阅
device.setOnLine(false);
// 清理离线设备的相关缓存
cleanOfflineDevice(device);
// 更新数据库
offlineDevices.add(device);
}
}
if (!offlineDevices.isEmpty()) {
offlineByIds(offlineDevices);
}
}
}
// 处理订阅任务
List<SubscribeTaskInfo> taskInfoList = subscribeTaskRunner.getAllTaskInfo();
if (!taskInfoList.isEmpty()) {
@@ -184,6 +188,56 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
}
}
private void offlineByIds(List<Device> offlineDevices) {
if (offlineDevices.isEmpty()) {
log.info("[更新多个离线设备信息] 参数为空");
return;
}
deviceMapper.offlineByList(offlineDevices);
for (Device device : offlineDevices) {
device.setOnLine(false);
redisCatchStorage.updateDevice(device);
}
}
private void cleanOfflineDevice(Device device) {
if (subscribeTaskRunner.containsKey(SubscribeTaskForCatalog.getKey(device))) {
subscribeTaskRunner.removeSubscribe(SubscribeTaskForCatalog.getKey(device));
}
if (subscribeTaskRunner.containsKey(SubscribeTaskForMobilPosition.getKey(device))) {
subscribeTaskRunner.removeSubscribe(SubscribeTaskForMobilPosition.getKey(device));
}
//进行通道离线
// deviceChannelMapper.offlineByDeviceId(deviceId);
// 离线释放所有ssrc
List<SsrcTransaction> ssrcTransactions = sessionManager.getSsrcTransactionByDeviceId(device.getDeviceId());
if (ssrcTransactions != null && !ssrcTransactions.isEmpty()) {
for (SsrcTransaction ssrcTransaction : ssrcTransactions) {
mediaServerService.releaseSsrc(ssrcTransaction.getMediaServerId(), ssrcTransaction.getSsrc());
mediaServerService.closeRTPServer(ssrcTransaction.getMediaServerId(), ssrcTransaction.getStream());
sessionManager.removeByCallId(ssrcTransaction.getCallId());
}
}
// 移除订阅
removeCatalogSubscribe(device, null);
removeMobilePositionSubscribe(device, null);
List<AudioBroadcastCatch> audioBroadcastCatches = audioBroadcastManager.getByDeviceId(device.getDeviceId());
if (!audioBroadcastCatches.isEmpty()) {
for (AudioBroadcastCatch audioBroadcastCatch : audioBroadcastCatches) {
SendRtpInfo sendRtpItem = sendRtpServerService.queryByChannelId(audioBroadcastCatch.getChannelId(), device.getDeviceId());
if (sendRtpItem != null) {
sendRtpServerService.delete(sendRtpItem);
MediaServer mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
mediaServerService.stopSendRtp(mediaInfo, sendRtpItem.getApp(), sendRtpItem.getStream(), null);
}
audioBroadcastManager.del(audioBroadcastCatch.getChannelId());
}
}
}
private void deviceStatusExpire(String deviceId, SipTransactionInfo transactionInfo) {
log.info("[设备状态] 到期, 编号: {}", deviceId);
offline(deviceId, "");
@@ -223,6 +277,7 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
device.setCreateTime(now);
device.setUpdateTime(now);
log.info("[设备上线,首次注册]: {},查询设备信息以及通道信息", device.getDeviceId());
addCustomDevice(device);
deviceMapper.add(device);
redisCatchStorage.updateDevice(device);
try {
@@ -297,47 +352,10 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
}
log.info("[设备离线] {}, device{} 心跳间隔: {},心跳超时次数: {} 上次心跳时间:{} 上次注册时间: {}", reason, deviceId,
device.getHeartBeatInterval(), device.getHeartBeatCount(), device.getKeepaliveTime(), device.getRegisterTime());
String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + deviceId;
dynamicTask.stop(registerExpireTaskKey);
if (device.isOnLine()) {
if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), null, false);
}
}
device.setOnLine(false);
cleanOfflineDevice(device);
redisCatchStorage.updateDevice(device);
deviceMapper.update(device);
//进行通道离线
// deviceChannelMapper.offlineByDeviceId(deviceId);
// 离线释放所有ssrc
List<SsrcTransaction> ssrcTransactions = sessionManager.getSsrcTransactionByDeviceId(deviceId);
if (ssrcTransactions != null && !ssrcTransactions.isEmpty()) {
for (SsrcTransaction ssrcTransaction : ssrcTransactions) {
mediaServerService.releaseSsrc(ssrcTransaction.getMediaServerId(), ssrcTransaction.getSsrc());
mediaServerService.closeRTPServer(ssrcTransaction.getMediaServerId(), ssrcTransaction.getStream());
sessionManager.removeByCallId(ssrcTransaction.getCallId());
}
}
// 移除订阅
removeCatalogSubscribe(device, null);
removeMobilePositionSubscribe(device, null);
List<AudioBroadcastCatch> audioBroadcastCatches = audioBroadcastManager.getByDeviceId(deviceId);
if (!audioBroadcastCatches.isEmpty()) {
for (AudioBroadcastCatch audioBroadcastCatch : audioBroadcastCatches) {
SendRtpInfo sendRtpItem = sendRtpServerService.queryByChannelId(audioBroadcastCatch.getChannelId(), deviceId);
if (sendRtpItem != null) {
sendRtpServerService.delete(sendRtpItem);
MediaServer mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
mediaServerService.stopSendRtp(mediaInfo, sendRtpItem.getApp(), sendRtpItem.getStream(), null);
}
audioBroadcastManager.del(audioBroadcastCatch.getChannelId());
}
}
}
// 订阅丢失检查
@@ -621,7 +639,7 @@ public class DeviceServiceImpl implements IDeviceService, CommandLineRunner {
}
@Override
public void addDevice(Device device) {
public void addCustomDevice(Device device) {
device.setOnLine(false);
device.setCreateTime(DateUtil.getNow());
device.setUpdateTime(DateUtil.getNow());