|
@@ -810,48 +810,68 @@ public class DahuaServiceImpl extends BaseService implements DahuaService {
|
|
|
|
|
|
@Override
|
|
|
public AjaxResult reportMp4ToFileService(List<DaHuaMp4VO> mp4VOList) {
|
|
|
- if(mp4VOList.isEmpty()){
|
|
|
+ if (mp4VOList.isEmpty()) {
|
|
|
return AjaxResult.error("请求参数为空!");
|
|
|
}
|
|
|
+
|
|
|
String token = dahuaService.getToken();
|
|
|
String baseUrl = host + "/evo-apigw/evo-gmai/1.4.0/ai/history/task/getAlarmVideo";
|
|
|
String downloadUrl = host + "/evo-apigw/evo-oss/";
|
|
|
|
|
|
+ List<String> successIds = new ArrayList<>();
|
|
|
+ List<String> failureIds = new ArrayList<>();
|
|
|
+
|
|
|
mp4VOList.forEach(mp4VO -> {
|
|
|
- //发送get请求, 获取MP4地址.
|
|
|
try {
|
|
|
- String videoUrl = downloadUrl + VideoUrlFetcher.getVideoUrl(baseUrl, mp4VO.getChnnaleCode(), mp4VO.getAlarmCode(), token) + "?token=" + token;
|
|
|
- //上传到文件服务器
|
|
|
+ // 发送GET请求,获取MP4地址
|
|
|
+ String videoUrl = downloadUrl + VideoUrlFetcher.getVideoUrl(baseUrl, mp4VO.getChannelCode(), mp4VO.getAlarmCode(), token) + "?token=" + token;
|
|
|
+ // 上传到文件服务器
|
|
|
R<SysFile> sysFileR = fileBaseService.upload(convertUrlToMultipartFile(videoUrl));
|
|
|
+
|
|
|
if (sysFileR.getCode() == 200) {
|
|
|
log.info("reportMp4ToFileService => 文件上传成功!{}", sysFileR.getData().getUrl());
|
|
|
- //保存到数据中心
|
|
|
- CenterdataTAttach attach = new CenterdataTAttach();
|
|
|
- attach.setBusId(mp4VO.getLogId());
|
|
|
- attach.setAttachPath(sysFileR.getData().getUrl());
|
|
|
- attach.setFileName(sysFileR.getData().getName());
|
|
|
- attach.setBusSource("PC");
|
|
|
- attach.setFileType("video");
|
|
|
- dataBaseService.insertAttach(attach);
|
|
|
+ // 保存到数据中心
|
|
|
+ saveAttachToDataBase(mp4VO, sysFileR.getData());
|
|
|
+ // 保存下载结果到事件中心
|
|
|
+ saveDownloadResult(mp4VO, sysFileR.getData().getUrl(), sysFileR.getCode(), sysFileR.getMsg());
|
|
|
+ successIds.add(mp4VO.getId());
|
|
|
} else {
|
|
|
- log.info("getPlaybackByTime => 文件上传失败!{}", sysFileR.getMsg());
|
|
|
+ log.info("reportMp4ToFileService => 文件上传失败!{}", sysFileR.getMsg());
|
|
|
+ saveDownloadResult(mp4VO, null, sysFileR.getCode(), sysFileR.getMsg());
|
|
|
+ failureIds.add(mp4VO.getId());
|
|
|
}
|
|
|
-
|
|
|
- //将视频下载结果保存至事件中心
|
|
|
- CentereventTDownloads downloads = new CentereventTDownloads();
|
|
|
- downloads.setId(mp4VO.getId());
|
|
|
- if (sysFileR.getCode() == HttpStatus.SUCCESS) {
|
|
|
- downloads.setPath(sysFileR.getData().getUrl());
|
|
|
- }
|
|
|
- downloads.setFlag(String.valueOf(sysFileR.getCode()));
|
|
|
- downloads.setReason(sysFileR.getMsg());
|
|
|
- eventBaseService.downloads(downloads);
|
|
|
-
|
|
|
} catch (Exception e) {
|
|
|
- log.error("alarmCode={}, chnnaleCode={}, 下载视频失败,{}", mp4VO.getAlarmCode(), mp4VO.getChnnaleCode(), e.getMessage());
|
|
|
+ log.error("alarmCode={}, channelCode={}, 下载视频失败,{}", mp4VO.getAlarmCode(), mp4VO.getChannelCode(), e.getMessage());
|
|
|
+ saveDownloadResult(mp4VO, null, HttpStatus.ERROR, e.getMessage());
|
|
|
+ failureIds.add(mp4VO.getId());
|
|
|
}
|
|
|
});
|
|
|
- return AjaxResult.success("下载成功");
|
|
|
+
|
|
|
+ if (!failureIds.isEmpty()) {
|
|
|
+ return AjaxResult.error("部分视频下载失败,失败的ID列表:" + String.join(", ", failureIds));
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success("所有视频下载成功!");
|
|
|
}
|
|
|
|
|
|
+ private void saveAttachToDataBase(DaHuaMp4VO mp4VO, SysFile sysFile) {
|
|
|
+ CenterdataTAttach attach = new CenterdataTAttach();
|
|
|
+ attach.setBusId(mp4VO.getLogId());
|
|
|
+ attach.setAttachPath(sysFile.getUrl());
|
|
|
+ attach.setFileName(sysFile.getName());
|
|
|
+ attach.setBusSource("PC");
|
|
|
+ attach.setFileType("video");
|
|
|
+ dataBaseService.insertAttach(attach);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveDownloadResult(DaHuaMp4VO mp4VO, String path, int code, String message) {
|
|
|
+ CentereventTDownloads downloads = new CentereventTDownloads();
|
|
|
+ downloads.setId(mp4VO.getId());
|
|
|
+ downloads.setPath(path);
|
|
|
+ downloads.setFlag(String.valueOf(code));
|
|
|
+ downloads.setReason(message);
|
|
|
+ eventBaseService.downloads(downloads);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|