Browse Source

报警回放调试

gao.qiang 1 year ago
parent
commit
2b7648df4b

+ 39 - 36
vehicle-admin/src/main/java/com/ozs/web/controller/accountmanagment/BaseCameraManagementController.java

@@ -486,42 +486,45 @@ public class BaseCameraManagementController extends BaseController {
     @ApiOperation("根据相机ID获取相机台账管理信息")
     @Log(title = "相机台账管理", businessType = BusinessType.MESSAGE)
     public AjaxResult getInfo(@PathVariable Long id) {
-        BaseCameraManagement baseCameraManagement = baseCameraManagementService.getById(id);
-        LambdaQueryWrapper<BaseRailwayManagement> queryWrapper = new LambdaQueryWrapper<BaseRailwayManagement>();
-        if (!ObjectUtils.isEmpty(baseCameraManagement.getRailwayCode())) {
-            queryWrapper.eq(BaseRailwayManagement::getRailwayCode, baseCameraManagement.getRailwayCode());
-        }
-        BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(queryWrapper);
-//        SysDept sysDept = deptService.selectDeptById(baseCameraManagement.getDeptId());
-//        baseCameraManagement.setDeptName(sysDept.getDeptName());
-        baseCameraManagement.setRailwayName(baseRailwayManagement.getRailwayName());
-        if (!StringUtils.isEmptySunhh(baseCameraManagement.getInstallMile())) {
-            String mils = AppendUtils.stringAppend(baseCameraManagement.getInstallMile());
-            baseCameraManagement.setInstallMiles(mils);
-        }
-        String end = "";
-        if (!StringUtils.isEmptySunhh(baseCameraManagement.getEndMile())) {
-            end = AppendUtils.stringAppend(baseCameraManagement.getEndMile());
-            baseCameraManagement.setEndMiles(end);
-        }
-        String begin = "";
-        if (!StringUtils.isEmptySunhh(baseCameraManagement.getBeginMile())) {
-            begin = AppendUtils.stringAppend(baseCameraManagement.getBeginMile());
-            baseCameraManagement.setBeginMiles(begin);
-        }
-        if (!StringUtils.isEmptySunhh(baseCameraManagement.getInstallMile())) {
-            baseCameraManagement.setInstallMileBD(new BigDecimal(baseCameraManagement.getInstallMile()).divide(new BigDecimal(1000)).setScale(3, RoundingMode.HALF_UP));
-        }
-        if (!StringUtils.isEmptySunhh(baseCameraManagement.getBeginMile())) {
-            baseCameraManagement.setBeginMileBD(new BigDecimal(baseCameraManagement.getBeginMile()).divide(new BigDecimal(1000)).setScale(3, RoundingMode.HALF_UP));
-        }
-        if (!StringUtils.isEmptySunhh(baseCameraManagement.getEndMile())) {
-            baseCameraManagement.setEndMileBD(new BigDecimal(baseCameraManagement.getEndMile()).divide(new BigDecimal(1000)).setScale(3, RoundingMode.HALF_UP));
-        }
-        baseCameraManagement.setLineDirStr(baseCameraManagement.getLineDir() == 1 ? "上行" : "下行");
-        baseCameraManagement.setMilesRange(begin + "-" + end);
-        baseCameraManagement.setLongitudeAndLatitude(baseCameraManagement.getInstallLongitude() + "," + baseCameraManagement.getInstallLongitude());
-        return AjaxResult.success(baseCameraManagement);
+//        BaseCameraManagement baseCameraManagement = baseCameraManagementService.getById(id);
+//        LambdaQueryWrapper<BaseRailwayManagement> queryWrapper = new LambdaQueryWrapper<BaseRailwayManagement>();
+//        if (!ObjectUtils.isEmpty(baseCameraManagement.getRailwayCode())) {
+//            queryWrapper.eq(BaseRailwayManagement::getRailwayCode, baseCameraManagement.getRailwayCode());
+//        }
+//        BaseRailwayManagement baseRailwayManagement = baseRailwayManagementService.getOne(queryWrapper);
+////        SysDept sysDept = deptService.selectDeptById(baseCameraManagement.getDeptId());
+////        baseCameraManagement.setDeptName(sysDept.getDeptName());
+//        baseCameraManagement.setRailwayName(baseRailwayManagement.getRailwayName());
+//        if (!StringUtils.isEmptySunhh(baseCameraManagement.getInstallMile())) {
+//            String mils = AppendUtils.stringAppend(baseCameraManagement.getInstallMile());
+//            baseCameraManagement.setInstallMiles(mils);
+//        }
+//        String end = "";
+//        if (!StringUtils.isEmptySunhh(baseCameraManagement.getEndMile())) {
+//            end = AppendUtils.stringAppend(baseCameraManagement.getEndMile());
+//            baseCameraManagement.setEndMiles(end);
+//        }
+//        String begin = "";
+//        if (!StringUtils.isEmptySunhh(baseCameraManagement.getBeginMile())) {
+//            begin = AppendUtils.stringAppend(baseCameraManagement.getBeginMile());
+//            baseCameraManagement.setBeginMiles(begin);
+//        }
+//        if (!StringUtils.isEmptySunhh(baseCameraManagement.getInstallMile())) {
+//            baseCameraManagement.setInstallMileBD(new BigDecimal(baseCameraManagement.getInstallMile()).divide(new BigDecimal(1000)).setScale(3, RoundingMode.HALF_UP));
+//        }
+//        if (!StringUtils.isEmptySunhh(baseCameraManagement.getBeginMile())) {
+//            baseCameraManagement.setBeginMileBD(new BigDecimal(baseCameraManagement.getBeginMile()).divide(new BigDecimal(1000)).setScale(3, RoundingMode.HALF_UP));
+//        }
+//        if (!StringUtils.isEmptySunhh(baseCameraManagement.getEndMile())) {
+//            baseCameraManagement.setEndMileBD(new BigDecimal(baseCameraManagement.getEndMile()).divide(new BigDecimal(1000)).setScale(3, RoundingMode.HALF_UP));
+//        }
+//        baseCameraManagement.setLineDirStr(baseCameraManagement.getLineDir() == 1 ? "上行" : "下行");
+//        baseCameraManagement.setMilesRange(begin + "-" + end);
+//        baseCameraManagement.setLongitudeAndLatitude(baseCameraManagement.getInstallLongitude() + "," + baseCameraManagement.getInstallLongitude());
+//        return AjaxResult.success(baseCameraManagement);
+        String cameraPreviewURL = GetCameraPreviewURL.getCameraPreviewURL();
+        log.info("------------------------------------------getInfo"+cameraPreviewURL);
+        return AjaxResult.success(cameraPreviewURL);
     }
 
     /**

+ 32 - 30
vehicle-admin/src/main/java/com/ozs/web/controller/sdk/GeoHazardMonitorTokenController.java

@@ -33,6 +33,7 @@ import com.ozs.entity.vo.CameraVo;
 import com.ozs.entity.vo.Files;
 import com.ozs.entity.vo.HeartbeatVo;
 import com.ozs.entity.vo.ParameterVo;
+import com.ozs.entity.vo.PlaybackVo;
 import com.ozs.entity.vo.QueryAlarmVo;
 import com.ozs.entity.vo.ReleaseAlarmVo;
 import com.ozs.entity.vo.ReqMsgAlarmVo;
@@ -85,6 +86,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
 /**
@@ -235,13 +237,11 @@ public class GeoHazardMonitorTokenController {
             String key = split[split.length - 1];
             String s = SM4Utils.decryptData_ECB(parameterVo.getParameter(), key);
             ReqMsgAlarmVo reqMsgAlarmVo = JSON.parseObject(s, ReqMsgAlarmVo.class);
-            if (!ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmAttr())) {
-                if (!reqMsgAlarmVo.getAlarmAttr().matches(PATTERN)) {
+            if (ObjectUtils.isEmpty(reqMsgAlarmVo.getAlarmAttr())) {
                     jsonObject.put("resultCode", 0);
                     jsonObject.put("message", "失败");
                     jsonObject.put("data", "你填写的报警病害属性不符合规则!!!");
                     return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
-                }
             }
             if (!reqMsgAlarmVo.getAlarmMile().toString().matches(PATTERNS)) {
                 jsonObject.put("resultCode", 0);
@@ -301,6 +301,7 @@ public class GeoHazardMonitorTokenController {
                 wrapper.ge(BaseCameraManagement::getEndMile, reqMsgAlarmVo.getAlarmMile());
                 wrapper.eq(BaseCameraManagement::getRailwayCode, reqMsgAlarmVo.getAlarmRailway());
                 wrapper.eq(BaseCameraManagement::getLineDir, reqMsgAlarmVo.getLineDir());
+                wrapper.eq(BaseCameraManagement::getEnableOrNot, 1);
             }
             List<BaseCameraManagement> baseCameraManagementList = baseCameraManagementService.list(wrapper);
             log.info("baseCameraManagement:{}", baseCameraManagementList);
@@ -359,33 +360,34 @@ public class GeoHazardMonitorTokenController {
                 msgAlarmVice.setAlarmTime(new Date(reqMsgAlarmVo.getAlarmTime()));
                 msgAlarmFrequencyService.save(msgAlarmVice);
                 webSocketCommon.publish(msgAlarm);
-                for (BaseCameraManagement baseCameraManagement : baseCameraManagementList) {
-                    String invite = CameraUtil.invite(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel());
-                    if ("304".equals(invite) || "200".equals(invite)) {
-                        String start = HttpUtils.sendGet(CameraUtil.startRecording(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel()));
-                        log.info("startRecording------------" + start);
-                        if (start.startsWith(baseCameraManagement.getCameraCode() + "/" + baseCameraManagement.getChannel())) {
-                            baseCameraManagement.setTaskId(start);
-                            baseCameraManagement.setUpdateBy(admin.getUserId());
-                        } else {
-                            jsonObject.put("resultCode", 0);
-                            jsonObject.put("message", "失败");
-                            jsonObject.put("data", "视频录制失败:请确认流是否存在!!!");
-                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
-                        }
-                        if (!baseCameraManagementService.updateById(baseCameraManagement)) {
-                            jsonObject.put("resultCode", 0);
-                            jsonObject.put("message", "失败");
-                            jsonObject.put("data", "开启录制视频失败!!!");
-                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
-                        }
-                    } else {
-                        jsonObject.put("resultCode", 0);
-                        jsonObject.put("message", "失败");
-                        jsonObject.put("data", "视频邀约失败,视频中心没有该相机编码或通道编码的摄像头!!!");
-                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
-                    }
-                }
+                List<String> collect = baseCameraManagementList.stream().map(BaseCameraManagement::getCameraCode).collect(Collectors.toList());
+//                CompletableFuture.runAsync(() ->cameraUtil.playbackURLs(collect));
+//                    String invite = CameraUtil.invite(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel());
+//                    if ("304".equals(invite) || "200".equals(invite)) {
+//                        String start = HttpUtils.sendGet(CameraUtil.startRecording(baseCameraManagement.getCameraCode(), baseCameraManagement.getChannel()));
+//                        log.info("startRecording------------" + start);
+//                        if (start.startsWith(baseCameraManagement.getCameraCode() + "/" + baseCameraManagement.getChannel())) {
+//                            baseCameraManagement.setTaskId(start);
+//                            baseCameraManagement.setUpdateBy(admin.getUserId());
+//                        } else {
+//                            jsonObject.put("resultCode", 0);
+//                            jsonObject.put("message", "失败");
+//                            jsonObject.put("data", "视频录制失败:请确认流是否存在!!!");
+//                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
+//                        }
+//                        if (!baseCameraManagementService.updateById(baseCameraManagement)) {
+//                            jsonObject.put("resultCode", 0);
+//                            jsonObject.put("message", "失败");
+//                            jsonObject.put("data", "开启录制视频失败!!!");
+//                            return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
+//                        }
+//                    } else {
+//                        jsonObject.put("resultCode", 0);
+//                        jsonObject.put("message", "失败");
+//                        jsonObject.put("data", "视频邀约失败,视频中心没有该相机编码或通道编码的摄像头!!!");
+//                        return SM4Utils.encryptData_ECB(JSONObject.toJSONString(jsonObject), key);
+//                    }
+                
 
             } else {
                 BeanUtils.copyProperties(reqMsgAlarmVo, msgAlarmVice);

+ 1 - 1
vehicle-admin/src/main/java/com/ozs/web/core/config/GetCameraPreviewURL.java

@@ -30,7 +30,7 @@ public class GetCameraPreviewURL {
         /**
          * STEP3:设置接口的URI地址
          */
-        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v2/encodeDevice/search";
+        final String previewURLsApi = ARTEMIS_PATH + "/api/resource/v1/camera/search";
         Map<String, String> path = new HashMap<String, String>(2) {
             {
                 put("https://", previewURLsApi);//根据现场环境部署确认是http还是https

+ 60 - 27
vehicle-admin/src/main/java/com/ozs/web/core/util/CameraUtil.java

@@ -34,8 +34,11 @@ import javax.annotation.Resource;
 import java.io.*;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.Callable;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
@@ -491,7 +494,7 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
         sc = serverConfig;
         wsUrl = caneraConfig.getWsUrl();
         recordUrl = caneraConfig.getRecordUrl();
-        hkUrl=caneraConfig.getHkUrl();
+        hkUrl = caneraConfig.getHkUrl();
     }
 
     /**
@@ -772,6 +775,15 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
     }
 
 
+    /**
+     * RTSP流下载
+     */
+    public static void streamUrlDownload(String url, String code) {
+        log.info(ffmpegPath + " -i " + url + " -c copy /opt/stream/map" + code);
+        cUtil.cmd(ffmpegPath + " -i " + url + " -c copy /opt/stream/map" + code);
+    }
+
+
     public static List<Map<String, Object>> filterRecordList(String channel,
                                                              Date startTm,
                                                              Date endTm,
@@ -890,42 +902,63 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
         }
 
     }
-    
-    
-    public void previewURLs(CamerasVo camerasVo){
+
+
+    public void previewURLs(CamerasVo camerasVo) {
         String result = null;
-        String url="http://"+hkUrl+"/api/video/v2/cameras/previewURLs";
+        String url = "http://" + hkUrl + "/api/video/v2/cameras/previewURLs";
         try {
             result = HttpClientUtil.postJson(url, JSON.toJSONString(camerasVo));
         } catch (Exception e) {
-            log.error("previewURLs------------>"+e.getMessage());
+            log.error("previewURLs------------>" + e.getMessage());
             e.printStackTrace();
         }
         JSONObject outJson = (JSONObject) JSONObject.parse(result);
-        if ("200".equals(outJson.getString("code"))) {
-            log.info("outJson----->"+outJson);
+        if ("0".equals(outJson.getString("code"))) {
+            log.info("outJson----->" + outJson);
             JSONObject data = outJson.getJSONObject("data");
-            String urls=data.getString("url");
-            HttpUtils.sendGet(historyUrl+"rtsp/api/pull?target="+urls+"&streamPath="+camerasVo.getCameraIndexCode()+"/"+camerasVo.getCameraIndexCode()+"&save=0");
+            String urls = data.getString("url");
+            HttpUtils.sendGet(historyUrl + "rtsp/api/pull?target=" + urls + "&streamPath=" + camerasVo.getCameraIndexCode() + "/" + camerasVo.getCameraIndexCode() + "&save=0");
         }
-        
+
     }
-    
-    public AjaxResult playbackURLs(PlaybackVo playbackVo){
-        String result = null;
-        String url="http://"+hkUrl+"/api/video/v2/cameras/playbackURLs";
-        try {
-            result = HttpClientUtil.postJson(url, JSON.toJSONString(playbackVo));
-        } catch (Exception e) {
-            log.error("playbackURLs------------>"+e.getMessage());
-            e.printStackTrace();
-        }
-        JSONObject outJson = (JSONObject) JSONObject.parse(result);
-        if ("200".equals(outJson.getString("code"))) {
-            log.info("outJson----->"+outJson);
-            return AjaxResult.success(outJson);
-        }
-        return AjaxResult.error("方法调用异常");
+
+    public void playbackURLs(List<String> list) {
+        CompletableFuture future = CompletableFuture.supplyAsync(() -> {
+            for (String code : list) {
+                PlaybackVo playbackVo = new PlaybackVo();
+                playbackVo.setCameraIndexCode(code);
+                // 获取当前时间
+                LocalDateTime currentTime = LocalDateTime.now();
+                // 获取当前时间的前10分钟时间
+                LocalDateTime beforeTenMinutes = currentTime.minusMinutes(10);
+                // 获取当前时间的后10分钟时间
+                LocalDateTime afterTenMinutes = currentTime.plusMinutes(10);
+                // 格式化时间
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                playbackVo.setBeginTime(beforeTenMinutes.format(formatter));
+                playbackVo.setEndTime(afterTenMinutes.format(formatter));
+
+
+                String result = null;
+                String url = "http://" + hkUrl + "/api/video/v2/cameras/playbackURLs";
+                try {
+                    result = HttpClientUtil.postJson(url, JSON.toJSONString(playbackVo));
+                } catch (Exception e) {
+                    log.error("playbackURLs------------>" + e.getMessage());
+                    e.printStackTrace();
+                }
+                JSONObject outJson = (JSONObject) JSONObject.parse(result);
+                if ("0".equals(outJson.getString("code"))) {
+                    log.info("outJson----->" + outJson);
+                    JSONObject data = outJson.getJSONObject("data");
+                    String urls = data.getString("url");
+                    streamUrlDownload(urls, playbackVo.getCameraIndexCode());
+                }
+            }
+            return 1;
+        });
+        future.join();
     }
 
     public static void main(String[] args) throws InterruptedException, ParseException, IOException {