From 16026ec48a4f526d15882de0a7afc2875cd21475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Thu, 8 Aug 2024 09:51:39 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9B=B7=E8=BE=BE=E5=85=B3=E8=81=94=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E7=82=B9=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/controller/VideoController.java | 30 ++++++++++++++++++- .../service/impl/DcWarningServiceImpl.java | 14 ++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index 2df09ac8..d4e6d2f6 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -711,6 +711,7 @@ public class VideoController extends BaseController { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); + JSONObject jsonResult = null; OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(); @@ -733,7 +734,34 @@ public class VideoController extends BaseController { .data(requestParams) // 请求参数 .get(); // 请求方法 - return getJsonResult(response,okHttp); + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + + if (jsonResult.containsKey("code")) { + if (HttpStatus.SUCCESS == jsonResult.getInteger("code")) { + Map data = jsonResult.getJSONObject("data"); + String fileUrl = data.get("fileUrl").toString(); + fileUrl = configService.selectConfigByKey("dc.cameraUrl") + fileUrl.substring(UniversalEnum.SEVEN.getNumber()); + data.put("fileUrl",fileUrl); + jsonResult.put("data",data); + } else if (UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { + getToken(); + okHttp.post(); + if (response.body() != null) { + jsonResult = JSONObject.parseObject(response.body().string()); + if (HttpStatus.SUCCESS == jsonResult.getInteger("code")) { + Map data = jsonResult.getJSONObject("data"); + String fileUrl = data.get("fileUrl").toString(); + fileUrl = configService.selectConfigByKey("cameraUrl") + fileUrl.substring(UniversalEnum.SEVEN.getNumber()); + data.put("liveUrl",fileUrl); + jsonResult.put("data",data); + } + } + } + } + } + + return jsonResult; } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java index 6c747675..8661b2cc 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java @@ -1082,16 +1082,16 @@ public class DcWarningServiceImpl implements IDcWarningService { public String getRadarIncidentVideo(String id) throws Exception { String msg = ""; HashMap stringObjectHashMap = dcWarningMapper.selectDcWarningById(id); - // 给定的时间 + // 时间 String givenTime = (String) stringObjectHashMap.get("warningTime"); // 定义日期时间格式 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - // 解析给定的时间 + // 解析时间 LocalDateTime currentTime = LocalDateTime.parse(givenTime, formatter); - // 计算 30 秒后的时间 - LocalDateTime timeAfter30Seconds = currentTime.plus(Duration.ofSeconds(30)); + // 计算 30 秒前的时间 + LocalDateTime timeAfter30Seconds = currentTime.plus(Duration.ofSeconds(-30)); // 格式化时间 String formattedTime = timeAfter30Seconds.format(formatter); @@ -1109,7 +1109,7 @@ public class DcWarningServiceImpl implements IDcWarningService { JsonNode code = jsonNodelist.get(0).get("cameraIndexCode"); // 使用 textValue() 方法获取纯字符串 String codestring = code.textValue(); - com.alibaba.fastjson.JSONObject jsonObject = videoController.downloadCameraVideo(codestring, formattedTime, 1); + com.alibaba.fastjson.JSONObject jsonObject = videoController.downloadCameraVideo(codestring, formattedTime, 2); if (jsonObject.get("code").toString().equals("500")) { return null; @@ -1136,12 +1136,12 @@ public class DcWarningServiceImpl implements IDcWarningService { JsonNode paramsNode = otherConfigurationNode.get("params"); JsonNode eventsNode = paramsNode.get("events"); - // 假设只有一个事件,我们只处理第一个事件 + // 假设只有一个事件,只处理第一个事件 JsonNode eventDataNode = eventsNode.get(0); JsonNode dataNode2 = eventDataNode.get("data"); JsonNode vehicleRcogResultNode = dataNode2.get("vehicleRcogResult"); - // 假设只有一个 vehicleRcogResult 对象 + // vehicleRcogResult 对象 JsonNode targetAttrsNode = vehicleRcogResultNode.get(0).get("targetAttrs");