| | |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.storager.dao.*; |
| | | import com.genersoft.iot.vmp.storager.dao.dto.ChannelSourceInfo; |
| | | import com.genersoft.iot.vmp.utils.node.ForestNodeMerger; |
| | | import com.genersoft.iot.vmp.vmanager.bean.DeviceChannelTree; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | | import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | |
| | | import org.springframework.transaction.TransactionDefinition; |
| | | import org.springframework.transaction.TransactionStatus; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | | /** |
| | | * 视频设备数据存储-jdbc实现 |
| | | * swwheihei |
| | | * 2020年5月6日 下午2:31:42 |
| | |
| | | @Autowired |
| | | private ParentPlatformMapper parentPlatformMapper; |
| | | |
| | | private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | |
| | | /** |
| | | * 根据设备ID判断设备是否存在 |
| | | * |
| | |
| | | return deviceMapper.getDeviceByDeviceId(deviceId) != null; |
| | | } |
| | | |
| | | /** |
| | | * 视频设备创建 |
| | | * |
| | | * @param device 设备对象 |
| | | * @return true:创建成功 false:创建失败 |
| | | */ |
| | | @Override |
| | | public synchronized boolean create(Device device) { |
| | | redisCatchStorage.updateDevice(device); |
| | | return deviceMapper.add(device) > 0; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 视频设备更新 |
| | | * |
| | | * @param device 设备对象 |
| | | * @return true:更新成功 false:更新失败 |
| | | */ |
| | | @Override |
| | | public synchronized boolean updateDevice(Device device) { |
| | | String now = this.format.format(System.currentTimeMillis()); |
| | | device.setUpdateTime(now); |
| | | Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); |
| | | device.setCharset(device.getCharset().toUpperCase()); |
| | | if (deviceByDeviceId == null) { |
| | | device.setCreateTime(now); |
| | | redisCatchStorage.updateDevice(device); |
| | | return deviceMapper.add(device) > 0; |
| | | }else { |
| | | redisCatchStorage.updateDevice(device); |
| | | |
| | | return deviceMapper.update(device) > 0; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public synchronized void updateChannel(String deviceId, DeviceChannel channel) { |
| | | String channelId = channel.getChannelId(); |
| | |
| | | if (streamInfo != null) { |
| | | channel.setStreamId(streamInfo.getStream()); |
| | | } |
| | | String now = this.format.format(System.currentTimeMillis()); |
| | | String now = DateUtil.getNow(); |
| | | channel.setUpdateTime(now); |
| | | DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); |
| | | if (deviceChannel == null) { |
| | |
| | | if (streamInfo != null) { |
| | | channel.setStreamId(streamInfo.getStream()); |
| | | } |
| | | String now = this.format.format(System.currentTimeMillis()); |
| | | String now = DateUtil.getNow(); |
| | | channel.setUpdateTime(now); |
| | | channel.setCreateTime(now); |
| | | addChannels.add(channel); |
| | |
| | | if (streamInfo != null) { |
| | | channel.setStreamId(streamInfo.getStream()); |
| | | } |
| | | String now = this.format.format(System.currentTimeMillis()); |
| | | String now = DateUtil.getNow(); |
| | | channel.setUpdateTime(now); |
| | | if (channelsInStore.get(channel.getChannelId()) != null) { |
| | | updateChannels.add(channel); |
| | |
| | | |
| | | @Override |
| | | public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) { |
| | | if (deviceChannelList == null) { |
| | | if (CollectionUtils.isEmpty(deviceChannelList)) { |
| | | return false; |
| | | } |
| | | List<DeviceChannel> allChannelInPlay = deviceChannelMapper.getAllChannelInPlay(); |
| | | Map<String,DeviceChannel> allChannelMapInPlay = new ConcurrentHashMap<>(); |
| | | if (allChannelInPlay.size() > 0) { |
| | | for (DeviceChannel deviceChannel : allChannelInPlay) { |
| | | allChannelMapInPlay.put(deviceChannel.getChannelId(), deviceChannel); |
| | | } |
| | | } |
| | | TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); |
| | | // 数据去重 |
| | | List<DeviceChannel> channels = new ArrayList<>(); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | Map<String, Integer> subContMap = new HashMap<>(); |
| | | if (deviceChannelList != null && deviceChannelList.size() > 1) { |
| | | if (deviceChannelList.size() > 1) { |
| | | // 数据去重 |
| | | Set<String> gbIdSet = new HashSet<>(); |
| | | for (DeviceChannel deviceChannel : deviceChannelList) { |
| | | if (!gbIdSet.contains(deviceChannel.getChannelId())) { |
| | | gbIdSet.add(deviceChannel.getChannelId()); |
| | | if (allChannelMapInPlay.containsKey(deviceChannel.getChannelId())) { |
| | | deviceChannel.setStreamId(allChannelMapInPlay.get(deviceChannel.getChannelId()).getStreamId()); |
| | | } |
| | | channels.add(deviceChannel); |
| | | if (!StringUtils.isEmpty(deviceChannel.getParentId())) { |
| | | if (subContMap.get(deviceChannel.getParentId()) == null) { |
| | |
| | | } |
| | | if (stringBuilder.length() > 0) { |
| | | logger.info("[目录查询]收到的数据存在重复: {}" , stringBuilder); |
| | | } |
| | | if(CollectionUtils.isEmpty(channels)){ |
| | | logger.info("通道重设,数据为空={}" , deviceChannelList); |
| | | return false; |
| | | } |
| | | try { |
| | | int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count) { |
| | | public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, Boolean catalogUnderDevice, int page, int count) { |
| | | // 获取到所有正在播放的流 |
| | | PageHelper.startPage(page, count); |
| | | List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online); |
| | | List<DeviceChannel> all; |
| | | if (catalogUnderDevice != null && catalogUnderDevice) { |
| | | all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online); |
| | | // 海康设备的parentId是SIP id |
| | | List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, sipConfig.getId(), query, hasSubChannel, online); |
| | | all.addAll(deviceChannels); |
| | | }else { |
| | | all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online); |
| | | } |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | |
| | | return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit); |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceChannelTree> tree(String deviceId) { |
| | | return ForestNodeMerger.merge(deviceChannelMapper.tree(deviceId)); |
| | | } |
| | | |
| | | @Override |
| | | public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { |
| | | public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) { |
| | | PageHelper.startPage(page, count); |
| | | List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, null, null, null); |
| | | List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, query, hasSubChannel, online); |
| | | return new PageInfo<>(all); |
| | | } |
| | | |
| | |
| | | public synchronized boolean outline(String deviceId) { |
| | | logger.info("更新设备离线: " + deviceId); |
| | | Device device = deviceMapper.getDeviceByDeviceId(deviceId); |
| | | if (device == null) return false; |
| | | if (device == null) { |
| | | return false; |
| | | } |
| | | device.setOnline(0); |
| | | redisCatchStorage.updateDevice(device); |
| | | return deviceMapper.update(device) > 0; |
| | |
| | | */ |
| | | @Override |
| | | public synchronized boolean insertMobilePosition(MobilePosition mobilePosition) { |
| | | if (mobilePosition.getDeviceId().equals(mobilePosition.getChannelId())) { |
| | | mobilePosition.setChannelId(null); |
| | | } |
| | | return deviceMobilePositionMapper.insertNewPosition(mobilePosition) > 0; |
| | | } |
| | | |
| | |
| | | * @param endTime |
| | | */ |
| | | @Override |
| | | public synchronized List<MobilePosition> queryMobilePositions(String deviceId, String startTime, String endTime) { |
| | | return deviceMobilePositionMapper.queryPositionByDeviceIdAndTime(deviceId, startTime, endTime); |
| | | public synchronized List<MobilePosition> queryMobilePositions(String deviceId, String channelId, String startTime, String endTime) { |
| | | return deviceMobilePositionMapper.queryPositionByDeviceIdAndTime(deviceId, channelId, startTime, endTime); |
| | | } |
| | | |
| | | @Override |
| | |
| | | parentPlatform.setCatalogGroup(1); |
| | | } |
| | | if (parentPlatform.getAdministrativeDivision() == null) { |
| | | parentPlatform.setAdministrativeDivision(parentPlatform.getDeviceGBId().substring(0,6)); |
| | | parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision()); |
| | | } |
| | | ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId()); |
| | | if (parentPlatform.getId() == null ) { |
| | |
| | | * 删除指定设备的所有移动位置 |
| | | * @param deviceId |
| | | */ |
| | | @Override |
| | | public int clearMobilePositionsByDeviceId(String deviceId) { |
| | | return deviceMobilePositionMapper.clearMobilePositionsByDeviceId(deviceId); |
| | | } |
| | |
| | | boolean result = false; |
| | | streamProxyItem.setStreamType("proxy"); |
| | | streamProxyItem.setStatus(true); |
| | | String now = this.format.format(System.currentTimeMillis()); |
| | | String now = DateUtil.getNow(); |
| | | streamProxyItem.setCreateTime(now); |
| | | streamProxyItem.setCreateStamp(System.currentTimeMillis()); |
| | | try { |
| | | if (streamProxyMapper.add(streamProxyItem) > 0) { |
| | | if (!StringUtils.isEmpty(streamProxyItem.getGbId())) { |
| | |
| | | |
| | | @Override |
| | | public void updateMediaList(List<StreamPushItem> streamPushItems) { |
| | | if (streamPushItems == null || streamPushItems.size() == 0) return; |
| | | if (streamPushItems == null || streamPushItems.size() == 0) { |
| | | return; |
| | | } |
| | | logger.info("updateMediaList: " + streamPushItems.size()); |
| | | streamPushMapper.addAll(streamPushItems); |
| | | // TODO 待优化 |
| | | for (int i = 0; i < streamPushItems.size(); i++) { |
| | | int onlineResult = gbStreamMapper.setStatus(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream(), true); |
| | | int onlineResult = mediaOnline(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream()); |
| | | if (onlineResult > 0) { |
| | | // 发送上线通知 |
| | | eventPublisher.catalogEventPublishForStream(null, streamPushItems.get(i), CatalogEvent.ON); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | | public void updateMedia(StreamPushItem streamPushItem) { |
| | | streamPushMapper.del(streamPushItem.getApp(), streamPushItem.getStream()); |
| | | streamPushMapper.add(streamPushItem); |
| | | gbStreamMapper.setStatus(streamPushItem.getApp(), streamPushItem.getStream(), true); |
| | | mediaOffline(streamPushItem.getApp(), streamPushItem.getStream()); |
| | | |
| | | if(!StringUtils.isEmpty(streamPushItem.getGbId() )){ |
| | | // 查找开启了全部直播流共享的上级平台 |
| | |
| | | } |
| | | |
| | | @Override |
| | | public StreamPushItem getMedia(String app, String stream) { |
| | | return streamPushMapper.selectOne(app, stream); |
| | | } |
| | | |
| | | @Override |
| | | public void clearMediaList() { |
| | | streamPushMapper.clear(); |
| | | } |
| | | |
| | | @Override |
| | | public int mediaOutline(String app, String streamId) { |
| | | return gbStreamMapper.setStatus(app, streamId, false); |
| | | public int mediaOffline(String app, String stream) { |
| | | GbStream gbStream = gbStreamMapper.selectOne(app, stream); |
| | | int result; |
| | | if ("proxy".equals(gbStream.getStreamType())) { |
| | | result = streamProxyMapper.updateStatus(app, stream, false); |
| | | }else { |
| | | result = streamPushMapper.updateStatus(app, stream, false); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public int mediaOnline(String app, String stream) { |
| | | GbStream gbStream = gbStreamMapper.selectOne(app, stream); |
| | | int result; |
| | | if ("proxy".equals(gbStream.getStreamType())) { |
| | | result = streamProxyMapper.updateStatus(app, stream, true); |
| | | }else { |
| | | result = streamPushMapper.updateStatus(app, stream, true); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public int setDefaultCatalog(String platformId, String catalogId) { |
| | | return platformMapper.setDefaultCatalog(platformId, catalogId); |
| | | return platformMapper.setDefaultCatalog(platformId, catalogId, DateUtil.getNow()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | deviceChannel.setParentId(catalog.getParentId()); |
| | | deviceChannel.setRegisterWay(1); |
| | | // 行政区划应该是Domain的前八位 |
| | | deviceChannel.setCivilCode(parentPlatByServerGBId.getDeviceGBId().substring(0,6)); |
| | | deviceChannel.setCivilCode(parentPlatByServerGBId.getAdministrativeDivision()); |
| | | deviceChannel.setModel("live"); |
| | | deviceChannel.setOwner("wvp-pro"); |
| | | deviceChannel.setSecrecy("0"); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void updateChannelPotion(String deviceId, String channelId, double longitude, double latitude) { |
| | | deviceChannelMapper.updatePotion(deviceId, channelId, longitude, latitude); |
| | | public void updateChannelPosition(DeviceChannel deviceChannel) { |
| | | if (deviceChannel.getChannelId().equals(deviceChannel.getDeviceId())) { |
| | | deviceChannel.setChannelId(null); |
| | | } |
| | | if (deviceChannel.getGpsTime() == null) { |
| | | deviceChannel.setGpsTime(DateUtil.getNow()); |
| | | } |
| | | |
| | | deviceChannelMapper.updatePosition(deviceChannel); |
| | | } |
| | | } |