From 058909197e7c972fcea40acc9e4e6a14d2052bd6 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 27 Dec 2024 17:37:50 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=9B=BD=E6=A0=87PTZ]=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E4=BA=91=E5=8F=B0=E6=8E=A7=E5=88=B6=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmp/gb28181/controller/PtzController.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PtzController.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PtzController.java index 8749ef48..3b87d1cf 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PtzController.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/PtzController.java @@ -5,6 +5,7 @@ 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.service.IDeviceService; +import com.genersoft.iot.vmp.gb28181.service.IPTZService; 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; @@ -15,8 +16,12 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.DeferredResult; import javax.sip.InvalidArgumentException; @@ -36,6 +41,9 @@ public class PtzController { @Autowired private IDeviceService deviceService; + @Autowired + private IPTZService iptzService; + @Autowired private DeferredResultHolder resultHolder; @@ -52,7 +60,6 @@ public class PtzController { if (log.isDebugEnabled()) { log.debug(String.format("设备云台控制 API调用,deviceId:%s ,channelId:%s ,cmdCode:%d parameter1:%d parameter2:%d",deviceId, channelId, cmdCode, parameter1, parameter2)); } - Device device = deviceService.getDeviceByDeviceId(deviceId); if (parameter1 == null || parameter1 < 0 || parameter1 > 255) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "parameter1 为 1-255的数字"); @@ -63,12 +70,12 @@ public class PtzController { if (combindCode2 == null || combindCode2 < 0 || combindCode2 > 16) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "parameter1 为 1-255的数字"); } - try { - cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2); - } catch (SipException | InvalidArgumentException | ParseException e) { - log.error("[命令发送失败] 前端控制: {}", e.getMessage()); - throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); - } + + Device device = deviceService.getDeviceByDeviceId(deviceId); + + Assert.notNull(device, "设备[" + deviceId + "]不存在"); + + iptzService.frontEndCommand(device, channelId, cmdCode, parameter1, parameter2, combindCode2); } @Operation(summary = "云台控制", security = @SecurityRequirement(name = JwtUtils.HEADER))