| | |
| | | package com.genersoft.iot.vmp.storager.impl; |
| | | |
| | | import com.genersoft.iot.vmp.conf.SipConfig; |
| | | import com.genersoft.iot.vmp.gb28181.bean.*; |
| | | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| | | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| | | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| | | import com.genersoft.iot.vmp.service.IGbStreamService; |
| | | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| | | import com.genersoft.iot.vmp.storager.dao.*; |
| | |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @description:视频设备数据存储-jdbc实现 |
| | | * @author: swwheihei |
| | | * @date: 2020年5月6日 下午2:31:42 |
| | | * 视频设备数据存储-jdbc实现 |
| | | * swwheihei |
| | | * 2020年5月6日 下午2:31:42 |
| | | */ |
| | | @SuppressWarnings("rawtypes") |
| | | @Component |
| | | public class VideoManagerStoragerImpl implements IVideoManagerStorager { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger(VideoManagerStoragerImpl.class); |
| | | |
| | | @Autowired |
| | | EventPublisher eventPublisher; |
| | | |
| | | @Autowired |
| | | SipConfig sipConfig; |
| | | |
| | | @Autowired |
| | | DataSourceTransactionManager dataSourceTransactionManager; |
| | |
| | | |
| | | @Autowired |
| | | private GbStreamMapper gbStreamMapper; |
| | | |
| | | @Autowired |
| | | private PlatformCatalogMapper catalogMapper; |
| | | ; |
| | | |
| | | @Autowired |
| | |
| | | return deviceMapper.add(device) > 0; |
| | | }else { |
| | | redisCatchStorage.updateDevice(device); |
| | | |
| | | return deviceMapper.update(device) > 0; |
| | | } |
| | | |
| | |
| | | } |
| | | try { |
| | | int cleanChannelsResult = deviceChannelMapper.cleanChannelsByDeviceId(deviceId); |
| | | int limitCount = 1; |
| | | int limitCount = 300; |
| | | boolean result = cleanChannelsResult < 0; |
| | | if (!result && channels.size() > 0) { |
| | | if (channels.size() > limitCount) { |
| | |
| | | device.setOnline(1); |
| | | logger.info("更新设备在线: " + deviceId); |
| | | redisCatchStorage.updateDevice(device); |
| | | List<DeviceChannel> deviceChannelList = deviceChannelMapper.queryOnlineChannelsByDeviceId(deviceId); |
| | | eventPublisher.catalogEventPublish(null, deviceChannelList, CatalogEvent.ON); |
| | | return deviceMapper.update(device) > 0; |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public boolean addParentPlatform(ParentPlatform parentPlatform) { |
| | | if (parentPlatform.getCatalogId() == null) { |
| | | parentPlatform.setCatalogId(parentPlatform.getServerGBId()); |
| | | } |
| | | int result = platformMapper.addParentPlatform(parentPlatform); |
| | | return result > 0; |
| | | } |
| | |
| | | int result = 0; |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId()); |
| | | if (parentPlatform.getId() == null ) { |
| | | if (parentPlatform.getCatalogId() == null) { |
| | | parentPlatform.setCatalogId(parentPlatform.getServerGBId()); |
| | | } |
| | | result = platformMapper.addParentPlatform(parentPlatform); |
| | | if (parentPlatformCatch == null) { |
| | | parentPlatformCatch = new ParentPlatformCatch(); |
| | |
| | | // 更新缓存 |
| | | parentPlatformCatch.setParentPlatform(parentPlatform); |
| | | redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); |
| | | // 共享所有视频流,需要将现有视频流添加到此平台 |
| | | List<GbStream> gbStreams = gbStreamMapper.selectAll(); |
| | | if (gbStreams.size() > 0) { |
| | | if (parentPlatform.isShareAllLiveStream()) { |
| | | gbStreamService.addPlatformInfo(gbStreams, parentPlatform.getServerGBId()); |
| | | }else { |
| | | gbStreamService.delPlatformInfo(gbStreams); |
| | | if (parentPlatform.isEnable()) { |
| | | // 共享所有视频流,需要将现有视频流添加到此平台 |
| | | List<GbStream> gbStreams = gbStreamMapper.queryStreamNotInPlatform(); |
| | | if (gbStreams.size() > 0) { |
| | | for (GbStream gbStream : gbStreams) { |
| | | gbStream.setCatalogId(parentPlatform.getCatalogId()); |
| | | } |
| | | if (parentPlatform.isShareAllLiveStream()) { |
| | | gbStreamService.addPlatformInfo(gbStreams, parentPlatform.getServerGBId(), parentPlatform.getCatalogId()); |
| | | }else { |
| | | gbStreamService.delPlatformInfo(parentPlatform.getServerGBId(), gbStreams); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return result > 0; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces) { |
| | | public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId) { |
| | | |
| | | Map<String, ChannelReduce> deviceAndChannels = new HashMap<>(); |
| | | for (ChannelReduce channelReduce : channelReduces) { |
| | | channelReduce.setCatalogId(catalogId); |
| | | deviceAndChannels.put(channelReduce.getDeviceId() + "_" + channelReduce.getChannelId(), channelReduce); |
| | | } |
| | | List<String> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet()); |
| | |
| | | int result = 0; |
| | | if (channelReducesToAdd.size() > 0) { |
| | | result = platformChannelMapper.addChannels(platformId, channelReducesToAdd); |
| | | // TODO 后续给平台增加控制开关以控制是否响应目录订阅 |
| | | List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId); |
| | | eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); |
| | | } |
| | | |
| | | return result; |
| | |
| | | public int delChannelForGB(String platformId, List<ChannelReduce> channelReduces) { |
| | | |
| | | int result = platformChannelMapper.delChannelForGB(platformId, channelReduces); |
| | | |
| | | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| | | for (ChannelReduce channelReduce : channelReduces) { |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setChannelId(channelReduce.getChannelId()); |
| | | deviceChannelList.add(deviceChannel); |
| | | } |
| | | eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL); |
| | | return result; |
| | | } |
| | | |
| | |
| | | public DeviceChannel queryChannelInParentPlatform(String platformId, String channelId) { |
| | | DeviceChannel channel = platformChannelMapper.queryChannelInParentPlatform(platformId, channelId); |
| | | return channel; |
| | | } |
| | | |
| | | @Override |
| | | public List<PlatformCatalog> queryChannelInParentPlatformAndCatalog(String platformId, String catalogId) { |
| | | List<PlatformCatalog> catalogs = platformChannelMapper.queryChannelInParentPlatformAndCatalog(platformId, catalogId); |
| | | return catalogs; |
| | | } |
| | | |
| | | @Override |
| | | public List<PlatformCatalog> queryStreamInParentPlatformAndCatalog(String platformId, String catalogId) { |
| | | List<PlatformCatalog> catalogs = platformGbStreamMapper.queryChannelInParentPlatformAndCatalogForCatalog(platformId, catalogId); |
| | | return catalogs; |
| | | } |
| | | |
| | | @Override |
| | |
| | | streamProxyItem.setStatus(true); |
| | | String now = this.format.format(System.currentTimeMillis()); |
| | | streamProxyItem.setCreateTime(now); |
| | | streamProxyItem.setCreateStamp(System.currentTimeMillis()); |
| | | try { |
| | | if (gbStreamMapper.add(streamProxyItem)<0 || streamProxyMapper.add(streamProxyItem) < 0) { |
| | | //事务回滚 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<GbStream> queryStreamInParentPlatform(String platformId, String gbId) { |
| | | public GbStream queryStreamInParentPlatform(String platformId, String gbId) { |
| | | return gbStreamMapper.queryStreamInPlatform(platformId, gbId); |
| | | } |
| | | |
| | |
| | | streamPushMapper.addAll(streamPushItems); |
| | | // TODO 待优化 |
| | | for (int i = 0; i < streamPushItems.size(); i++) { |
| | | gbStreamMapper.setStatus(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream(), true); |
| | | int onlineResult = gbStreamMapper.setStatus(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream(), true); |
| | | if (onlineResult > 0) { |
| | | // 发送上线通知 |
| | | eventPublisher.catalogEventPublishForStream(null, streamPushItems.get(i), CatalogEvent.ON); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | streamPushMapper.del(streamPushItem.getApp(), streamPushItem.getStream()); |
| | | streamPushMapper.add(streamPushItem); |
| | | gbStreamMapper.setStatus(streamPushItem.getApp(), streamPushItem.getStream(), true); |
| | | |
| | | if(!StringUtils.isEmpty(streamPushItem.getGbId() )){ |
| | | // 查找开启了全部直播流共享的上级平台 |
| | | List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream(); |
| | | if (parentPlatforms.size() > 0) { |
| | | for (ParentPlatform parentPlatform : parentPlatforms) { |
| | | streamPushItem.setCatalogId(parentPlatform.getCatalogId()); |
| | | streamPushItem.setPlatformId(parentPlatform.getServerGBId()); |
| | | String stream = streamPushItem.getStream(); |
| | | StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(streamPushItem.getApp(), stream, parentPlatform.getServerGBId()); |
| | | StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(streamPushItem.getApp(), stream, |
| | | parentPlatform.getServerGBId()); |
| | | if (streamProxyItems == null) { |
| | | platformGbStreamMapper.add(streamPushItem); |
| | | eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), streamPushItem, CatalogEvent.ADD); |
| | | } |
| | | } |
| | | } |
| | |
| | | return streamProxyMapper.selectOne(app, streamId); |
| | | } |
| | | |
| | | @Override |
| | | public List<PlatformCatalog> getChildrenCatalogByPlatform(String platformId, String parentId) { |
| | | return catalogMapper.selectByParentId(platformId, parentId); |
| | | } |
| | | |
| | | @Override |
| | | public int addCatalog(PlatformCatalog platformCatalog) { |
| | | int result = catalogMapper.add(platformCatalog); |
| | | if (result > 0) { |
| | | DeviceChannel deviceChannel = getDeviceChannelByCatalog(platformCatalog); |
| | | eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.ADD); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public PlatformCatalog getCatalog(String id) { |
| | | return catalogMapper.select(id); |
| | | } |
| | | |
| | | @Override |
| | | public int delCatalog(String id) { |
| | | PlatformCatalog platformCatalog = catalogMapper.select(id); |
| | | if (platformCatalog.getChildrenCount() > 0) { |
| | | List<PlatformCatalog> platformCatalogList = catalogMapper.selectByParentId(platformCatalog.getPlatformId(), platformCatalog.getId()); |
| | | for (PlatformCatalog catalog : platformCatalogList) { |
| | | if (catalog.getChildrenCount() == 0) { |
| | | delCatalogExecute(catalog.getId(), catalog.getPlatformId()); |
| | | }else { |
| | | delCatalog(catalog.getId()); |
| | | } |
| | | } |
| | | } |
| | | return delCatalogExecute(id, platformCatalog.getPlatformId()); |
| | | } |
| | | private int delCatalogExecute(String id, String platformId) { |
| | | int delresult = catalogMapper.del(id); |
| | | DeviceChannel deviceChannelForCatalog = new DeviceChannel(); |
| | | if (delresult > 0){ |
| | | deviceChannelForCatalog.setChannelId(id); |
| | | eventPublisher.catalogEventPublish(platformId, deviceChannelForCatalog, CatalogEvent.DEL); |
| | | } |
| | | |
| | | List<GbStream> gbStreams = platformGbStreamMapper.queryChannelInParentPlatformAndCatalog(platformId, id); |
| | | if (gbStreams.size() > 0){ |
| | | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| | | for (GbStream gbStream : gbStreams) { |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setChannelId(gbStream.getGbId()); |
| | | deviceChannelList.add(deviceChannel); |
| | | } |
| | | eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL); |
| | | } |
| | | int delStreamresult = platformGbStreamMapper.delByCatalogId(id); |
| | | List<PlatformCatalog> platformCatalogs = platformChannelMapper.queryChannelInParentPlatformAndCatalog(platformId, id); |
| | | if (platformCatalogs.size() > 0){ |
| | | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| | | for (PlatformCatalog platformCatalog : platformCatalogs) { |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setChannelId(platformCatalog.getId()); |
| | | deviceChannelList.add(deviceChannel); |
| | | } |
| | | eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL); |
| | | } |
| | | int delChannelresult = platformChannelMapper.delByCatalogId(id); |
| | | return delresult + delChannelresult + delStreamresult; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public int updateCatalog(PlatformCatalog platformCatalog) { |
| | | int result = catalogMapper.update(platformCatalog); |
| | | if (result > 0) { |
| | | DeviceChannel deviceChannel = getDeviceChannelByCatalog(platformCatalog); |
| | | eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.UPDATE); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public int setDefaultCatalog(String platformId, String catalogId) { |
| | | return platformMapper.setDefaultCatalog(platformId, catalogId); |
| | | } |
| | | |
| | | @Override |
| | | public List<PlatformCatalog> queryCatalogInPlatform(String platformId) { |
| | | return catalogMapper.selectByPlatForm(platformId); |
| | | } |
| | | |
| | | @Override |
| | | public int delRelation(PlatformCatalog platformCatalog) { |
| | | if (platformCatalog.getType() == 1) { |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setChannelId(platformCatalog.getId()); |
| | | eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.DEL); |
| | | return platformChannelMapper.delByCatalogIdAndChannelIdAndPlatformId(platformCatalog); |
| | | }else if (platformCatalog.getType() == 2) { |
| | | List<GbStream> gbStreams = platformGbStreamMapper.queryChannelInParentPlatformAndCatalog(platformCatalog.getPlatformId(), platformCatalog.getParentId()); |
| | | for (GbStream gbStream : gbStreams) { |
| | | if (gbStream.getGbId().equals(platformCatalog.getId())) { |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setChannelId(gbStream.getGbId()); |
| | | eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.DEL); |
| | | return platformGbStreamMapper.delByAppAndStream(gbStream.getApp(), gbStream.getStream()); |
| | | } |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | @Override |
| | | public int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfos) { |
| | | return gbStreamMapper.updateStreamGPS(gpsMsgInfos); |
| | | } |
| | | |
| | | private List<DeviceChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId) { |
| | | List<DeviceChannel> deviceChannelList = new ArrayList<>(); |
| | | if (channelReduces.size() > 0){ |
| | | for (ChannelReduce channelReduce : channelReduces) { |
| | | DeviceChannel deviceChannel = queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId()); |
| | | deviceChannel.setParental(1); |
| | | deviceChannel.setParentId(catalogId); |
| | | deviceChannelList.add(deviceChannel); |
| | | } |
| | | } |
| | | return deviceChannelList; |
| | | } |
| | | |
| | | private DeviceChannel getDeviceChannelByCatalog(PlatformCatalog catalog) { |
| | | ParentPlatform parentPlatByServerGBId = platformMapper.getParentPlatByServerGBId(catalog.getPlatformId()); |
| | | DeviceChannel deviceChannel = new DeviceChannel(); |
| | | deviceChannel.setChannelId(catalog.getId()); |
| | | deviceChannel.setName(catalog.getName()); |
| | | deviceChannel.setLongitude(0.0); |
| | | deviceChannel.setLatitude(0.0); |
| | | deviceChannel.setDeviceId(parentPlatByServerGBId.getDeviceGBId()); |
| | | deviceChannel.setManufacture("wvp-pro"); |
| | | deviceChannel.setStatus(1); |
| | | deviceChannel.setParental(1); |
| | | deviceChannel.setParentId(catalog.getParentId()); |
| | | deviceChannel.setRegisterWay(1); |
| | | deviceChannel.setCivilCode(sipConfig.getDomain()); |
| | | deviceChannel.setModel("live"); |
| | | deviceChannel.setOwner("wvp-pro"); |
| | | deviceChannel.setSecrecy("0"); |
| | | return deviceChannel; |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId) { |
| | | return deviceChannelMapper.queryOnlineChannelsByDeviceId(deviceId); |
| | | } |
| | | |
| | | @Override |
| | | public List<ParentPlatform> queryPlatFormListForGBWithGBId(String channelId, List<String> platforms) { |
| | | return platformChannelMapper.queryPlatFormListForGBWithGBId(channelId, platforms); |
| | | } |
| | | |
| | | @Override |
| | | public List<ParentPlatform> queryPlatFormListForStreamWithGBId(String app, String stream, List<String> platforms) { |
| | | return platformGbStreamMapper.queryPlatFormListForGBWithGBId(app, stream, platforms); |
| | | } |
| | | |
| | | @Override |
| | | public GbStream getGbStream(String app, String streamId) { |
| | | return gbStreamMapper.selectOne(app, streamId); |
| | | } |
| | | |
| | | @Override |
| | | public void delCatalogByPlatformId(String serverGBId) { |
| | | catalogMapper.delByPlatformId(serverGBId); |
| | | } |
| | | |
| | | @Override |
| | | public void delRelationByPlatformId(String serverGBId) { |
| | | platformGbStreamMapper.delByPlatformId(serverGBId); |
| | | platformChannelMapper.delByPlatformId(serverGBId); |
| | | } |
| | | } |