From 764d04b497356ba6bcbb75fd42b51eca750f7223 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 29 五月 2024 15:02:51 +0800 Subject: [PATCH] 调整上级观看消息的发送 --- src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java | 126 +++++++++++++++++++++++------------------ 1 files changed, 70 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java old mode 100644 new mode 100755 index 4a29f8e..36047f0 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java @@ -1,28 +1,32 @@ package com.genersoft.iot.vmp.vmanager.gb28181.ptz; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; -import io.swagger.annotations.ApiOperation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.async.DeferredResult; +import com.genersoft.iot.vmp.conf.exception.ControllerException; +import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.ObjectUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.async.DeferredResult; +import javax.sip.InvalidArgumentException; +import javax.sip.SipException; +import java.text.ParseException; import java.util.UUID; -@Api(tags = "浜戝彴鎺у埗") -@CrossOrigin +@Tag(name = "浜戝彴鎺у埗") + @RestController @RequestMapping("/api/ptz") public class PtzController { @@ -46,19 +50,17 @@ * @param horizonSpeed 姘村钩绉诲姩閫熷害 * @param verticalSpeed 鍨傜洿绉诲姩閫熷害 * @param zoomSpeed 缂╂斁閫熷害 - * @return String 鎺у埗缁撴灉 */ - @ApiOperation("浜戝彴鎺у埗") - @ApiImplicitParams({ - @ApiImplicitParam(name = "deviceId", value = "璁惧ID", dataTypeClass = String.class), - @ApiImplicitParam(name = "channelId", value = "閫氶亾ID", dataTypeClass = String.class), - @ApiImplicitParam(name = "command", value = "鎺у埗鎸囦护,鍏佽鍊�: left, right, up, down, upleft, upright, downleft, downright, zoomin, zoomout, stop", dataTypeClass = String.class), - @ApiImplicitParam(name = "horizonSpeed", value = "姘村钩閫熷害", dataTypeClass = Integer.class), - @ApiImplicitParam(name = "verticalSpeed", value = "鍨傜洿閫熷害", dataTypeClass = Integer.class), - @ApiImplicitParam(name = "zoomSpeed", value = "缂╂斁閫熷害", dataTypeClass = Integer.class), - }) + + @Operation(summary = "浜戝彴鎺у埗", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true) + @Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true) + @Parameter(name = "command", description = "鎺у埗鎸囦护,鍏佽鍊�: left, right, up, down, upleft, upright, downleft, downright, zoomin, zoomout, stop", required = true) + @Parameter(name = "horizonSpeed", description = "姘村钩閫熷害", required = true) + @Parameter(name = "verticalSpeed", description = "鍨傜洿閫熷害", required = true) + @Parameter(name = "zoomSpeed", description = "缂╂斁閫熷害", required = true) @PostMapping("/control/{deviceId}/{channelId}") - public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){ + public void ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){ if (logger.isDebugEnabled()) { logger.debug(String.format("璁惧浜戝彴鎺у埗 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s 锛宑ommand锛�%s 锛宧orizonSpeed锛�%d 锛寁erticalSpeed锛�%d 锛寊oomSpeed锛�%d",deviceId, channelId, command, horizonSpeed, verticalSpeed, zoomSpeed)); @@ -97,50 +99,58 @@ cmdCode = 32; break; case "stop": - cmdCode = 0; + horizonSpeed = 0; + verticalSpeed = 0; + zoomSpeed = 0; break; default: break; } - cmder.frontEndCmd(device, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed); - return new ResponseEntity<String>("success",HttpStatus.OK); + try { + cmder.frontEndCmd(device, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed); + } catch (SipException | InvalidArgumentException | ParseException e) { + logger.error("[鍛戒护鍙戦�佸け璐 浜戝彴鎺у埗: {}", e.getMessage()); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage()); + } } - @ApiOperation("閫氱敤鍓嶇鎺у埗鍛戒护") - @ApiImplicitParams({ - @ApiImplicitParam(name = "deviceId", value = "璁惧ID", dataTypeClass = String.class), - @ApiImplicitParam(name = "channelId", value = "閫氶亾ID", dataTypeClass = String.class), - @ApiImplicitParam(name = "cmdCode", value = "鎸囦护鐮�", dataTypeClass = Integer.class), - @ApiImplicitParam(name = "parameter1", value = "鏁版嵁涓�", dataTypeClass = Integer.class), - @ApiImplicitParam(name = "parameter2", value = "鏁版嵁浜�", dataTypeClass = Integer.class), - @ApiImplicitParam(name = "combindCode2", value = "缁勫悎鐮佷簩", dataTypeClass = Integer.class), - }) + + @Operation(summary = "閫氱敤鍓嶇鎺у埗鍛戒护", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true) + @Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true) + @Parameter(name = "cmdCode", description = "鎸囦护鐮�", required = true) + @Parameter(name = "parameter1", description = "鏁版嵁涓�", required = true) + @Parameter(name = "parameter2", description = "鏁版嵁浜�", required = true) + @Parameter(name = "combindCode2", description = "缁勫悎鐮佷簩", required = true) @PostMapping("/front_end_command/{deviceId}/{channelId}") - public ResponseEntity<String> frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){ + public void frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){ if (logger.isDebugEnabled()) { logger.debug(String.format("璁惧浜戝彴鎺у埗 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s 锛宑mdCode锛�%d parameter1锛�%d parameter2锛�%d",deviceId, channelId, cmdCode, parameter1, parameter2)); } Device device = storager.queryVideoDevice(deviceId); - cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2); - return new ResponseEntity<String>("success",HttpStatus.OK); + try { + cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2); + } catch (SipException | InvalidArgumentException | ParseException e) { + logger.error("[鍛戒护鍙戦�佸け璐 鍓嶇鎺у埗: {}", e.getMessage()); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage()); + } } - @ApiOperation("棰勭疆浣嶆煡璇�") - @ApiImplicitParams({ - @ApiImplicitParam(name = "deviceId", value = "璁惧ID", dataTypeClass = String.class), - @ApiImplicitParam(name = "channelId", value = "閫氶亾ID", dataTypeClass = String.class), - }) + + @Operation(summary = "棰勭疆浣嶆煡璇�", security = @SecurityRequirement(name = JwtUtils.HEADER)) + @Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true) + @Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true) @GetMapping("/preset/query/{deviceId}/{channelId}") - public DeferredResult<ResponseEntity<String>> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) { + public DeferredResult<String> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) { if (logger.isDebugEnabled()) { logger.debug("璁惧棰勭疆浣嶆煡璇PI璋冪敤"); } Device device = storager.queryVideoDevice(deviceId); String uuid = UUID.randomUUID().toString(); - String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (StringUtils.isEmpty(channelId) ? deviceId : channelId); - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); + String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId); + DeferredResult<String> result = new DeferredResult<String> (3 * 1000L); result.onTimeout(()->{ logger.warn(String.format("鑾峰彇璁惧棰勭疆浣嶈秴鏃�")); // 閲婃斁rtpserver @@ -154,14 +164,18 @@ return result; } resultHolder.put(key, uuid, result); - cmder.presetQuery(device, channelId, event -> { - RequestMessage msg = new RequestMessage(); - msg.setId(uuid); - msg.setKey(key); - msg.setData(String.format("鑾峰彇璁惧棰勭疆浣嶅け璐ワ紝閿欒鐮侊細 %s, %s", event.statusCode, event.msg)); - resultHolder.invokeResult(msg); - }); - + try { + cmder.presetQuery(device, channelId, event -> { + RequestMessage msg = new RequestMessage(); + msg.setId(uuid); + msg.setKey(key); + msg.setData(String.format("鑾峰彇璁惧棰勭疆浣嶅け璐ワ紝閿欒鐮侊細 %s, %s", event.statusCode, event.msg)); + resultHolder.invokeResult(msg); + }); + } catch (InvalidArgumentException | SipException | ParseException e) { + logger.error("[鍛戒护鍙戦�佸け璐 鑾峰彇璁惧棰勭疆浣�: {}", e.getMessage()); + throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage()); + } return result; } } -- Gitblit v1.8.0