Browse Source

支持推流通道预导入

pull/317/head
648540858 3 years ago
parent
commit
06e22d980e
  1. 9
      pom.xml
  2. 2
      src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
  3. 3
      src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java
  4. 34
      src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
  5. 50
      src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java
  6. 4
      src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java
  7. 2
      src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java
  8. 50
      src/main/java/com/genersoft/iot/vmp/vmanager/bean/StreamPushExcelDto.java
  9. 38
      src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java
  10. 18
      web_src/src/components/PushVideoList.vue
  11. 84
      web_src/src/components/dialog/importChannel.vue

9
pom.xml

@ -161,7 +161,7 @@
<version>2.1.3</version> <version>2.1.3</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <!-- json解析库fastjson -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson</artifactId>
@ -203,6 +203,13 @@
<version>1.12</version> <version>1.12</version>
</dependency> </dependency>
<!--excel解析库-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>3.0.4</version>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.session</groupId> <groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId> <artifactId>spring-session-core</artifactId>

2
src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java

@ -85,7 +85,7 @@ public class OnlineEventListener implements ApplicationListener<OnlineEvent> {
device.setOnline(1); device.setOnline(1);
Device deviceInstore = storager.queryVideoDevice(device.getDeviceId()); Device deviceInstore = storager.queryVideoDevice(device.getDeviceId());
if (deviceInstore.getOnline() == 0) { if (deviceInstore != null && deviceInstore.getOnline() == 0) {
List<DeviceChannel> deviceChannelList = storager.queryOnlineChannelsByDeviceId(device.getDeviceId()); List<DeviceChannel> deviceChannelList = storager.queryOnlineChannelsByDeviceId(device.getDeviceId());
eventPublisher.catalogEventPublish(null, deviceChannelList, CatalogEvent.ON); eventPublisher.catalogEventPublish(null, deviceChannelList, CatalogEvent.ON);
} }

3
src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java

@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import java.util.List; import java.util.List;
@ -65,4 +66,6 @@ public interface IStreamPushService {
void clean(); void clean();
boolean saveToRandomGB(); boolean saveToRandomGB();
void batchAdd(List<StreamPushItem> streamPushExcelDtoList);
} }

34
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java

@ -22,6 +22,7 @@ import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
import com.genersoft.iot.vmp.storager.dao.StreamPushMapper; import com.genersoft.iot.vmp.storager.dao.StreamPushMapper;
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -321,4 +322,37 @@ public class StreamPushServiceImpl implements IStreamPushService {
} }
return true; return true;
} }
@Override
public void batchAdd(List<StreamPushItem> streamPushItems) {
streamPushMapper.addAll(streamPushItems);
gbStreamMapper.batchAdd(streamPushItems);
// 查找开启了全部直播流共享的上级平台
List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();
if (parentPlatforms.size() > 0) {
for (StreamPushItem stream : streamPushItems) {
for (ParentPlatform parentPlatform : parentPlatforms) {
stream.setCatalogId(parentPlatform.getCatalogId());
stream.setPlatformId(parentPlatform.getServerGBId());
String streamId = stream.getStream();
StreamProxyItem streamProxyItem = platformGbStreamMapper.selectOne(stream.getApp(), streamId, parentPlatform.getServerGBId());
if (streamProxyItem == null) {
platformGbStreamMapper.add(stream);
eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD);
}else {
if (!streamProxyItem.getGbId().equals(stream.getGbId())) {
// 此流使用另一个国标Id已经与该平台关联,移除此记录
platformGbStreamMapper.delByAppAndStreamAndPlatform(stream.getApp(), streamId, parentPlatform.getServerGBId());
platformGbStreamMapper.add(stream);
eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD);
stream.setGbId(streamProxyItem.getGbId());
eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.DEL);
}
}
}
}
}
}
} }

50
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java

@ -0,0 +1,50 @@
package com.genersoft.iot.vmp.service.impl;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.IStreamPushService;
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
import java.util.ArrayList;
import java.util.List;
public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPushExcelDto> {
private IStreamPushService pushService;
private String defaultMediaServerId;
private List<StreamPushItem> streamPushItems = new ArrayList<>();
public StreamPushUploadFileHandler(IStreamPushService pushService, String defaultMediaServerId) {
this.pushService = pushService;
this.defaultMediaServerId = defaultMediaServerId;
}
@Override
public void invoke(StreamPushExcelDto streamPushExcelDto, AnalysisContext analysisContext) {
StreamPushItem streamPushItem = new StreamPushItem();
streamPushItem.setApp(streamPushExcelDto.getApp());
streamPushItem.setStream(streamPushExcelDto.getStream());
streamPushItem.setGbId(streamPushExcelDto.getGbId());
streamPushItem.setStatus(false);
streamPushItem.setStreamType("push");
streamPushItem.setCreateStamp(System.currentTimeMillis());
streamPushItem.setMediaServerId(defaultMediaServerId);
streamPushItem.setName(streamPushExcelDto.getName());
streamPushItem.setOriginType(2);
streamPushItem.setOriginTypeStr("rtsp_push");
streamPushItem.setTotalReaderCount("0");
streamPushItems.add(streamPushItem);
if (streamPushItems.size() > 300) {
pushService.batchAdd(streamPushItems);
// 存储完成清理 list
streamPushItems.clear();
}
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
// 这里也要保存数据,确保最后遗留的数据也存储到数据库
pushService.batchAdd(streamPushItems);
}
}

4
src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java

@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
import org.apache.ibatis.annotations.*; import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@ -82,7 +83,7 @@ public interface GbStreamMapper {
void batchDel(List<StreamProxyItem> streamProxyItemList); void batchDel(List<StreamProxyItem> streamProxyItemList);
@Insert("<script> " + @Insert("<script> " +
"insert into gb_stream " + "REPLACE into gb_stream " +
"(app, stream, gbId, name, " + "(app, stream, gbId, name, " +
"longitude, latitude, streamType, mediaServerId, status)" + "longitude, latitude, streamType, mediaServerId, status)" +
"values " + "values " +
@ -94,7 +95,6 @@ public interface GbStreamMapper {
"</script>") "</script>")
void batchAdd(List<StreamPushItem> subList); void batchAdd(List<StreamPushItem> subList);
@Update({"<script>" + @Update({"<script>" +
"<foreach collection='gpsMsgInfos' item='item' separator=';'>" + "<foreach collection='gpsMsgInfos' item='item' separator=';'>" +
" UPDATE" + " UPDATE" +

2
src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java

@ -52,7 +52,7 @@ public interface StreamPushMapper {
@Insert("<script>" + @Insert("<script>" +
"INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " + "INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
"createStamp, aliveSecond, mediaServerId) " + "createStamp, aliveSecond, mediaServerId) " +
"VALUES <foreach collection='streamPushItems' item='item' index='index' >" + "VALUES <foreach collection='streamPushItems' item='item' index='index' separator=','>" +
"( '${item.app}', '${item.stream}', '${item.totalReaderCount}', '${item.originType}', " + "( '${item.app}', '${item.stream}', '${item.totalReaderCount}', '${item.originType}', " +
"'${item.originTypeStr}','${item.createStamp}', '${item.aliveSecond}', '${item.mediaServerId}' )" + "'${item.originTypeStr}','${item.createStamp}', '${item.aliveSecond}', '${item.mediaServerId}' )" +
" </foreach>" + " </foreach>" +

50
src/main/java/com/genersoft/iot/vmp/vmanager/bean/StreamPushExcelDto.java

@ -0,0 +1,50 @@
package com.genersoft.iot.vmp.vmanager.bean;
import com.alibaba.excel.annotation.ExcelProperty;
public class StreamPushExcelDto {
@ExcelProperty("名称")
private String name;
@ExcelProperty("应用名")
private String app;
@ExcelProperty("流ID")
private String stream;
@ExcelProperty("国标ID")
private String gbId;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getApp() {
return app;
}
public void setApp(String app) {
this.app = app;
}
public String getStream() {
return stream;
}
public void setStream(String stream) {
this.stream = stream;
}
public String getGbId() {
return gbId;
}
public void setGbId(String gbId) {
this.gbId = gbId;
}
}

38
src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java

@ -1,19 +1,29 @@
package com.genersoft.iot.vmp.vmanager.streamPush; package com.genersoft.iot.vmp.vmanager.streamPush;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IStreamPushService; import com.genersoft.iot.vmp.service.IStreamPushService;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.genersoft.iot.vmp.service.impl.StreamPushUploadFileHandler;
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.poi.sl.usermodel.Sheet;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
@Api(tags = "推流信息管理") @Api(tags = "推流信息管理")
@Controller @Controller
@ -26,6 +36,9 @@ public class StreamPushController {
@Autowired @Autowired
private IStreamPushService streamPushService; private IStreamPushService streamPushService;
@Autowired
private IMediaServerService mediaServerService;
@ApiOperation("推流列表查询") @ApiOperation("推流列表查询")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name="page", value = "当前页", required = true, dataTypeClass = Integer.class), @ApiImplicitParam(name="page", value = "当前页", required = true, dataTypeClass = Integer.class),
@ -88,5 +101,28 @@ public class StreamPushController {
return "fail"; return "fail";
} }
} }
@PostMapping(value = "upload")
@ResponseBody
public String uploadChannelFile(@RequestParam(value = "file") MultipartFile file){
if (file.isEmpty()) {
return "fail";
}
//获取文件流
InputStream inputStream = null;
try {
String name = file.getName();
inputStream = file.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
//传入参数
ExcelReader excelReader = EasyExcel.read(inputStream, StreamPushExcelDto.class,
new StreamPushUploadFileHandler(streamPushService, mediaServerService.getDefaultMediaServer().getId())).build();
ReadSheet readSheet = EasyExcel.readSheet(0).build();
excelReader.read(readSheet);
excelReader.finish();
return "success";
}
} }

18
web_src/src/components/PushVideoList.vue

@ -8,6 +8,13 @@
<div style="background-color: #FFFFFF; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left;"> <div style="background-color: #FFFFFF; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left;">
<span style="font-size: 1rem; font-weight: bold;">推流列表</span> <span style="font-size: 1rem; font-weight: bold;">推流列表</span>
</div> </div>
<div style="background-color: #FFFFFF; margin-bottom: 1rem; position: relative; padding: 0.5rem; text-align: left;font-size: 14px;">
<el-button icon="el-icon-upload2" size="mini" style="margin-right: 1rem;" type="primary" @click="importChannel">通道导入</el-button>
<el-button icon="el-icon-download" size="mini" style="margin-right: 1rem;" type="primary" >
<a style="color: #FFFFFF; text-align: center; text-decoration: none" href="/static/file/推流通道导入.zip" download='推流通道导入.zip' >下载模板</a>
</el-button>
</div>
<devicePlayer ref="devicePlayer"></devicePlayer> <devicePlayer ref="devicePlayer"></devicePlayer>
<addStreamTOGB ref="addStreamTOGB"></addStreamTOGB> <addStreamTOGB ref="addStreamTOGB"></addStreamTOGB>
<el-table :data="pushList" border style="width: 100%" :height="winHeight"> <el-table :data="pushList" border style="width: 100%" :height="winHeight">
@ -54,6 +61,7 @@
:total="total"> :total="total">
</el-pagination> </el-pagination>
<streamProxyEdit ref="streamProxyEdit" ></streamProxyEdit> <streamProxyEdit ref="streamProxyEdit" ></streamProxyEdit>
<importChannel ref="importChannel" ></importChannel>
</el-main> </el-main>
</el-container> </el-container>
</div> </div>
@ -64,13 +72,15 @@
import devicePlayer from './dialog/devicePlayer.vue' import devicePlayer from './dialog/devicePlayer.vue'
import addStreamTOGB from './dialog/addStreamTOGB.vue' import addStreamTOGB from './dialog/addStreamTOGB.vue'
import uiHeader from './UiHeader.vue' import uiHeader from './UiHeader.vue'
import importChannel from './dialog/importChannel.vue'
export default { export default {
name: 'pushVideoList', name: 'pushVideoList',
components: { components: {
devicePlayer, devicePlayer,
addStreamTOGB, addStreamTOGB,
streamProxyEdit, streamProxyEdit,
uiHeader uiHeader,
importChannel,
}, },
data() { data() {
return { return {
@ -196,8 +206,12 @@
s = t.getSeconds(); s = t.getSeconds();
// //
return y+'-'+(m<10?'0'+m:m)+'-'+(d<10?'0'+d:d)+' '+(h<10?'0'+h:h)+':'+(i<10?'0'+i:i)+':'+(s<10?'0'+s:s); return y+'-'+(m<10?'0'+m:m)+'-'+(d<10?'0'+d:d)+' '+(h<10?'0'+h:h)+':'+(i<10?'0'+i:i)+':'+(s<10?'0'+s:s);
} },
importChannel: function () {
this.$refs.importChannel.openDialog(()=>{
})
},
} }
}; };
</script> </script>

84
web_src/src/components/dialog/importChannel.vue

@ -0,0 +1,84 @@
<template>
<div id="importChannel" v-loading="isLoging">
<el-dialog
title="导入通道数据"
width="30rem"
top="2rem"
:append-to-body="true"
:close-on-click-modal="false"
:visible.sync="showDialog"
:destroy-on-close="true"
@close="close()"
>
<div>
<el-upload
class="upload-box"
drag
action="debug/api/push/upload"
name="file"
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">只能上传 csv / xls / xlsx 文件</div>
</el-upload>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
name: "importChannel",
computed: {},
created() {},
data() {
return {
submitCallback: null,
showDialog: false,
isLoging: false,
isEdit: false,
};
},
methods: {
openDialog: function (callback) {
this.showDialog = true;
this.submitCallback = callback;
},
onSubmit: function () {
console.log("onSubmit");
console.log(this.form);
this.$axios({
method:"post",
url:`/api/platform/catalog/${!this.isEdit? "add":"edit"}`,
data: this.form
})
.then((res)=> {
if (res.data.code === 0) {
console.log("添加/修改成功")
if (this.submitCallback)this.submitCallback()
}else {
this.$message({
showClose: true,
message: res.data.msg,
type: "error",
});
}
this.close();
})
.catch((error)=> {
console.log(error);
});
},
close: function () {
this.showDialog = false;
this.$refs.form.resetFields();
},
},
};
</script>
<style>
.upload-box{
text-align: center;
}
</style>
Loading…
Cancel
Save