소스 검색

定时任务视频下载

Memory_LG 5 일 전
부모
커밋
9d6c2e0427

+ 1 - 1
src/main/java/com/sooka/sponest/monitor/dahua/controller/DahuaController.java

@@ -296,7 +296,7 @@ public class DahuaController {
     }
 
     @PostMapping("/reportMp4ToFileService")
-    public AjaxResult reportMp4ToFileService(@RequestBody DaHuaMp4VO mp4VO) throws IOException, ClientException {
+    public AjaxResult reportMp4ToFileService(@RequestBody List<DaHuaMp4VO> mp4VO){
         return dahuaService.reportMp4ToFileService(mp4VO);
     }
 

+ 1 - 0
src/main/java/com/sooka/sponest/monitor/dahua/domain/DaHuaMp4VO.java

@@ -11,6 +11,7 @@ import org.apache.ibatis.type.Alias;
 @ToString
 @Alias("daHuaMp4VO")
 public class DaHuaMp4VO {
+    private String id;
     private String chnnaleCode;
     private String alarmCode;
     private String logId;

+ 1 - 1
src/main/java/com/sooka/sponest/monitor/dahua/service/DahuaService.java

@@ -117,5 +117,5 @@ public interface DahuaService {
     */
     AjaxResult cameraSteering(Double lng, Double lat, List<String> list);
 
-    AjaxResult reportMp4ToFileService(DaHuaMp4VO mp4VO) throws IOException, ClientException;
+    AjaxResult reportMp4ToFileService(List<DaHuaMp4VO> mp4VO);
 }

+ 41 - 29
src/main/java/com/sooka/sponest/monitor/dahua/service/impl/DahuaServiceImpl.java

@@ -42,12 +42,10 @@ import com.sooka.sponest.monitor.util.VideoUrlFetcher;
 import org.apache.commons.collections4.CollectionUtils;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.crypto.Cipher;
 import java.io.File;
-import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.security.KeyFactory;
 import java.security.interfaces.RSAPublicKey;
@@ -811,35 +809,49 @@ public class DahuaServiceImpl extends BaseService implements DahuaService {
     }
 
     @Override
-    public AjaxResult reportMp4ToFileService(DaHuaMp4VO mp4VO) throws IOException, ClientException {
+    public AjaxResult reportMp4ToFileService(List<DaHuaMp4VO> mp4VOList) {
+        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/";
-        //发送get请求, 获取MP4地址.
-        String videoUrl = downloadUrl + VideoUrlFetcher.getVideoUrl(baseUrl, mp4VO.getChnnaleCode(), mp4VO.getAlarmCode(), token) + "?token="+token;
-        try {
-            //上传到文件服务器
-            R<SysFile> sysFileR = fileBaseService.upload(convertUrlToMultipartFile(videoUrl));
-            if (sysFileR.getCode() == 200) {
-                log.info("getPlaybackByTime => 文件上传成功!{}", 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);*/
-            } else {
-                log.info("getPlaybackByTime => 文件上传失败!{}", sysFileR.getMsg());
-            }
+        String baseUrl = host + "/evo-apigw/evo-gmai/1.4.0/ai/history/task/getAlarmVideo";
+        String downloadUrl = host + "/evo-apigw/evo-oss/";
 
-            return AjaxResult.success("下载成功");
-        } catch (IOException e) {
-            e.printStackTrace();
-            return AjaxResult.error(e.getMessage());
-        }
-    }
+        mp4VOList.forEach(mp4VO -> {
+            //发送get请求, 获取MP4地址.
+            try {
+                String videoUrl = downloadUrl + VideoUrlFetcher.getVideoUrl(baseUrl, mp4VO.getChnnaleCode(), mp4VO.getAlarmCode(), token) + "?token=" + token;
+                //上传到文件服务器
+                R<SysFile> sysFileR = fileBaseService.upload(convertUrlToMultipartFile(videoUrl));
+                if (sysFileR.getCode() == 200) {
+                    log.info("getPlaybackByTime => 文件上传成功!{}", 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);
+                } else {
+                    log.info("getPlaybackByTime => 文件上传失败!{}", sysFileR.getMsg());
+                }
+
+                //将视频下载结果保存至事件中心
+                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());
+            }
+        });
+        return AjaxResult.success("下载成功");
+    }
 
 }