Commit 3d6db7478d79b824f93708f936c598cc622221f2

Authored by mk1990
1 parent ddfe4a7b

fix设备状态查询接口

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 @@ -82,7 +82,7 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen
82 deviceService.offline(device.getDeviceId()); 82 deviceService.offline(device.getDeviceId());
83 } 83 }
84 RequestMessage msg = new RequestMessage(); 84 RequestMessage msg = new RequestMessage();
85 - msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId() + channelId); 85 + msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId());
86 msg.setData(json); 86 msg.setData(json);
87 deferredResultHolder.invokeAllResult(msg); 87 deferredResultHolder.invokeAllResult(msg);
88 } 88 }
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
@@ -45,18 +45,18 @@ import java.util.*; @@ -45,18 +45,18 @@ import java.util.*;
45 @RestController 45 @RestController
46 @RequestMapping("/api/device/query") 46 @RequestMapping("/api/device/query")
47 public class DeviceQuery { 47 public class DeviceQuery {
48 - 48 +
49 private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class); 49 private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class);
50 - 50 +
51 @Autowired 51 @Autowired
52 private IVideoManagerStorage storager; 52 private IVideoManagerStorage storager;
53 53
54 @Autowired 54 @Autowired
55 private IRedisCatchStorage redisCatchStorage; 55 private IRedisCatchStorage redisCatchStorage;
56 - 56 +
57 @Autowired 57 @Autowired
58 private SIPCommander cmder; 58 private SIPCommander cmder;
59 - 59 +
60 @Autowired 60 @Autowired
61 private DeferredResultHolder resultHolder; 61 private DeferredResultHolder resultHolder;
62 62
@@ -80,11 +80,11 @@ public class DeviceQuery { @@ -80,11 +80,11 @@ public class DeviceQuery {
80 }) 80 })
81 @GetMapping("/devices/{deviceId}") 81 @GetMapping("/devices/{deviceId}")
82 public ResponseEntity<Device> devices(@PathVariable String deviceId){ 82 public ResponseEntity<Device> devices(@PathVariable String deviceId){
83 - 83 +
84 // if (logger.isDebugEnabled()) { 84 // if (logger.isDebugEnabled()) {
85 // logger.debug("查询视频设备API调用,deviceId:" + deviceId); 85 // logger.debug("查询视频设备API调用,deviceId:" + deviceId);
86 // } 86 // }
87 - 87 +
88 Device device = storager.queryVideoDevice(deviceId); 88 Device device = storager.queryVideoDevice(deviceId);
89 return new ResponseEntity<>(device,HttpStatus.OK); 89 return new ResponseEntity<>(device,HttpStatus.OK);
90 } 90 }
@@ -102,11 +102,11 @@ public class DeviceQuery { @@ -102,11 +102,11 @@ public class DeviceQuery {
102 }) 102 })
103 @GetMapping("/devices") 103 @GetMapping("/devices")
104 public PageInfo<Device> devices(int page, int count){ 104 public PageInfo<Device> devices(int page, int count){
105 - 105 +
106 // if (logger.isDebugEnabled()) { 106 // if (logger.isDebugEnabled()) {
107 // logger.debug("查询所有视频设备API调用"); 107 // logger.debug("查询所有视频设备API调用");
108 // } 108 // }
109 - 109 +
110 return storager.queryVideoDeviceList(page, count); 110 return storager.queryVideoDeviceList(page, count);
111 } 111 }
112 112
@@ -160,7 +160,7 @@ public class DeviceQuery { @@ -160,7 +160,7 @@ public class DeviceQuery {
160 }) 160 })
161 @PostMapping("/devices/{deviceId}/sync") 161 @PostMapping("/devices/{deviceId}/sync")
162 public WVPResult<SyncStatus> devicesSync(@PathVariable String deviceId){ 162 public WVPResult<SyncStatus> devicesSync(@PathVariable String deviceId){
163 - 163 +
164 if (logger.isDebugEnabled()) { 164 if (logger.isDebugEnabled()) {
165 logger.debug("设备通道信息同步API调用,deviceId:" + deviceId); 165 logger.debug("设备通道信息同步API调用,deviceId:" + deviceId);
166 } 166 }
@@ -193,7 +193,7 @@ public class DeviceQuery { @@ -193,7 +193,7 @@ public class DeviceQuery {
193 }) 193 })
194 @DeleteMapping("/devices/{deviceId}/delete") 194 @DeleteMapping("/devices/{deviceId}/delete")
195 public ResponseEntity<String> delete(@PathVariable String deviceId){ 195 public ResponseEntity<String> delete(@PathVariable String deviceId){
196 - 196 +
197 if (logger.isDebugEnabled()) { 197 if (logger.isDebugEnabled()) {
198 logger.debug("设备信息删除API调用,deviceId:" + deviceId); 198 logger.debug("设备信息删除API调用,deviceId:" + deviceId);
199 } 199 }
@@ -327,7 +327,7 @@ public class DeviceQuery { @@ -327,7 +327,7 @@ public class DeviceQuery {
327 327
328 /** 328 /**
329 * 设备状态查询请求API接口 329 * 设备状态查询请求API接口
330 - * 330 + *
331 * @param deviceId 设备id 331 * @param deviceId 设备id
332 */ 332 */
333 @ApiOperation("设备状态查询") 333 @ApiOperation("设备状态查询")
@@ -339,9 +339,14 @@ public class DeviceQuery { @@ -339,9 +339,14 @@ public class DeviceQuery {
339 if (logger.isDebugEnabled()) { 339 if (logger.isDebugEnabled()) {
340 logger.debug("设备状态查询API调用"); 340 logger.debug("设备状态查询API调用");
341 } 341 }
342 - Device device = storager.queryVideoDevice(deviceId);  
343 String uuid = UUID.randomUUID().toString(); 342 String uuid = UUID.randomUUID().toString();
344 String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId; 343 String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId;
  344 + Device device = storager.queryVideoDevice(deviceId);
  345 + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L);
  346 + if(device == null) {
  347 + result.setResult(new ResponseEntity(String.format("设备%s不存在", deviceId),HttpStatus.OK));
  348 + return result;
  349 + }
345 cmder.deviceStatusQuery(device, event -> { 350 cmder.deviceStatusQuery(device, event -> {
346 RequestMessage msg = new RequestMessage(); 351 RequestMessage msg = new RequestMessage();
347 msg.setId(uuid); 352 msg.setId(uuid);
@@ -349,7 +354,7 @@ public class DeviceQuery { @@ -349,7 +354,7 @@ public class DeviceQuery {
349 msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg)); 354 msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg));
350 resultHolder.invokeResult(msg); 355 resultHolder.invokeResult(msg);
351 }); 356 });
352 - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L); 357 +
353 result.onTimeout(()->{ 358 result.onTimeout(()->{
354 logger.warn(String.format("获取设备状态超时")); 359 logger.warn(String.format("获取设备状态超时"));
355 // 释放rtpserver 360 // 释放rtpserver
@@ -386,8 +391,8 @@ public class DeviceQuery { @@ -386,8 +391,8 @@ public class DeviceQuery {
386 }) 391 })
387 @GetMapping("/alarm/{deviceId}") 392 @GetMapping("/alarm/{deviceId}")
388 public DeferredResult<ResponseEntity<String>> alarmApi(@PathVariable String deviceId, 393 public DeferredResult<ResponseEntity<String>> alarmApi(@PathVariable String deviceId,
389 - @RequestParam(required = false) String startPriority,  
390 - @RequestParam(required = false) String endPriority, 394 + @RequestParam(required = false) String startPriority,
  395 + @RequestParam(required = false) String endPriority,
391 @RequestParam(required = false) String alarmMethod, 396 @RequestParam(required = false) String alarmMethod,
392 @RequestParam(required = false) String alarmType, 397 @RequestParam(required = false) String alarmType,
393 @RequestParam(required = false) String startTime, 398 @RequestParam(required = false) String startTime,