|
@@ -3,6 +3,7 @@ package com.ozs.utils;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
|
|
import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
|
@@ -15,12 +16,15 @@ import com.ozs.common.exception.base.BaseException;
|
|
|
import com.ozs.common.utils.DateUtils;
|
|
|
import com.ozs.common.utils.HttpClientUtil;
|
|
|
import com.ozs.common.utils.http.HttpUtils;
|
|
|
+import com.ozs.entity.BaseCameraManagement;
|
|
|
import com.ozs.entity.BaseTerminal;
|
|
|
import com.ozs.entity.BaseTerminalLog;
|
|
|
import com.ozs.entity.MsgHeartbeatAlarmMessage;
|
|
|
+import com.ozs.entity.response.BaseCameraManagementResponse;
|
|
|
import com.ozs.entity.vo.CamerasVo;
|
|
|
import com.ozs.entity.vo.PlaybackVo;
|
|
|
import com.ozs.framework.config.ServerConfig;
|
|
|
+import com.ozs.service.BaseCameraManagementService;
|
|
|
import com.ozs.service.BaseTerminalLogService;
|
|
|
import com.ozs.service.BaseTerminalService;
|
|
|
import com.ozs.service.MsgHeartbeatAlarmMessageService;
|
|
@@ -45,8 +49,11 @@ import java.io.OutputStreamWriter;
|
|
|
import java.io.PrintWriter;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.OffsetDateTime;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
@@ -115,6 +122,8 @@ public class CameraUtil {
|
|
|
private ISysDictTypeService dictTypeService;
|
|
|
@Autowired
|
|
|
private RtspToMP4 rtspToMP4;
|
|
|
+ @Resource
|
|
|
+ BaseCameraManagementService baseCameraManagementService;
|
|
|
|
|
|
@Resource
|
|
|
private BaseTerminalLogService baseTerminalLogService;
|
|
@@ -1108,25 +1117,95 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
System.out.println(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, sdate));
|
|
|
}
|
|
|
|
|
|
- public String heartbeatGetPlayFlv() {
|
|
|
- List<String> pathList = new ArrayList<>();
|
|
|
- String data = HttpUtils.sendGet(webUrl + "/api/summary");
|
|
|
- log.info("data------------------>" + data);
|
|
|
- if (StringUtils.isNotEmpty(data)) {
|
|
|
-
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
- JSONArray streamArray = jsonObject.getJSONArray("Streams");
|
|
|
- // 创建一个新的列表来存储Subscribers字段的值
|
|
|
- List<String> subList = new ArrayList<>();
|
|
|
- for (int i = 0; i < streamArray.size(); i++) {
|
|
|
- JSONObject subObj = streamArray.getJSONObject(i);
|
|
|
- String subValue = subObj.getString("Subscribers");
|
|
|
- String PathValue = subObj.getString("Path");
|
|
|
-
|
|
|
- subList.add(subValue);
|
|
|
+
|
|
|
+ public List<BaseCameraManagementResponse> heartbeatGetPlayFlv() {
|
|
|
+ int maxRetries = 5;
|
|
|
+ int retryCount = 0;
|
|
|
+ boolean success = false;
|
|
|
+ JSONArray streamArray = null;
|
|
|
+ List<BaseCameraManagementResponse> baseCameraManagementResponseList = new ArrayList<>();
|
|
|
+ while (!success && retryCount < maxRetries) {
|
|
|
+ try {
|
|
|
+ String data = HttpUtils.sendGet(webUrl + "/api/summary");
|
|
|
+ log.info("data------------------>" + data);
|
|
|
+ if (StringUtils.isNotEmpty(data)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
+ streamArray = jsonObject.getJSONArray("Streams");
|
|
|
+ success = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("Exception caught: " + e.getMessage());
|
|
|
+ // 增加重试计数
|
|
|
+ retryCount++;
|
|
|
}
|
|
|
}
|
|
|
+ for (int i = 0; i < streamArray.size(); i++) {
|
|
|
+ BaseCameraManagementResponse baseCameraManagementResponse = new BaseCameraManagementResponse();
|
|
|
+ JSONObject subObj = streamArray.getJSONObject(i);
|
|
|
+ String subValue = subObj.getString("Subscribers");
|
|
|
+ String PathValue = subObj.getString("Path");
|
|
|
+ String type = subObj.getString("Type");
|
|
|
+ String timestampString = subObj.getString("StartTime");
|
|
|
+ ZonedDateTime givenTime = ZonedDateTime.parse(timestampString);
|
|
|
+ // 当前时间
|
|
|
+ Instant currentTime = Instant.now();
|
|
|
+ // 将给定时间转换为Instant对象
|
|
|
+ Instant givenInstant = givenTime.toInstant();
|
|
|
+ // 计算时间差
|
|
|
+ Duration duration = Duration.between(givenInstant, currentTime);
|
|
|
+ //封装
|
|
|
+ // 获取小时差
|
|
|
+ baseCameraManagementResponse.setStartTime(duration.toHours() + "小时前");
|
|
|
+ baseCameraManagementResponse.setStreamPath(PathValue);
|
|
|
+ baseCameraManagementResponse.setSubscribers(subValue);
|
|
|
+ baseCameraManagementResponse.setType(type);
|
|
|
+ // 寻找第一个斜杠的位置
|
|
|
+ int slashIndex = PathValue.indexOf("/");
|
|
|
+ if (slashIndex != -1) {
|
|
|
+ BaseCameraManagementResponse response = new BaseCameraManagementResponse();
|
|
|
+ String result = PathValue.substring(0, slashIndex);
|
|
|
+ BaseCameraManagement cameraManagement = baseCameraManagementService.getOne(new LambdaQueryWrapper<BaseCameraManagement>()
|
|
|
+ .eq(BaseCameraManagement::getCameraCode, result));
|
|
|
+ if (!ObjectUtils.isEmpty(cameraManagement)) {
|
|
|
+ baseCameraManagementResponse.setCameraCode(cameraManagement.getCameraCode());
|
|
|
+ baseCameraManagementResponse.setInstallMile(cameraManagement.getInstallMile());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //取出AudioTracks
|
|
|
+ JSONArray audioJson = subObj.getJSONArray("AudioTracks");
|
|
|
+ for (int v = 0; v < audioJson.size(); v++) {
|
|
|
+ BaseCameraManagementResponse.AudioTracks audioTracks = new BaseCameraManagementResponse.AudioTracks();
|
|
|
+ JSONObject arrayJSONObject = audioJson.getJSONObject(v);
|
|
|
+ String name = arrayJSONObject.getString("Name");
|
|
|
+ String sampleRate = arrayJSONObject.getString("SampleRate");
|
|
|
+ String channels = arrayJSONObject.getString("Channels");
|
|
|
+ String bps = arrayJSONObject.getString("BPS");
|
|
|
+ audioTracks.setBps(bps);
|
|
|
+ audioTracks.setChannels(channels);
|
|
|
+ audioTracks.setName(name);
|
|
|
+ audioTracks.setSampleRate(sampleRate);
|
|
|
+ baseCameraManagementResponse.setAudioTracks(audioTracks);
|
|
|
+ }
|
|
|
+ //取出VideoTracks
|
|
|
+ JSONArray videoJson = subObj.getJSONArray("VideoTracks");
|
|
|
+ for (int v = 0; v < videoJson.size(); v++) {
|
|
|
+ BaseCameraManagementResponse.VideoTracks videoTracks = new BaseCameraManagementResponse.VideoTracks();
|
|
|
+ JSONObject arrayJSONObject = videoJson.getJSONObject(v);
|
|
|
+ String name = arrayJSONObject.getString("Name");
|
|
|
+ String width = arrayJSONObject.getString("Width");
|
|
|
+ String height = arrayJSONObject.getString("Height");
|
|
|
+ String resolution = width + "*" + height;
|
|
|
+ String gop = arrayJSONObject.getString("GOP");
|
|
|
+ String bps = arrayJSONObject.getString("BPS");
|
|
|
+ videoTracks.setBps(bps);
|
|
|
+ videoTracks.setGop(gop);
|
|
|
+ videoTracks.setName(name);
|
|
|
+ videoTracks.setResolution(resolution);
|
|
|
+ baseCameraManagementResponse.setVideoTracks(videoTracks);
|
|
|
+ }
|
|
|
+ baseCameraManagementResponseList.add(baseCameraManagementResponse);
|
|
|
+ }
|
|
|
|
|
|
- return null;
|
|
|
+ return baseCameraManagementResponseList;
|
|
|
}
|
|
|
}
|