|
@ -4,11 +4,14 @@ import com.alibaba.excel.EasyExcel; |
|
|
import com.alibaba.excel.ExcelReader; |
|
|
import com.alibaba.excel.ExcelReader; |
|
|
import com.alibaba.excel.read.metadata.ReadSheet; |
|
|
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.gb28181.transmit.callback.DeferredResultHolder; |
|
|
|
|
|
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
|
|
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.IMediaServerService; |
|
|
import com.genersoft.iot.vmp.service.IStreamPushService; |
|
|
import com.genersoft.iot.vmp.service.IStreamPushService; |
|
|
import com.genersoft.iot.vmp.service.impl.StreamPushUploadFileHandler; |
|
|
import com.genersoft.iot.vmp.service.impl.StreamPushUploadFileHandler; |
|
|
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto; |
|
|
import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto; |
|
|
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
|
|
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; |
|
@ -18,12 +21,19 @@ 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.http.HttpStatus; |
|
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
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.context.request.async.DeferredResult; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.io.InputStream; |
|
|
import java.io.InputStream; |
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
@Api(tags = "推流信息管理") |
|
|
@Api(tags = "推流信息管理") |
|
|
@Controller |
|
|
@Controller |
|
@ -39,6 +49,9 @@ public class StreamPushController { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private IMediaServerService mediaServerService; |
|
|
private IMediaServerService mediaServerService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private DeferredResultHolder resultHolder; |
|
|
|
|
|
|
|
|
@ApiOperation("推流列表查询") |
|
|
@ApiOperation("推流列表查询") |
|
|
@ApiImplicitParams({ |
|
|
@ApiImplicitParams({ |
|
|
@ApiImplicitParam(name="page", value = "当前页", required = true, dataTypeClass = Integer.class), |
|
|
@ApiImplicitParam(name="page", value = "当前页", required = true, dataTypeClass = Integer.class), |
|
@ -103,10 +116,44 @@ public class StreamPushController { |
|
|
} |
|
|
} |
|
|
@PostMapping(value = "upload") |
|
|
@PostMapping(value = "upload") |
|
|
@ResponseBody |
|
|
@ResponseBody |
|
|
public String uploadChannelFile(@RequestParam(value = "file") MultipartFile file){ |
|
|
public DeferredResult<ResponseEntity<WVPResult<Object>>> uploadChannelFile(@RequestParam(value = "file") MultipartFile file){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 最多处理文件一个小时
|
|
|
|
|
|
DeferredResult<ResponseEntity<WVPResult<Object>>> result = new DeferredResult<>(60*60*1000L); |
|
|
|
|
|
// 录像查询以channelId作为deviceId查询
|
|
|
|
|
|
String key = DeferredResultHolder.UPLOAD_FILE_CHANNEL; |
|
|
|
|
|
String uuid = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
|
if (file.isEmpty()) { |
|
|
if (file.isEmpty()) { |
|
|
return "fail"; |
|
|
logger.warn("通道导入文件为空"); |
|
|
|
|
|
WVPResult<Object> wvpResult = new WVPResult<>(); |
|
|
|
|
|
wvpResult.setCode(-1); |
|
|
|
|
|
wvpResult.setMsg("文件为空"); |
|
|
|
|
|
result.setResult(ResponseEntity.status(HttpStatus.BAD_REQUEST).body(wvpResult)); |
|
|
|
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
// 同时只处理一个文件
|
|
|
|
|
|
if (resultHolder.exist(key, null)) { |
|
|
|
|
|
logger.warn("已有导入任务正在执行"); |
|
|
|
|
|
WVPResult<Object> wvpResult = new WVPResult<>(); |
|
|
|
|
|
wvpResult.setCode(-1); |
|
|
|
|
|
wvpResult.setMsg("已有导入任务正在执行"); |
|
|
|
|
|
result.setResult(ResponseEntity.status(HttpStatus.TOO_MANY_REQUESTS).body(wvpResult)); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resultHolder.put(key, uuid, result); |
|
|
|
|
|
result.onTimeout(()->{ |
|
|
|
|
|
logger.warn("通道导入超时,可能文件过大"); |
|
|
|
|
|
RequestMessage msg = new RequestMessage(); |
|
|
|
|
|
msg.setKey(key); |
|
|
|
|
|
WVPResult<Object> wvpResult = new WVPResult<>(); |
|
|
|
|
|
wvpResult.setCode(-1); |
|
|
|
|
|
wvpResult.setMsg("导入超时,可能文件过大"); |
|
|
|
|
|
msg.setData(wvpResult); |
|
|
|
|
|
resultHolder.invokeAllResult(msg); |
|
|
|
|
|
}); |
|
|
//获取文件流
|
|
|
//获取文件流
|
|
|
InputStream inputStream = null; |
|
|
InputStream inputStream = null; |
|
|
try { |
|
|
try { |
|
@ -117,11 +164,29 @@ public class StreamPushController { |
|
|
} |
|
|
} |
|
|
//传入参数
|
|
|
//传入参数
|
|
|
ExcelReader excelReader = EasyExcel.read(inputStream, StreamPushExcelDto.class, |
|
|
ExcelReader excelReader = EasyExcel.read(inputStream, StreamPushExcelDto.class, |
|
|
new StreamPushUploadFileHandler(streamPushService, mediaServerService.getDefaultMediaServer().getId())).build(); |
|
|
new StreamPushUploadFileHandler(streamPushService, mediaServerService.getDefaultMediaServer().getId(), (errorStreams, errorGBs)->{ |
|
|
|
|
|
logger.info("通道导入成功,存在重复App+Stream为{}个,存在国标ID为{}个", errorStreams.size(), errorGBs.size()); |
|
|
|
|
|
RequestMessage msg = new RequestMessage(); |
|
|
|
|
|
msg.setKey(key); |
|
|
|
|
|
WVPResult<Map<String, List<String>>> wvpResult = new WVPResult<>(); |
|
|
|
|
|
if (errorStreams.size() == 0 && errorGBs.size() == 0) { |
|
|
|
|
|
wvpResult.setCode(0); |
|
|
|
|
|
wvpResult.setMsg("成功"); |
|
|
|
|
|
}else { |
|
|
|
|
|
wvpResult.setCode(1); |
|
|
|
|
|
wvpResult.setMsg("导入成功。但是存在重复数据"); |
|
|
|
|
|
Map<String, List<String>> errorData = new HashMap<>(); |
|
|
|
|
|
errorData.put("gbId", errorGBs); |
|
|
|
|
|
errorData.put("stream", errorStreams); |
|
|
|
|
|
wvpResult.setData(errorData); |
|
|
|
|
|
} |
|
|
|
|
|
msg.setData(wvpResult); |
|
|
|
|
|
resultHolder.invokeAllResult(msg); |
|
|
|
|
|
})).build(); |
|
|
ReadSheet readSheet = EasyExcel.readSheet(0).build(); |
|
|
ReadSheet readSheet = EasyExcel.readSheet(0).build(); |
|
|
excelReader.read(readSheet); |
|
|
excelReader.read(readSheet); |
|
|
excelReader.finish(); |
|
|
excelReader.finish(); |
|
|
return "success"; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|