Commit db3240d918212b9f6f87fdb7704040f0107b456f

Authored by 648540858
1 parent 2ef41112

优化截图获取接口

src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
... ... @@ -1133,9 +1133,10 @@ public class PlayServiceImpl implements IPlayService {
1133 1133 // 请求截图
1134 1134 logger.info("[请求截图]: " + fileName);
1135 1135 zlmresTfulUtils.getSnap(mediaServerItemInuse, streamUrl, 15, 1, path, fileName);
  1136 + String filePath = path + File.separator + fileName;
1136 1137 File snapFile = new File(path + File.separator + fileName);
1137 1138 if (snapFile.exists()) {
1138   - errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), snapFile.getAbsoluteFile());
  1139 + errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), filePath);
1139 1140 }else {
1140 1141 errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null);
1141 1142 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/bean/ErrorCode.java
... ... @@ -6,7 +6,7 @@ package com.genersoft.iot.vmp.vmanager.bean;
6 6 public enum ErrorCode {
7 7 SUCCESS(0, "成功"),
8 8 ERROR100(100, "失败"),
9   - ERROR400(400, "参数不全或者错误"),
  9 + ERROR400(400, "参数或方法错误"),
10 10 ERROR404(404, "资源未找到"),
11 11 ERROR403(403, "无权限操作"),
12 12 ERROR401(401, "请登录后重新请求"),
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/bean/SnapPath.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.bean;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +
  5 +@Schema(description = "截图地址信息")
  6 +public class SnapPath {
  7 +
  8 + @Schema(description = "相对地址")
  9 + private String path;
  10 +
  11 + @Schema(description = "绝对地址")
  12 + private String absoluteFilePath;
  13 +
  14 + @Schema(description = "请求地址")
  15 + private String url;
  16 +
  17 +
  18 + public static SnapPath getInstance(String path, String absoluteFilePath, String url) {
  19 + SnapPath snapPath = new SnapPath();
  20 + snapPath.setPath(path);
  21 + snapPath.setAbsoluteFilePath(absoluteFilePath);
  22 + snapPath.setUrl(url);
  23 + return snapPath;
  24 + }
  25 +
  26 +
  27 + public String getPath() {
  28 + return path;
  29 + }
  30 +
  31 + public void setPath(String path) {
  32 + this.path = path;
  33 + }
  34 +
  35 + public String getAbsoluteFilePath() {
  36 + return absoluteFilePath;
  37 + }
  38 +
  39 + public void setAbsoluteFilePath(String absoluteFilePath) {
  40 + this.absoluteFilePath = absoluteFilePath;
  41 + }
  42 +
  43 + public String getUrl() {
  44 + return url;
  45 + }
  46 +
  47 + public void setUrl(String url) {
  48 + this.url = url;
  49 + }
  50 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
... ... @@ -466,10 +466,12 @@ public class DeviceQuery {
466 466 @Operation(summary = "请求截图")
467 467 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
468 468 @Parameter(name = "channelId", description = "通道国标编号", required = true)
469   - public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId) {
  469 + @Parameter(name = "mark", description = "标识", required = false)
  470 + public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId, @RequestParam(required = false) String mark) {
470 471  
471 472 try {
472   - final InputStream in = Files.newInputStream(new File("snap" + File.separator + deviceId + "_" + channelId + ".jpg").toPath());
  473 +
  474 + final InputStream in = Files.newInputStream(new File("snap" + File.separator + deviceId + "_" + channelId + (mark == null? ".jpg": ("_" + mark + ".jpg"))).toPath());
473 475 resp.setContentType(MediaType.IMAGE_PNG_VALUE);
474 476 IOUtils.copy(in, resp.getOutputStream());
475 477 } catch (IOException e) {
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
... ... @@ -26,6 +26,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
26 26 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
27 27 import com.genersoft.iot.vmp.utils.DateUtil;
28 28 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
  29 +import com.genersoft.iot.vmp.vmanager.bean.SnapPath;
29 30 import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
30 31 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
31 32 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -40,6 +41,7 @@ import org.springframework.web.context.request.async.DeferredResult;
40 41 import javax.servlet.http.HttpServletRequest;
41 42 import javax.sip.InvalidArgumentException;
42 43 import javax.sip.SipException;
  44 +import java.io.File;
43 45 import java.text.ParseException;
44 46 import java.util.List;
45 47 import java.util.UUID;
... ... @@ -342,7 +344,7 @@ public class PlayController {
342 344 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
343 345 @Parameter(name = "channelId", description = "通道国标编号", required = true)
344 346 @GetMapping("/snap")
345   - public DeferredResult<String> getSnap(String deviceId, String channelId) {
  347 + public DeferredResult<String> getSnap(HttpServletRequest request, String deviceId, String channelId) {
346 348 if (logger.isDebugEnabled()) {
347 349 logger.debug("获取截图: {}/{}", deviceId, channelId);
348 350 }
... ... @@ -355,11 +357,16 @@ public class PlayController {
355 357 RequestMessage message = new RequestMessage();
356 358 message.setKey(key);
357 359 message.setId(uuid);
  360 + String nowForUrl = DateUtil.getNowForUrl();
  361 + String fileName = deviceId + "_" + channelId + "_" + nowForUrl + ".jpg";
358 362  
359   - String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + ".jpg";
360 363 playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> {
361 364 if (code == InviteErrorCode.SUCCESS.getCode()) {
362   - message.setData(data);
  365 + File snapFile = new File((String)data);
  366 + String fileNameForUrl = deviceId + "/" + channelId + "?mark=" + nowForUrl;
  367 + String uri = request.getRequestURL().toString().replace(request.getRequestURI(), "/api/device/query/snap/" + fileNameForUrl);
  368 + SnapPath snapPath = SnapPath.getInstance((String) data, snapFile.getAbsolutePath(), uri);
  369 + message.setData(snapPath);
363 370 }else {
364 371 message.setData(WVPResult.fail(code, msg));
365 372 }
... ...