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