Commit bf66f8f694607fdd41ff9d7f6149459eef96bb67
1 parent
d07a5680
推流导入支持添加平台信息与目录信息
Showing
10 changed files
with
145 additions
and
30 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
| ... | ... | @@ -131,7 +131,7 @@ public class EventPublisher { |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | @Async |
| 134 | - public void catalogEventPublishForStream(String platformId, List<GbStream> gbStreams, String type) { | |
| 134 | + public void catalogEventPublishForStream(String platformId, GbStream[] gbStreams, String type) { | |
| 135 | 135 | CatalogEvent outEvent = new CatalogEvent(this); |
| 136 | 136 | outEvent.setGbStreams(gbStreams); |
| 137 | 137 | outEvent.setType(type); |
| ... | ... | @@ -141,8 +141,7 @@ public class EventPublisher { |
| 141 | 141 | |
| 142 | 142 | @Async |
| 143 | 143 | public void catalogEventPublishForStream(String platformId, GbStream gbStream, String type) { |
| 144 | - List<GbStream> gbStreamList = new ArrayList<>(); | |
| 145 | - gbStreamList.add(gbStream); | |
| 146 | - catalogEventPublishForStream(platformId, gbStreamList, type); | |
| 144 | + GbStream[] gbStreams = {gbStream}; | |
| 145 | + catalogEventPublishForStream(platformId, gbStreams, type); | |
| 147 | 146 | } |
| 148 | 147 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java
| ... | ... | @@ -20,7 +20,7 @@ public class CatalogEvent extends ApplicationEvent { |
| 20 | 20 | public static final String UPDATE = "UPDATE"; // 更新 |
| 21 | 21 | |
| 22 | 22 | private List<DeviceChannel> deviceChannels; |
| 23 | - private List<GbStream> gbStreams; | |
| 23 | + private GbStream[] gbStreams; | |
| 24 | 24 | private String type; |
| 25 | 25 | private String platformId; |
| 26 | 26 | |
| ... | ... | @@ -48,11 +48,11 @@ public class CatalogEvent extends ApplicationEvent { |
| 48 | 48 | this.platformId = platformId; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public List<GbStream> getGbStreams() { | |
| 51 | + public GbStream[] getGbStreams() { | |
| 52 | 52 | return gbStreams; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - public void setGbStreams(List<GbStream> gbStreams) { | |
| 55 | + public void setGbStreams(GbStream[] gbStreams) { | |
| 56 | 56 | this.gbStreams = gbStreams; |
| 57 | 57 | } |
| 58 | 58 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
| ... | ... | @@ -94,7 +94,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 94 | 94 | if (event.getDeviceChannels() != null) { |
| 95 | 95 | deviceChannelList.addAll(event.getDeviceChannels()); |
| 96 | 96 | } |
| 97 | - if (event.getGbStreams() != null && event.getGbStreams().size() > 0){ | |
| 97 | + if (event.getGbStreams() != null && event.getGbStreams().length > 0){ | |
| 98 | 98 | for (GbStream gbStream : event.getGbStreams()) { |
| 99 | 99 | DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform.getDeviceGBId()); |
| 100 | 100 | deviceChannelList.add(deviceChannelByStream); |
| ... | ... | @@ -134,7 +134,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> { |
| 134 | 134 | if (event.getDeviceChannels() != null) { |
| 135 | 135 | deviceChannelList.addAll(event.getDeviceChannels()); |
| 136 | 136 | } |
| 137 | - if (event.getGbStreams() != null && event.getGbStreams().size() > 0){ | |
| 137 | + if (event.getGbStreams() != null && event.getGbStreams().length > 0){ | |
| 138 | 138 | for (GbStream gbStream : event.getGbStreams()) { |
| 139 | 139 | DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform.getDeviceGBId()); |
| 140 | 140 | deviceChannelList.add(deviceChannelByStream); | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| ... | ... | @@ -371,7 +371,7 @@ public class ZLMHttpHookListener { |
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | if (gbStreams.size() > 0) { |
| 374 | - eventPublisher.catalogEventPublishForStream(null, gbStreams, CatalogEvent.ON); | |
| 374 | + eventPublisher.catalogEventPublishForStream(null, gbStreams.toArray(new GbStream[0]), CatalogEvent.ON); | |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | }else { | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java
| ... | ... | @@ -68,4 +68,6 @@ public interface IStreamPushService { |
| 68 | 68 | void batchAdd(List<StreamPushItem> streamPushExcelDtoList); |
| 69 | 69 | |
| 70 | 70 | boolean batchStop(List<GbStream> streamPushItems); |
| 71 | + | |
| 72 | + void batchAddForUpload(String platformId, String catalogId, List<StreamPushItem> streamPushItems); | |
| 71 | 73 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
| ... | ... | @@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.conf.UserSetup; |
| 8 | 8 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 9 | 9 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; |
| 10 | 10 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 11 | +import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog; | |
| 11 | 12 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 12 | 13 | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| 13 | 14 | import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe; |
| ... | ... | @@ -18,10 +19,7 @@ import com.genersoft.iot.vmp.service.IGbStreamService; |
| 18 | 19 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 19 | 20 | import com.genersoft.iot.vmp.service.IStreamPushService; |
| 20 | 21 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 21 | -import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; | |
| 22 | -import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; | |
| 23 | -import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; | |
| 24 | -import com.genersoft.iot.vmp.storager.dao.StreamPushMapper; | |
| 22 | +import com.genersoft.iot.vmp.storager.dao.*; | |
| 25 | 23 | import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto; |
| 26 | 24 | import com.github.pagehelper.PageHelper; |
| 27 | 25 | import com.github.pagehelper.PageInfo; |
| ... | ... | @@ -44,6 +42,9 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 44 | 42 | private ParentPlatformMapper parentPlatformMapper; |
| 45 | 43 | |
| 46 | 44 | @Autowired |
| 45 | + private PlatformCatalogMapper platformCatalogMapper; | |
| 46 | + | |
| 47 | + @Autowired | |
| 47 | 48 | private PlatformGbStreamMapper platformGbStreamMapper; |
| 48 | 49 | |
| 49 | 50 | @Autowired |
| ... | ... | @@ -95,13 +96,12 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 95 | 96 | streamPushItem.setMediaServerId(item.getMediaServerId()); |
| 96 | 97 | streamPushItem.setStream(item.getStream()); |
| 97 | 98 | streamPushItem.setAliveSecond(item.getAliveSecond()); |
| 98 | - streamPushItem.setCreateStamp(item.getCreateStamp()); | |
| 99 | 99 | streamPushItem.setOriginSock(item.getOriginSock()); |
| 100 | 100 | streamPushItem.setTotalReaderCount(item.getTotalReaderCount()); |
| 101 | 101 | streamPushItem.setOriginType(item.getOriginType()); |
| 102 | 102 | streamPushItem.setOriginTypeStr(item.getOriginTypeStr()); |
| 103 | 103 | streamPushItem.setOriginUrl(item.getOriginUrl()); |
| 104 | - streamPushItem.setCreateStamp(item.getCreateStamp()); | |
| 104 | + streamPushItem.setCreateStamp(item.getCreateStamp() * 1000); | |
| 105 | 105 | streamPushItem.setAliveSecond(item.getAliveSecond()); |
| 106 | 106 | streamPushItem.setStatus(true); |
| 107 | 107 | streamPushItem.setStreamType("push"); |
| ... | ... | @@ -359,6 +359,27 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | @Override |
| 362 | + public void batchAddForUpload(String platformId, String catalogId, List<StreamPushItem> streamPushItems) { | |
| 363 | + streamPushMapper.addAll(streamPushItems); | |
| 364 | + gbStreamMapper.batchAdd(streamPushItems); | |
| 365 | + if (platformId != null) { | |
| 366 | + ParentPlatform platform = parentPlatformMapper.getParentPlatByServerGBId(platformId); | |
| 367 | + if (platform != null) { | |
| 368 | + if (catalogId == null) { | |
| 369 | + catalogId = platform.getCatalogId(); | |
| 370 | + }else { | |
| 371 | + PlatformCatalog catalog = platformCatalogMapper.select(catalogId); | |
| 372 | + if (catalog == null) { | |
| 373 | + return; | |
| 374 | + } | |
| 375 | + } | |
| 376 | + platformGbStreamMapper.batchAdd(platformId, catalogId, streamPushItems); | |
| 377 | + eventPublisher.catalogEventPublishForStream(platformId, streamPushItems.toArray(new GbStream[0]), CatalogEvent.ADD); | |
| 378 | + } | |
| 379 | + } | |
| 380 | + } | |
| 381 | + | |
| 382 | + @Override | |
| 362 | 383 | public boolean batchStop(List<GbStream> gbStreams) { |
| 363 | 384 | if (gbStreams == null || gbStreams.size() == 0) { |
| 364 | 385 | return false; | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java
| ... | ... | @@ -7,10 +7,7 @@ import com.genersoft.iot.vmp.service.IStreamPushService; |
| 7 | 7 | import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto; |
| 8 | 8 | import org.springframework.util.StringUtils; |
| 9 | 9 | |
| 10 | -import java.util.ArrayList; | |
| 11 | -import java.util.HashSet; | |
| 12 | -import java.util.List; | |
| 13 | -import java.util.Set; | |
| 10 | +import java.util.*; | |
| 14 | 11 | |
| 15 | 12 | public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPushExcelDto> { |
| 16 | 13 | |
| ... | ... | @@ -18,10 +15,13 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPus |
| 18 | 15 | private IStreamPushService pushService; |
| 19 | 16 | private String defaultMediaServerId; |
| 20 | 17 | private List<StreamPushItem> streamPushItems = new ArrayList<>(); |
| 18 | + private Map<String, UploadData> streamPushItemsForPlatform = new HashMap<>(); | |
| 21 | 19 | private Set<String> streamPushStreamSet = new HashSet<>(); |
| 22 | 20 | private Set<String> streamPushGBSet = new HashSet<>(); |
| 23 | 21 | private List<String> errorStreamList = new ArrayList<>(); |
| 24 | 22 | private List<String> errorGBList = new ArrayList<>(); |
| 23 | + // 读取数量计数器 | |
| 24 | + private int loadedSize = 0; | |
| 25 | 25 | |
| 26 | 26 | public StreamPushUploadFileHandler(IStreamPushService pushService, String defaultMediaServerId, ErrorDataHandler errorDataHandler) { |
| 27 | 27 | this.pushService = pushService; |
| ... | ... | @@ -33,6 +33,16 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPus |
| 33 | 33 | void handle(List<String> streams, List<String> gbId); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | + private class UploadData{ | |
| 37 | + public String platformId; | |
| 38 | + public Map<String, List<StreamPushItem>> catalogData = new HashMap<>(); | |
| 39 | + public List<StreamPushItem> streamPushItems = new ArrayList<>(); | |
| 40 | + | |
| 41 | + public UploadData(String platformId) { | |
| 42 | + this.platformId = platformId; | |
| 43 | + } | |
| 44 | + } | |
| 45 | + | |
| 36 | 46 | @Override |
| 37 | 47 | public void invoke(StreamPushExcelDto streamPushExcelDto, AnalysisContext analysisContext) { |
| 38 | 48 | if (StringUtils.isEmpty(streamPushExcelDto.getApp()) |
| ... | ... | @@ -43,10 +53,10 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPus |
| 43 | 53 | if (streamPushGBSet.contains(streamPushExcelDto.getGbId())) { |
| 44 | 54 | errorGBList.add(streamPushExcelDto.getGbId()); |
| 45 | 55 | } |
| 46 | - if (streamPushStreamSet.contains(streamPushExcelDto.getApp() + streamPushExcelDto.getStream())) { | |
| 56 | + if (streamPushStreamSet.contains(streamPushExcelDto.getApp() + streamPushExcelDto.getStream() + streamPushExcelDto.getPlatformId())) { | |
| 47 | 57 | errorStreamList.add(streamPushExcelDto.getApp() + "/" + streamPushExcelDto.getStream()); |
| 48 | 58 | } |
| 49 | - if (streamPushGBSet.contains(streamPushExcelDto.getGbId()) || streamPushStreamSet.contains(streamPushExcelDto.getApp() + streamPushExcelDto.getStream())) { | |
| 59 | + if (streamPushGBSet.contains(streamPushExcelDto.getGbId()) || streamPushStreamSet.contains(streamPushExcelDto.getApp() + streamPushExcelDto.getStream() + streamPushExcelDto.getPlatformId())) { | |
| 50 | 60 | return; |
| 51 | 61 | } |
| 52 | 62 | |
| ... | ... | @@ -62,24 +72,69 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPus |
| 62 | 72 | streamPushItem.setOriginType(2); |
| 63 | 73 | streamPushItem.setOriginTypeStr("rtsp_push"); |
| 64 | 74 | streamPushItem.setTotalReaderCount("0"); |
| 65 | - streamPushItems.add(streamPushItem); | |
| 75 | + streamPushItem.setPlatformId(streamPushExcelDto.getPlatformId()); | |
| 76 | + streamPushItem.setCatalogId(streamPushExcelDto.getCatalogId()); | |
| 77 | + if (StringUtils.isEmpty(streamPushExcelDto.getPlatformId())) { | |
| 78 | + streamPushItems.add(streamPushItem); | |
| 79 | + }else { | |
| 80 | + UploadData uploadData = streamPushItemsForPlatform.get(streamPushExcelDto.getPlatformId()); | |
| 81 | + if (uploadData == null) { | |
| 82 | + uploadData = new UploadData(streamPushExcelDto.getPlatformId()); | |
| 83 | + streamPushItemsForPlatform.put(streamPushExcelDto.getPlatformId(), uploadData); | |
| 84 | + } | |
| 85 | + if (!StringUtils.isEmpty(streamPushExcelDto.getCatalogId())) { | |
| 86 | + List<StreamPushItem> streamPushItems = uploadData.catalogData.get(streamPushExcelDto.getCatalogId()); | |
| 87 | + if (streamPushItems == null) { | |
| 88 | + streamPushItems = new ArrayList<>(); | |
| 89 | + uploadData.catalogData.put(streamPushExcelDto.getCatalogId(), streamPushItems); | |
| 90 | + } | |
| 91 | + streamPushItems.add(streamPushItem); | |
| 92 | + }else { | |
| 93 | + uploadData.streamPushItems.add(streamPushItem); | |
| 94 | + } | |
| 95 | + | |
| 96 | + } | |
| 97 | + | |
| 66 | 98 | streamPushGBSet.add(streamPushExcelDto.getGbId()); |
| 67 | 99 | streamPushStreamSet.add(streamPushExcelDto.getApp()+streamPushExcelDto.getStream()); |
| 68 | - if (streamPushItems.size() > 300) { | |
| 69 | - pushService.batchAdd(streamPushItems); | |
| 70 | - // 存储完成清理 list | |
| 100 | + loadedSize ++; | |
| 101 | + if (loadedSize > 1000) { | |
| 102 | + saveData(); | |
| 71 | 103 | streamPushItems.clear(); |
| 104 | + streamPushItemsForPlatform.clear(); | |
| 105 | + loadedSize = 0; | |
| 72 | 106 | } |
| 107 | + | |
| 73 | 108 | } |
| 74 | 109 | |
| 75 | 110 | @Override |
| 76 | 111 | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| 77 | 112 | // 这里也要保存数据,确保最后遗留的数据也存储到数据库 |
| 78 | - if (streamPushItems.size() > 0) { | |
| 79 | - pushService.batchAdd(streamPushItems); | |
| 80 | - } | |
| 113 | + saveData(); | |
| 81 | 114 | streamPushGBSet.clear(); |
| 82 | 115 | streamPushStreamSet.clear(); |
| 83 | 116 | errorDataHandler.handle(errorStreamList, errorGBList); |
| 84 | 117 | } |
| 118 | + | |
| 119 | + private void saveData(){ | |
| 120 | + if (streamPushItems.size() > 0) { | |
| 121 | + pushService.batchAddForUpload(null, null, streamPushItems); | |
| 122 | + } | |
| 123 | + // 处理已分配到平台的流 | |
| 124 | + if (streamPushItemsForPlatform.size() > 0){ | |
| 125 | + for (String platformId : streamPushItemsForPlatform.keySet()) { | |
| 126 | + UploadData uploadData = streamPushItemsForPlatform.get(platformId); | |
| 127 | + if (uploadData.streamPushItems.size() > 0) { | |
| 128 | + pushService.batchAddForUpload(platformId, null, uploadData.streamPushItems); | |
| 129 | + } | |
| 130 | + if (uploadData.catalogData.size() > 0) { | |
| 131 | + for (String catalogId : uploadData.catalogData.keySet()) { | |
| 132 | + if (uploadData.catalogData.get(catalogId).size() > 0) { | |
| 133 | + pushService.batchAddForUpload(platformId, catalogId, uploadData.catalogData.get(catalogId)); | |
| 134 | + } | |
| 135 | + } | |
| 136 | + } | |
| 137 | + } | |
| 138 | + } | |
| 139 | + } | |
| 85 | 140 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformGbStreamMapper.java
| ... | ... | @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.bean.PlatformGbStream; |
| 7 | 7 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| 8 | +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | |
| 8 | 9 | import org.apache.ibatis.annotations.*; |
| 9 | 10 | import org.springframework.stereotype.Repository; |
| 10 | 11 | |
| ... | ... | @@ -19,6 +20,17 @@ public interface PlatformGbStreamMapper { |
| 19 | 20 | "('${app}', '${stream}', '${platformId}', '${catalogId}')") |
| 20 | 21 | int add(PlatformGbStream platformGbStream); |
| 21 | 22 | |
| 23 | + | |
| 24 | + @Insert("<script> " + | |
| 25 | + "REPLACE into platform_gb_stream " + | |
| 26 | + "(app, stream, platformId, catalogId) " + | |
| 27 | + "values " + | |
| 28 | + "<foreach collection='streamPushItems' index='index' item='item' separator=','> " + | |
| 29 | + "('${item.app}', '${item.stream}', '${platformId}', '${catalogId}')" + | |
| 30 | + "</foreach> " + | |
| 31 | + "</script>") | |
| 32 | + int batchAdd(String platformId, String catalogId, List<StreamPushItem> streamPushItems); | |
| 33 | + | |
| 22 | 34 | @Delete("DELETE FROM platform_gb_stream WHERE app=#{app} AND stream=#{stream}") |
| 23 | 35 | int delByAppAndStream(String app, String stream); |
| 24 | 36 | |
| ... | ... | @@ -82,4 +94,7 @@ public interface PlatformGbStreamMapper { |
| 82 | 94 | "</foreach>" + |
| 83 | 95 | "</script>") |
| 84 | 96 | void delByGbStreams(List<GbStream> gbStreams); |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 85 | 100 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/bean/StreamPushExcelDto.java
| ... | ... | @@ -16,6 +16,12 @@ public class StreamPushExcelDto { |
| 16 | 16 | @ExcelProperty("国标ID") |
| 17 | 17 | private String gbId; |
| 18 | 18 | |
| 19 | + @ExcelProperty("平台ID") | |
| 20 | + private String platformId; | |
| 21 | + | |
| 22 | + @ExcelProperty("目录ID") | |
| 23 | + private String catalogId; | |
| 24 | + | |
| 19 | 25 | public String getName() { |
| 20 | 26 | return name; |
| 21 | 27 | } |
| ... | ... | @@ -47,4 +53,21 @@ public class StreamPushExcelDto { |
| 47 | 53 | public void setGbId(String gbId) { |
| 48 | 54 | this.gbId = gbId; |
| 49 | 55 | } |
| 56 | + | |
| 57 | + | |
| 58 | + public String getPlatformId() { | |
| 59 | + return platformId; | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void setPlatformId(String platformId) { | |
| 63 | + this.platformId = platformId; | |
| 64 | + } | |
| 65 | + | |
| 66 | + public String getCatalogId() { | |
| 67 | + return catalogId; | |
| 68 | + } | |
| 69 | + | |
| 70 | + public void setCatalogId(String catalogId) { | |
| 71 | + this.catalogId = catalogId; | |
| 72 | + } | |
| 50 | 73 | } | ... | ... |
web_src/src/components/PushVideoList.vue
| ... | ... | @@ -233,7 +233,7 @@ |
| 233 | 233 | dateFormat: function(/** timestamp=0 **/) { |
| 234 | 234 | let ts = arguments[0] || 0; |
| 235 | 235 | let t,y,m,d,h,i,s; |
| 236 | - t = ts ? new Date(ts*1000) : new Date(); | |
| 236 | + t = ts ? new Date(ts) : new Date(); | |
| 237 | 237 | y = t.getFullYear(); |
| 238 | 238 | m = t.getMonth()+1; |
| 239 | 239 | d = t.getDate(); | ... | ... |