ソースを参照

调用天网接口添加异常捕获

gao.qiang 1 年間 前
コミット
16dd26ba87
1 ファイル変更27 行追加8 行削除
  1. 27 8
      business-service/src/main/java/com/ozs/utils/CameraUtil.java

+ 27 - 8
business-service/src/main/java/com/ozs/utils/CameraUtil.java

@@ -889,7 +889,12 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
         //对象转换json字符串
         String body = JSONObject.toJSONString(playbackVo);
         //调用天网接口
-        String playbackURLs = getPreviewURLs("/api/video/v1/cameras/playbackURLs", body);
+        String playbackURLs = null;
+        try {
+            playbackURLs = getPreviewURLs("/api/video/v1/cameras/playbackURLs", body);
+        } catch (Exception e) {
+            return "调用天网接口失败";
+        }
         JSONObject outJson = (JSONObject) JSONObject.parse(playbackURLs);
         log.info("outJson-------->" + outJson);
         if ("0".equals(outJson.getString("code"))) {
@@ -1144,14 +1149,19 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
         camerasVo.setTransmode(1);
         camerasVo.setExpand("streamform=rtp");
         String body = JSONObject.toJSONString(camerasVo);
-        String previewURLs = getPreviewURLs("/api/video/v1/cameras/previewURLs", body);
+        String previewURLs = null;
+        try {
+            previewURLs = getPreviewURLs("/api/video/v1/cameras/previewURLs", body);
+        } catch (Exception e) {
+            log.info("-------异常--------"+e.getMessage());
+        }
         log.info("-------------------------------->>>>>previewURLs" + previewURLs);
         long end = System.currentTimeMillis();
         JSONObject outJson = JSONObject.parse(previewURLs);
         stringBuilder.append("测试结果:" + ("0".equals(outJson.getString("code")) ? "成功" : "失败"));
-        stringBuilder.append("\\/n调用时间:"+sdf.format(new Date(begin)));
-        stringBuilder.append("\\/n数据返回时间:"+sdf.format(new Date(end)));
-        stringBuilder.append("\\/n延迟:"+(end - begin) + "毫秒");
+        stringBuilder.append("调用时间:"+sdf.format(new Date(begin)));
+        stringBuilder.append("数据返回时间:"+sdf.format(new Date(end)));
+        stringBuilder.append("延迟:"+(end - begin) + "毫秒");
         return stringBuilder.toString();
     }
 
@@ -1200,7 +1210,12 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
         camerasVo.setTransmode(1);
         camerasVo.setExpand("streamform=rtp");
         String body = JSONObject.toJSONString(camerasVo);
-        String previewURLs = getPreviewURLs("/api/video/v1/cameras/previewURLs", body);
+        String previewURLs = null;
+        try {
+            previewURLs = getPreviewURLs("/api/video/v1/cameras/previewURLs", body);
+        } catch (Exception e) {
+            return "天网无视频-" + camerasVo.getCameraIndexCode();
+        }
         log.info("-------------------------------->>>>>previewURLs" + previewURLs);
         JSONObject outJson = JSONObject.parse(previewURLs);
         if ("0".equals(outJson.getString("code"))) {
@@ -1220,7 +1235,6 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
                     return "暂无视频-" + camerasVo.getCameraIndexCode();
                 }
             } catch (Exception e) {
-                e.printStackTrace();
                 return "暂无视频-" + camerasVo.getCameraIndexCode();
             }
         } else {
@@ -1270,7 +1284,12 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
             //调用天网接口
             log.info("body----->" + body);
             //获取回放视频的url
-            String playbackURLs = getPreviewURLs("/api/video/v1/cameras/playbackURLs", body);
+            String playbackURLs = null;
+            try {
+                playbackURLs = getPreviewURLs("/api/video/v1/cameras/playbackURLs", body);
+            } catch (Exception e) {
+                return "天网无视频-" + code;
+            }
             log.info("playbackURLs----->" + playbackURLs);
             JSONObject outJson = (JSONObject) JSONObject.parse(playbackURLs);
             if ("0".equals(outJson.getString("code"))) {