From 3d6db7478d79b824f93708f936c598cc622221f2 Mon Sep 17 00:00:00 2001 From: mk1990 <153958232@qq.com> Date: Mon, 20 Jun 2022 15:10:31 +0800 Subject: [PATCH] =?UTF-8?q?fix=E8=AE=BE=E5=A4=87=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DeviceStatusResponseMessageHandler.java | 2 +- .../vmanager/gb28181/device/DeviceQuery.java | 35 +++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceStatusResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceStatusResponseMessageHandler.java index 1fed401a..17738a5f 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceStatusResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceStatusResponseMessageHandler.java @@ -82,7 +82,7 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen deviceService.offline(device.getDeviceId()); } RequestMessage msg = new RequestMessage(); - msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId() + channelId); + msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId()); msg.setData(json); deferredResultHolder.invokeAllResult(msg); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java index 4c895378..ccec148b 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java @@ -45,18 +45,18 @@ import java.util.*; @RestController @RequestMapping("/api/device/query") public class DeviceQuery { - + private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class); - + @Autowired private IVideoManagerStorage storager; @Autowired private IRedisCatchStorage redisCatchStorage; - + @Autowired private SIPCommander cmder; - + @Autowired private DeferredResultHolder resultHolder; @@ -80,11 +80,11 @@ public class DeviceQuery { }) @GetMapping("/devices/{deviceId}") public ResponseEntity devices(@PathVariable String deviceId){ - + // if (logger.isDebugEnabled()) { // logger.debug("查询视频设备API调用,deviceId:" + deviceId); // } - + Device device = storager.queryVideoDevice(deviceId); return new ResponseEntity<>(device,HttpStatus.OK); } @@ -102,11 +102,11 @@ public class DeviceQuery { }) @GetMapping("/devices") public PageInfo devices(int page, int count){ - + // if (logger.isDebugEnabled()) { // logger.debug("查询所有视频设备API调用"); // } - + return storager.queryVideoDeviceList(page, count); } @@ -160,7 +160,7 @@ public class DeviceQuery { }) @PostMapping("/devices/{deviceId}/sync") public WVPResult devicesSync(@PathVariable String deviceId){ - + if (logger.isDebugEnabled()) { logger.debug("设备通道信息同步API调用,deviceId:" + deviceId); } @@ -193,7 +193,7 @@ public class DeviceQuery { }) @DeleteMapping("/devices/{deviceId}/delete") public ResponseEntity delete(@PathVariable String deviceId){ - + if (logger.isDebugEnabled()) { logger.debug("设备信息删除API调用,deviceId:" + deviceId); } @@ -327,7 +327,7 @@ public class DeviceQuery { /** * 设备状态查询请求API接口 - * + * * @param deviceId 设备id */ @ApiOperation("设备状态查询") @@ -339,9 +339,14 @@ public class DeviceQuery { if (logger.isDebugEnabled()) { logger.debug("设备状态查询API调用"); } - Device device = storager.queryVideoDevice(deviceId); String uuid = UUID.randomUUID().toString(); String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId; + Device device = storager.queryVideoDevice(deviceId); + DeferredResult> result = new DeferredResult>(2*1000L); + if(device == null) { + result.setResult(new ResponseEntity(String.format("设备%s不存在", deviceId),HttpStatus.OK)); + return result; + } cmder.deviceStatusQuery(device, event -> { RequestMessage msg = new RequestMessage(); msg.setId(uuid); @@ -349,7 +354,7 @@ public class DeviceQuery { msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg)); resultHolder.invokeResult(msg); }); - DeferredResult> result = new DeferredResult>(2*1000L); + result.onTimeout(()->{ logger.warn(String.format("获取设备状态超时")); // 释放rtpserver @@ -386,8 +391,8 @@ public class DeviceQuery { }) @GetMapping("/alarm/{deviceId}") public DeferredResult> alarmApi(@PathVariable String deviceId, - @RequestParam(required = false) String startPriority, - @RequestParam(required = false) String endPriority, + @RequestParam(required = false) String startPriority, + @RequestParam(required = false) String endPriority, @RequestParam(required = false) String alarmMethod, @RequestParam(required = false) String alarmType, @RequestParam(required = false) String startTime,