From fc89b7b517e191fb6c9b66fa86dd05ebab0f54c5 Mon Sep 17 00:00:00 2001 From: jiang <893224616@qq.com> Date: 星期三, 13 七月 2022 11:29:46 +0800 Subject: [PATCH] 测试提交权限 --- src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java | 179 +++++++++++++++++++++++++++++++++-------------------------- 1 files changed, 101 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java index 439ecd8..c4d1c9e 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java @@ -13,8 +13,7 @@ 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; @@ -26,12 +25,13 @@ 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 @@ -93,9 +93,6 @@ @Autowired private ParentPlatformMapper parentPlatformMapper; - private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - /** * 鏍规嵁璁惧ID鍒ゆ柇璁惧鏄惁瀛樺湪 * @@ -107,45 +104,6 @@ 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(); @@ -154,7 +112,7 @@ 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) { @@ -180,7 +138,7 @@ 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); @@ -195,7 +153,7 @@ 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); @@ -238,6 +196,16 @@ @Override public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) { + 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<>(); @@ -249,6 +217,9 @@ 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) { @@ -274,7 +245,11 @@ channels = deviceChannelList; } if (stringBuilder.length() > 0) { - logger.debug("[鐩綍鏌ヨ]鏀跺埌鐨勬暟鎹瓨鍦ㄩ噸澶嶏細 {}" , stringBuilder); + logger.info("[鐩綍鏌ヨ]鏀跺埌鐨勬暟鎹瓨鍦ㄩ噸澶嶏細 {}" , stringBuilder); + } + if(CollectionUtils.isEmpty(channels)){ + logger.info("閫氶亾閲嶈锛屾暟鎹负绌�={}" , deviceChannelList); + return false; } try { int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels); @@ -300,6 +275,7 @@ dataSourceTransactionManager.commit(transactionStatus); //鎵嬪姩鎻愪氦 return true; }catch (Exception e) { + e.printStackTrace(); dataSourceTransactionManager.rollback(transactionStatus); return false; } @@ -338,10 +314,18 @@ } @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); + // 娴峰悍璁惧鐨刾arentId鏄疭IP 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); } @@ -350,10 +334,6 @@ 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) { @@ -361,9 +341,9 @@ } @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); } @@ -415,10 +395,9 @@ TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); boolean result = false; try { - if (platformChannelMapper.delChannelForDeviceId(deviceId) <0 // 鍒犻櫎涓庡浗鏍囧钩鍙扮殑鍏宠仈 - || deviceChannelMapper.cleanChannelsByDeviceId(deviceId) < 0 // 鍒犻櫎浠栫殑閫氶亾 - || deviceMapper.del(deviceId) < 0 // 绉婚櫎璁惧淇℃伅 - ) { + platformChannelMapper.delChannelForDeviceId(deviceId); + deviceChannelMapper.cleanChannelsByDeviceId(deviceId); + if ( deviceMapper.del(deviceId) < 0 ) { //浜嬪姟鍥炴粴 dataSourceTransactionManager.rollback(transactionStatus); } @@ -445,8 +424,6 @@ 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; } @@ -460,7 +437,9 @@ 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; @@ -493,6 +472,9 @@ */ @Override public synchronized boolean insertMobilePosition(MobilePosition mobilePosition) { + if (mobilePosition.getDeviceId().equals(mobilePosition.getChannelId())) { + mobilePosition.setChannelId(null); + } return deviceMobilePositionMapper.insertNewPosition(mobilePosition) > 0; } @@ -503,8 +485,8 @@ * @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 @@ -519,6 +501,12 @@ @Override public boolean updateParentPlatform(ParentPlatform parentPlatform) { int result = 0; + if (parentPlatform.getCatalogGroup() == 0) { + parentPlatform.setCatalogGroup(1); + } + if (parentPlatform.getAdministrativeDivision() == null) { + parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision()); + } ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId()); if (parentPlatform.getId() == null ) { if (parentPlatform.getCatalogId() == null) { @@ -538,6 +526,7 @@ parentPlatformCatch.setId(parentPlatform.getServerGBId()); redisCatchStorage.delPlatformCatchInfo(parentPlatById.getServerGBId()); } + result = platformMapper.updateParentPlatform(parentPlatform); } // 鏇存柊缂撳瓨 @@ -707,6 +696,7 @@ * 鍒犻櫎鎸囧畾璁惧鐨勬墍鏈夌Щ鍔ㄤ綅缃� * @param deviceId */ + @Override public int clearMobilePositionsByDeviceId(String deviceId) { return deviceMobilePositionMapper.clearMobilePositionsByDeviceId(deviceId); } @@ -722,9 +712,8 @@ 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())) { @@ -852,12 +841,14 @@ @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); @@ -865,11 +856,13 @@ } } + + @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() )){ // 鏌ユ壘寮�鍚簡鍏ㄩ儴鐩存挱娴佸叡浜殑涓婄骇骞冲彴 @@ -896,13 +889,36 @@ } @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 @@ -1012,7 +1028,7 @@ @Override public int setDefaultCatalog(String platformId, String catalogId) { - return platformMapper.setDefaultCatalog(platformId, catalogId); + return platformMapper.setDefaultCatalog(platformId, catalogId, DateUtil.getNow()); } @Override @@ -1073,7 +1089,7 @@ deviceChannel.setParentId(catalog.getParentId()); deviceChannel.setRegisterWay(1); // 琛屾斂鍖哄垝搴旇鏄疍omain鐨勫墠鍏綅 - deviceChannel.setCivilCode(parentPlatByServerGBId.getDeviceGBId().substring(0,6)); + deviceChannel.setCivilCode(parentPlatByServerGBId.getAdministrativeDivision()); deviceChannel.setModel("live"); deviceChannel.setOwner("wvp-pro"); deviceChannel.setSecrecy("0"); @@ -1125,7 +1141,14 @@ } @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); } } -- Gitblit v1.8.0