| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.support.incrementer.AbstractIdentityColumnMaxValueIncrementer; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.SipException; |
| | | import java.text.ParseException; |
| | | import java.time.Instant; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | |
| | | logger.info("[设备上线,首次注册]: {},查询设备信息以及通道信息", device.getDeviceId()); |
| | | deviceMapper.add(device); |
| | | redisCatchStorage.updateDevice(device); |
| | | commander.deviceInfoQuery(device); |
| | | try { |
| | | commander.deviceInfoQuery(device); |
| | | } catch (InvalidArgumentException | SipException | ParseException e) { |
| | | logger.error("[命令发送失败] 查询设备信息: {}", e.getMessage()); |
| | | } |
| | | sync(device); |
| | | }else { |
| | | if(device.getOnline() == 0){ |
| | |
| | | logger.info("[设备上线,离线状态下重新注册]: {},查询设备信息以及通道信息", device.getDeviceId()); |
| | | deviceMapper.update(device); |
| | | redisCatchStorage.updateDevice(device); |
| | | commander.deviceInfoQuery(device); |
| | | try { |
| | | commander.deviceInfoQuery(device); |
| | | } catch (InvalidArgumentException | SipException | ParseException e) { |
| | | logger.error("[命令发送失败] 查询设备信息: {}", e.getMessage()); |
| | | } |
| | | sync(device); |
| | | // TODO 如果设备下的通道级联到了其他平台,那么需要发送事件或者notify给上级平台 |
| | | }else { |
| | |
| | | |
| | | @Override |
| | | public void offline(String deviceId) { |
| | | logger.info("[设备离线], device:{}", deviceId); |
| | | Device device = deviceMapper.getDeviceByDeviceId(deviceId); |
| | | if (device == null) { |
| | | return; |
| | |
| | | if (ssrcTransactions != null && ssrcTransactions.size() > 0) { |
| | | for (SsrcTransaction ssrcTransaction : ssrcTransactions) { |
| | | mediaServerService.releaseSsrc(ssrcTransaction.getMediaServerId(), ssrcTransaction.getSsrc()); |
| | | mediaServerService.closeRTPServer(deviceId, ssrcTransaction.getChannelId(), ssrcTransaction.getStream()); |
| | | mediaServerService.closeRTPServer(ssrcTransaction.getMediaServerId(), ssrcTransaction.getStream()); |
| | | streamSession.remove(deviceId, ssrcTransaction.getChannelId(), ssrcTransaction.getStream()); |
| | | } |
| | | } |
| | |
| | | } |
| | | int sn = (int)((Math.random()*9+1)*100000); |
| | | catalogResponseMessageHandler.setChannelSyncReady(device, sn); |
| | | sipCommander.catalogQuery(device, sn, event -> { |
| | | String errorMsg = String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg); |
| | | try { |
| | | sipCommander.catalogQuery(device, sn, event -> { |
| | | String errorMsg = String.format("同步通道失败,错误码: %s, %s", event.statusCode, event.msg); |
| | | catalogResponseMessageHandler.setChannelSyncEnd(device.getDeviceId(), errorMsg); |
| | | }); |
| | | } catch (SipException | InvalidArgumentException | ParseException e) { |
| | | logger.error("[同步通道], 信令发送失败:{}", e.getMessage() ); |
| | | String errorMsg = String.format("同步通道失败,信令发送失败: %s", e.getMessage()); |
| | | catalogResponseMessageHandler.setChannelSyncEnd(device.getDeviceId(), errorMsg); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Device queryDevice(String deviceId) { |
| | | return deviceMapper.getDeviceByDeviceId(deviceId); |
| | | Device device = redisCatchStorage.getDevice(deviceId); |
| | | if (device == null) { |
| | | device = deviceMapper.getDeviceByDeviceId(deviceId); |
| | | if (device != null) { |
| | | redisCatchStorage.updateDevice(device); |
| | | } |
| | | } |
| | | return device; |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (device == null || device.getOnline() == 0) { |
| | | return; |
| | | } |
| | | sipCommander.deviceStatusQuery(device, null); |
| | | try { |
| | | sipCommander.deviceStatusQuery(device, null); |
| | | } catch (InvalidArgumentException | SipException | ParseException e) { |
| | | logger.error("[命令发送失败] 设备状态查询: {}", e.getMessage()); |
| | | } |
| | | |
| | | } |
| | | |
| | |
| | | logger.warn("更新设备时未找到设备信息"); |
| | | return; |
| | | } |
| | | if (!StringUtils.isEmpty(device.getName())) { |
| | | if (!ObjectUtils.isEmpty(device.getName())) { |
| | | deviceInStore.setName(device.getName()); |
| | | } |
| | | if (!StringUtils.isEmpty(device.getCharset())) { |
| | | if (!ObjectUtils.isEmpty(device.getCharset())) { |
| | | deviceInStore.setCharset(device.getCharset()); |
| | | } |
| | | if (!StringUtils.isEmpty(device.getMediaServerId())) { |
| | | if (!ObjectUtils.isEmpty(device.getMediaServerId())) { |
| | | deviceInStore.setMediaServerId(device.getMediaServerId()); |
| | | } |
| | | |
| | |
| | | device.setUpdateTime(now); |
| | | device.setCharset(device.getCharset().toUpperCase()); |
| | | device.setUpdateTime(DateUtil.getNow()); |
| | | if (deviceMapper.update(device) > 0) { |
| | | if (deviceMapper.updateCustom(device) > 0) { |
| | | redisCatchStorage.updateDevice(device); |
| | | |
| | | } |
| | |
| | | return null; |
| | | } |
| | | // 使用行政区划展示树 |
| | | if (parentId.length() > 10) { |
| | | // TODO 可能是行政区划与业务分组混杂的情形 |
| | | return null; |
| | | } |
| | | // if (parentId.length() > 10) { |
| | | // // TODO 可能是行政区划与业务分组混杂的情形 |
| | | // return null; |
| | | // } |
| | | |
| | | if (parentId.length() == 10 ) { |
| | | if (onlyCatalog) { |
| | |
| | | List<DeviceChannel> channelsForCivilCode = deviceChannelMapper.getChannelsWithCivilCodeAndLength(deviceId, parentId, parentId.length() + 2); |
| | | if (!onlyCatalog) { |
| | | List<DeviceChannel> channels = deviceChannelMapper.getChannelsByCivilCode(deviceId, parentId); |
| | | channelsForCivilCode.addAll(channels); |
| | | |
| | | for(DeviceChannel channel : channels) { |
| | | boolean flag = false; |
| | | for(DeviceChannel deviceChannel : channelsForCivilCode) { |
| | | if(channel.getChannelId().equals(deviceChannel.getChannelId())) { |
| | | flag = true; |
| | | } |
| | | } |
| | | if(!flag) { |
| | | channelsForCivilCode.add(channel); |
| | | } |
| | | } |
| | | } |
| | | List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(channelsForCivilCode, parentId); |
| | | return trees; |