| | |
| | | |
| | | @Autowired |
| | | private GbStreamMapper gbStreamMapper; |
| | | |
| | | @Autowired |
| | | private PlatformCatalogMapper catalogMapper; |
| | | ; |
| | | |
| | | @Autowired |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void updateChannels(String deviceId, List<DeviceChannel> channels) { |
| | | public int updateChannels(String deviceId, List<DeviceChannel> channels) { |
| | | List<DeviceChannel> addChannels = new ArrayList<>(); |
| | | List<DeviceChannel> updateChannels = new ArrayList<>(); |
| | | HashMap<String, DeviceChannel> channelsInStore = new HashMap<>(); |
| | |
| | | if (i + limitCount > updateChannels.size()) { |
| | | toIndex = updateChannels.size(); |
| | | } |
| | | deviceChannelMapper.batchAdd(updateChannels.subList(i, toIndex)); |
| | | deviceChannelMapper.batchUpdate(updateChannels.subList(i, toIndex)); |
| | | } |
| | | }else { |
| | | deviceChannelMapper.batchUpdate(updateChannels); |
| | | } |
| | | } |
| | | } |
| | | return addChannels.size() + updateChannels.size(); |
| | | } |
| | | |
| | | @Override |
| | | public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) { |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | try { |
| | | int cleanChannelsResult = deviceChannelMapper.cleanChannelsByDeviceId(deviceId); |
| | | int limitCount = 300; |
| | | boolean result = cleanChannelsResult <0; |
| | | if (!result && deviceChannelList.size() > 0) { |
| | | if (deviceChannelList.size() > limitCount) { |
| | | for (int i = 0; i < deviceChannelList.size(); i += limitCount) { |
| | | int toIndex = i + limitCount; |
| | | if (i + limitCount > deviceChannelList.size()) { |
| | | toIndex = deviceChannelList.size(); |
| | | } |
| | | result = result || deviceChannelMapper.batchAdd(deviceChannelList.subList(i, toIndex)) < 0; |
| | | } |
| | | }else { |
| | | result = result || deviceChannelMapper.batchAdd(deviceChannelList) < 0; |
| | | } |
| | | } |
| | | if (result) { |
| | | //事务回滚 |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | } |
| | | dataSourceTransactionManager.commit(transactionStatus); //手动提交 |
| | | return true; |
| | | }catch (Exception e) { |
| | | dataSourceTransactionManager.rollback(transactionStatus); |
| | | return false; |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | PageHelper.startPage(page, count); |
| | | List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online); |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit) { |
| | | return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @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(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()); |
| | |
| | | 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.queryChannelInParentPlatformAndCatalogForCatlog(platformId, catalogId); |
| | | return catalogs; |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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()); |
| | | if (streamProxyItems == null) { |
| | | platformGbStreamMapper.add(streamPushItem); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | 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) { |
| | | return catalogMapper.add(platformCatalog); |
| | | } |
| | | |
| | | @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) { |
| | | catalogMapper.del(catalog.getId()); |
| | | platformGbStreamMapper.delByCatalogId(catalog.getId()); |
| | | platformChannelMapper.delByCatalogId(catalog.getId()); |
| | | }else { |
| | | delCatalog(catalog.getId()); |
| | | } |
| | | } |
| | | } |
| | | int delresult = catalogMapper.del(id); |
| | | int delStreamresult = platformGbStreamMapper.delByCatalogId(id); |
| | | int delChanneresult = platformChannelMapper.delByCatalogId(id); |
| | | return delresult + delChanneresult + delStreamresult; |
| | | } |
| | | |
| | | @Override |
| | | public int updateCatalog(PlatformCatalog platformCatalog) { |
| | | return catalogMapper.update(platformCatalog); |
| | | } |
| | | |
| | | @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) { |
| | | 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())) { |
| | | return platformGbStreamMapper.delByAppAndStream(gbStream.getApp(), gbStream.getStream()); |
| | | } |
| | | } |
| | | } |
| | | return 0; |
| | | } |
| | | } |