|
|
@@ -5,7 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.zksy.common.core.domain.Result;
|
|
|
import com.zksy.visualization.config.IccConfigProperty;
|
|
|
-import com.zksy.visualization.domain.request.RtspUrlRequest;
|
|
|
+import com.zksy.visualization.domain.request.*;
|
|
|
import com.zksy.visualization.domain.response.RtspUrlResponse;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
@@ -18,6 +18,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
|
|
|
/**
|
|
|
* @author Administrator
|
|
|
@@ -117,4 +120,172 @@ public class RealTimePreviewVideoController {
|
|
|
}
|
|
|
return response;
|
|
|
}*/
|
|
|
+/* @ApiOperation(value = "rtsp以文件形式回放录像")
|
|
|
+ @PostMapping("/getRTSPFileReplay")
|
|
|
+ public Result getRTSPFileReplay(VideoRecordQueryRequest request){
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String jsonParams = null;
|
|
|
+ try {
|
|
|
+ jsonParams = objectMapper.writeValueAsString(request);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error("JSON序列化失败: {}", e);
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }
|
|
|
+ String authorization = redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .get("Authorization:" + iccConfigProperty.getUsername());
|
|
|
+ // 创建请求体
|
|
|
+ RequestBody body = RequestBody.create(jsonParams, JSON);
|
|
|
+ // 构建请求
|
|
|
+ Request requestHttp = new Request.Builder()
|
|
|
+ .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/admin/API/SS/Playback/StartPlaybackByFile")
|
|
|
+ .addHeader("Authorization", authorization)
|
|
|
+ .post(body)
|
|
|
+ .build();
|
|
|
+ // 发送请求
|
|
|
+ try (Response response = httpClient.newCall(requestHttp).execute()) {
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if("true".equals(success.asText())) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode != null) {
|
|
|
+ return Result.ok(dataNode);
|
|
|
+ } else {
|
|
|
+ return Result.ok(null);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return Result.error("rtsp以文件形式回放录像失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("请求失败: {}", e);
|
|
|
+ }
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }*/
|
|
|
+ @ApiOperation(value = "rtsp以时间形式回放录像")
|
|
|
+ @PostMapping("/getRTSPDateReplay")
|
|
|
+ public Result getRTSPDateReplay(VideoRecordDateQueryRequest request){
|
|
|
+ String startTime = DateToTimeStamp(request.getData().getStartTime());
|
|
|
+ String endTime = DateToTimeStamp(request.getData().getEndTime());
|
|
|
+ request.getData().setStartTime(startTime);
|
|
|
+ request.getData().setEndTime(endTime);
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String jsonParams = null;
|
|
|
+ try {
|
|
|
+ jsonParams = objectMapper.writeValueAsString(request);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error("JSON序列化失败: {}", e);
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }
|
|
|
+ String authorization = redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .get("Authorization:" + iccConfigProperty.getUsername());
|
|
|
+ // 创建请求体
|
|
|
+ RequestBody body = RequestBody.create(jsonParams, JSON);
|
|
|
+ // 构建请求
|
|
|
+ Request requestHttp = new Request.Builder()
|
|
|
+ .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/admin/API/SS/Playback/StartPlaybackByTime")
|
|
|
+ .addHeader("Authorization", authorization)
|
|
|
+ .post(body)
|
|
|
+ .build();
|
|
|
+ // 发送请求
|
|
|
+ try (Response response = httpClient.newCall(requestHttp).execute()) {
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if("true".equals(success.asText())) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode != null) {
|
|
|
+ return Result.ok(dataNode);
|
|
|
+ } else {
|
|
|
+ return Result.ok(null);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ return Result.error("rtsp以时间形式回放录像失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("请求失败: {}", e);
|
|
|
+ }
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }
|
|
|
+ @ApiOperation(value = "HLS、RTMP录像回放(FLV不支持)")
|
|
|
+ @PostMapping("/getHRReplay")
|
|
|
+ public Result getHRReplay(VideoRecordHRQueryRequest request){
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String jsonParams = null;
|
|
|
+ try {
|
|
|
+ jsonParams = objectMapper.writeValueAsString(request);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ log.error("JSON序列化失败: {}", e);
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }
|
|
|
+ String authorization = redisTemplate
|
|
|
+ .opsForValue()
|
|
|
+ .get("Authorization:" + iccConfigProperty.getUsername());
|
|
|
+ // 创建请求体
|
|
|
+ RequestBody body = RequestBody.create(jsonParams, JSON);
|
|
|
+ // 构建请求
|
|
|
+ Request requestHttp = new Request.Builder()
|
|
|
+ .url("https://" + iccConfigProperty.getHost() + "/evo-apigw/admin/API/video/stream/record")
|
|
|
+ .addHeader("Authorization", authorization)
|
|
|
+ .post(body)
|
|
|
+ .build();
|
|
|
+ // 发送请求
|
|
|
+ try (Response response = httpClient.newCall(requestHttp).execute()) {
|
|
|
+ if (!response.isSuccessful()) {
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }
|
|
|
+ ResponseBody responseBody = response.body();
|
|
|
+ if (responseBody != null) {
|
|
|
+ String responseString = responseBody.string();
|
|
|
+ JsonNode rootNode = objectMapper.readTree(responseString);
|
|
|
+ JsonNode success = rootNode.path("success");
|
|
|
+ if("true".equals(success.asText())) {
|
|
|
+ JsonNode dataNode = rootNode.path("data");
|
|
|
+ if (dataNode != null) {
|
|
|
+ return Result.ok(dataNode);
|
|
|
+ } else {
|
|
|
+ return Result.ok(null);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ JsonNode code = rootNode.path("code");
|
|
|
+ if("2239".equals(code.asText())){
|
|
|
+ return Result.error("未查询到录像");
|
|
|
+ }else {
|
|
|
+ return Result.error("HLS、RTMP录像回放(FLV不支持)失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("请求失败: {}", e);
|
|
|
+ }
|
|
|
+ return Result.error("请求失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ public String DateToTimeStamp(String dateTimeString){
|
|
|
+ // 定义日期格式
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try {
|
|
|
+ // 解析字符串为Date对象
|
|
|
+ Date date = dateFormat.parse(dateTimeString);
|
|
|
+ // 将Date对象转换为时间戳(秒)
|
|
|
+ long timestamp = date.getTime() / 1000;
|
|
|
+ return String.valueOf(timestamp);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return dateTimeString;
|
|
|
+ }
|
|
|
}
|