From db3240d918212b9f6f87fdb7704040f0107b456f Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 05 六月 2023 11:10:15 +0800
Subject: [PATCH] 优化截图获取接口

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
index e95622c..200a7d9 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
@@ -26,6 +26,7 @@
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.utils.DateUtil;
 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
+import com.genersoft.iot.vmp.vmanager.bean.SnapPath;
 import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
 import io.swagger.v3.oas.annotations.Operation;
@@ -40,6 +41,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.sip.InvalidArgumentException;
 import javax.sip.SipException;
+import java.io.File;
 import java.text.ParseException;
 import java.util.List;
 import java.util.UUID;
@@ -342,7 +344,7 @@
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
 	@Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true)
 	@GetMapping("/snap")
-	public DeferredResult<String> getSnap(String deviceId, String channelId) {
+	public DeferredResult<String> getSnap(HttpServletRequest request, String deviceId, String channelId) {
 		if (logger.isDebugEnabled()) {
 			logger.debug("鑾峰彇鎴浘: {}/{}", deviceId, channelId);
 		}
@@ -355,11 +357,16 @@
 		RequestMessage message = new RequestMessage();
 		message.setKey(key);
 		message.setId(uuid);
+		String nowForUrl = DateUtil.getNowForUrl();
+		String fileName = deviceId + "_" + channelId + "_" + nowForUrl + ".jpg";
 
-		String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + ".jpg";
 		playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> {
 			if (code == InviteErrorCode.SUCCESS.getCode()) {
-				message.setData(data);
+				File snapFile = new File((String)data);
+				String fileNameForUrl = deviceId + "/" + channelId + "?mark=" + nowForUrl;
+				String uri = request.getRequestURL().toString().replace(request.getRequestURI(), "/api/device/query/snap/" + fileNameForUrl);
+				SnapPath snapPath = SnapPath.getInstance((String) data, snapFile.getAbsolutePath(), uri);
+				message.setData(snapPath);
 			}else {
 				message.setData(WVPResult.fail(code, msg));
 			}

--
Gitblit v1.8.0