fix设备状态查询接口

This commit is contained in:
mk1990 2022-06-20 15:10:31 +08:00
parent f0096af3e2
commit e87cd8cd91
2 changed files with 21 additions and 16 deletions

View File

@ -82,7 +82,7 @@ public class DeviceStatusResponseMessageHandler extends SIPRequestProcessorParen
deviceService.offline(device.getDeviceId()); deviceService.offline(device.getDeviceId());
} }
RequestMessage msg = new RequestMessage(); RequestMessage msg = new RequestMessage();
msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId() + channelId); msg.setKey(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + device.getDeviceId());
msg.setData(json); msg.setData(json);
deferredResultHolder.invokeAllResult(msg); deferredResultHolder.invokeAllResult(msg);
} }

View File

@ -45,18 +45,18 @@ import java.util.*;
@RestController @RestController
@RequestMapping("/api/device/query") @RequestMapping("/api/device/query")
public class DeviceQuery { public class DeviceQuery {
private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class); private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class);
@Autowired @Autowired
private IVideoManagerStorage storager; private IVideoManagerStorage storager;
@Autowired @Autowired
private IRedisCatchStorage redisCatchStorage; private IRedisCatchStorage redisCatchStorage;
@Autowired @Autowired
private SIPCommander cmder; private SIPCommander cmder;
@Autowired @Autowired
private DeferredResultHolder resultHolder; private DeferredResultHolder resultHolder;
@ -80,11 +80,11 @@ public class DeviceQuery {
}) })
@GetMapping("/devices/{deviceId}") @GetMapping("/devices/{deviceId}")
public ResponseEntity<Device> devices(@PathVariable String deviceId){ public ResponseEntity<Device> devices(@PathVariable String deviceId){
// if (logger.isDebugEnabled()) { // if (logger.isDebugEnabled()) {
// logger.debug("查询视频设备API调用deviceId" + deviceId); // logger.debug("查询视频设备API调用deviceId" + deviceId);
// } // }
Device device = storager.queryVideoDevice(deviceId); Device device = storager.queryVideoDevice(deviceId);
return new ResponseEntity<>(device,HttpStatus.OK); return new ResponseEntity<>(device,HttpStatus.OK);
} }
@ -102,11 +102,11 @@ public class DeviceQuery {
}) })
@GetMapping("/devices") @GetMapping("/devices")
public PageInfo<Device> devices(int page, int count){ public PageInfo<Device> devices(int page, int count){
// if (logger.isDebugEnabled()) { // if (logger.isDebugEnabled()) {
// logger.debug("查询所有视频设备API调用"); // logger.debug("查询所有视频设备API调用");
// } // }
return storager.queryVideoDeviceList(page, count); return storager.queryVideoDeviceList(page, count);
} }
@ -160,7 +160,7 @@ public class DeviceQuery {
}) })
@PostMapping("/devices/{deviceId}/sync") @PostMapping("/devices/{deviceId}/sync")
public WVPResult<SyncStatus> devicesSync(@PathVariable String deviceId){ public WVPResult<SyncStatus> devicesSync(@PathVariable String deviceId){
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("设备通道信息同步API调用deviceId" + deviceId); logger.debug("设备通道信息同步API调用deviceId" + deviceId);
} }
@ -193,7 +193,7 @@ public class DeviceQuery {
}) })
@DeleteMapping("/devices/{deviceId}/delete") @DeleteMapping("/devices/{deviceId}/delete")
public ResponseEntity<String> delete(@PathVariable String deviceId){ public ResponseEntity<String> delete(@PathVariable String deviceId){
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("设备信息删除API调用deviceId" + deviceId); logger.debug("设备信息删除API调用deviceId" + deviceId);
} }
@ -327,7 +327,7 @@ public class DeviceQuery {
/** /**
* 设备状态查询请求API接口 * 设备状态查询请求API接口
* *
* @param deviceId 设备id * @param deviceId 设备id
*/ */
@ApiOperation("设备状态查询") @ApiOperation("设备状态查询")
@ -339,9 +339,14 @@ public class DeviceQuery {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug("设备状态查询API调用"); logger.debug("设备状态查询API调用");
} }
Device device = storager.queryVideoDevice(deviceId);
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId; String key = DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId;
Device device = storager.queryVideoDevice(deviceId);
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L);
if(device == null) {
result.setResult(new ResponseEntity(String.format("设备%s不存在", deviceId),HttpStatus.OK));
return result;
}
cmder.deviceStatusQuery(device, event -> { cmder.deviceStatusQuery(device, event -> {
RequestMessage msg = new RequestMessage(); RequestMessage msg = new RequestMessage();
msg.setId(uuid); msg.setId(uuid);
@ -349,7 +354,7 @@ public class DeviceQuery {
msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg)); msg.setData(String.format("获取设备状态失败,错误码: %s, %s", event.statusCode, event.msg));
resultHolder.invokeResult(msg); resultHolder.invokeResult(msg);
}); });
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L);
result.onTimeout(()->{ result.onTimeout(()->{
logger.warn(String.format("获取设备状态超时")); logger.warn(String.format("获取设备状态超时"));
// 释放rtpserver // 释放rtpserver
@ -386,8 +391,8 @@ public class DeviceQuery {
}) })
@GetMapping("/alarm/{deviceId}") @GetMapping("/alarm/{deviceId}")
public DeferredResult<ResponseEntity<String>> alarmApi(@PathVariable String deviceId, public DeferredResult<ResponseEntity<String>> alarmApi(@PathVariable String deviceId,
@RequestParam(required = false) String startPriority, @RequestParam(required = false) String startPriority,
@RequestParam(required = false) String endPriority, @RequestParam(required = false) String endPriority,
@RequestParam(required = false) String alarmMethod, @RequestParam(required = false) String alarmMethod,
@RequestParam(required = false) String alarmType, @RequestParam(required = false) String alarmType,
@RequestParam(required = false) String startTime, @RequestParam(required = false) String startTime,