diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java index 1e783e86..8d673dbc 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java @@ -195,4 +195,7 @@ public class Device { @Schema(description = "控制语音对讲流程,释放收到ACK后发流") private boolean broadcastPushAfterAck; + + @Schema(description = "所属服务Id") + private String serverId; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java index e7a8b1c8..003478f9 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PlayController.java @@ -88,9 +88,12 @@ public class PlayController { Assert.notNull(channelId, "通道国标编号不可为NULL"); // 获取可用的zlm Device device = deviceService.getDeviceByDeviceId(deviceId); + Assert.notNull(deviceId, "设备不存在"); DeviceChannel channel = deviceChannelService.getOne(deviceId, channelId); Assert.notNull(channel, "通道不存在"); + + MediaServer newMediaServerItem = playService.getNewMediaServerItem(device); RequestMessage requestMessage = new RequestMessage(); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceMapper.java index abac64bb..07b18676 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/DeviceMapper.java @@ -78,6 +78,7 @@ public interface DeviceMapper { "as_message_channel,"+ "broadcast_push_after_ack,"+ "geo_coord_sys,"+ + "server_id,"+ "on_line"+ ") VALUES (" + "#{deviceId}," + @@ -108,6 +109,7 @@ public interface DeviceMapper { "#{asMessageChannel}," + "#{broadcastPushAfterAck}," + "#{geoCoordSys}," + + "#{serverId}," + "#{onLine}" + ")") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @@ -130,6 +132,7 @@ public interface DeviceMapper { ", keepalive_time=#{keepaliveTime}" + ", keepalive_interval_time=#{keepaliveIntervalTime}" + ", expires=#{expires}" + + ", server_id=#{serverId}" + "WHERE device_id=#{deviceId}"+ " "}) int update(Device device); @@ -207,9 +210,43 @@ public interface DeviceMapper { "as_message_channel,"+ "broadcast_push_after_ack,"+ "geo_coord_sys,"+ + "server_id,"+ "on_line"+ " FROM wvp_device WHERE on_line = true") List getOnlineDevices(); + @Select("SELECT " + + "id, " + + "device_id, " + + "coalesce(custom_name, name) as name, " + + "password, " + + "manufacturer, " + + "model, " + + "firmware, " + + "transport," + + "stream_mode," + + "ip," + + "sdp_ip,"+ + "local_ip,"+ + "port,"+ + "host_address,"+ + "expires,"+ + "register_time,"+ + "keepalive_time,"+ + "create_time,"+ + "update_time,"+ + "charset,"+ + "subscribe_cycle_for_catalog,"+ + "subscribe_cycle_for_mobile_position,"+ + "mobile_position_submission_interval,"+ + "subscribe_cycle_for_alarm,"+ + "ssrc_check,"+ + "as_message_channel,"+ + "broadcast_push_after_ack,"+ + "geo_coord_sys,"+ + "server_id,"+ + "on_line"+ + " FROM wvp_device WHERE on_line = true and server_id = #{serverId}") + List getOnlineDevicesByServerId(@Param("serverId") String serverId); @Select("SELECT " + "id,"+ @@ -269,6 +306,7 @@ public interface DeviceMapper { "geo_coord_sys,"+ "on_line,"+ "stream_mode," + + "server_id," + "media_server_id"+ ") VALUES (" + "#{deviceId}," + @@ -284,6 +322,7 @@ public interface DeviceMapper { "#{geoCoordSys}," + "#{onLine}," + "#{streamMode}," + + "#{serverId}," + "#{mediaServerId}" + ")") void addCustomDevice(Device device); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IDeviceService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IDeviceService.java index 0812f8cf..a8f48a47 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IDeviceService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IDeviceService.java @@ -86,7 +86,7 @@ public interface IDeviceService { * 获取所有在线设备 * @return 设备列表 */ - List getAllOnlineDevice(); + List getAllOnlineDevice(String serverId); List getAllByStatus(Boolean status); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/DeviceServiceImpl.java index c3ede305..4773b9fd 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/DeviceServiceImpl.java @@ -353,8 +353,8 @@ public class DeviceServiceImpl implements IDeviceService { } @Override - public List getAllOnlineDevice() { - return deviceMapper.getOnlineDevices(); + public List getAllOnlineDevice(String serverId) { + return deviceMapper.getOnlineDevicesByServerId(serverId); } @Override diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java b/src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java index 102f9d0c..56a649bc 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/task/SipRunner.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.task; +import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Platform; @@ -60,9 +61,12 @@ public class SipRunner implements CommandLineRunner { @Autowired private ISendRtpServerService sendRtpServerService; + @Autowired + private UserSetting userSetting; + @Override public void run(String... args) throws Exception { - List deviceList = deviceService.getAllOnlineDevice(); + List deviceList = deviceService.getAllOnlineDevice(userSetting.getServerId()); for (Device device : deviceList) { if (deviceService.expire(device)){ @@ -86,7 +90,8 @@ public class SipRunner implements CommandLineRunner { deviceMapInDb.put(device.getDeviceId(), device); }); devicesInRedis.parallelStream().forEach(device -> { - if (deviceMapInDb.get(device.getDeviceId()) == null) { + if (deviceMapInDb.get(device.getDeviceId()) == null + && userSetting.getServerId().equals(device.getServerId())) { redisCatchStorage.removeDevice(device.getDeviceId()); } }); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java index 44a3eb1e..8ad37f1e 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java @@ -183,7 +183,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen device.setGeoCoordSys("WGS84"); } } - + device.setServerId(userSetting.getServerId()); device.setIp(remoteAddressInfo.getIp()); device.setPort(remoteAddressInfo.getPort()); device.setHostAddress(remoteAddressInfo.getIp().concat(":").concat(String.valueOf(remoteAddressInfo.getPort())));