diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/DeviceControl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/DeviceControl.java index 06d5fa85..55017deb 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/controller/DeviceControl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/controller/DeviceControl.java @@ -16,6 +16,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.gb28181.service.IDeviceService; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; +import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -80,22 +81,22 @@ public class DeviceControl { @Parameter(name = "channelId", description = "通道国标编号", required = true) @Parameter(name = "recordCmdStr", description = "命令, 可选值:Record(手动录像),StopRecord(停止手动录像)", required = true) @GetMapping("/record/{deviceId}/{recordCmdStr}") - public DeferredResult> recordApi(@PathVariable String deviceId, - @PathVariable String recordCmdStr, String channelId) { + public DeferredResult>> recordApi(@PathVariable String deviceId, + @PathVariable String recordCmdStr, String channelId) { if (log.isDebugEnabled()) { log.debug("开始/停止录像API调用"); } Device device = deviceService.getDeviceByDeviceId(deviceId); String uuid = UUID.randomUUID().toString(); String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId + channelId; - DeferredResult> result = new DeferredResult>(3 * 1000L); + DeferredResult>> result = new DeferredResult<>(3 * 1000L); result.onTimeout(() -> { log.warn(String.format("开始/停止录像操作超时, 设备未返回应答指令")); // 释放rtpserver RequestMessage msg = new RequestMessage(); msg.setKey(key); msg.setId(uuid); - msg.setData("Timeout. Device did not response to this command."); + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答")); resultHolder.invokeAllResult(msg); }); if (resultHolder.exist(key, null)){ @@ -107,7 +108,7 @@ public class DeviceControl { RequestMessage msg = new RequestMessage(); msg.setId(uuid); msg.setKey(key); - msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg)); + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("开始/停止录像操作失败,错误码: %s, %s", event.statusCode, event.msg))); resultHolder.invokeAllResult(msg); },null); } catch (InvalidArgumentException | SipException | ParseException e) { @@ -128,7 +129,7 @@ public class DeviceControl { @Parameter(name = "deviceId", description = "设备国标编号", required = true) @Parameter(name = "guardCmdStr", description = "命令, 可选值:SetGuard(布防),ResetGuard(撤防)", required = true) @GetMapping("/guard/{deviceId}/{guardCmdStr}") - public DeferredResult guardApi(@PathVariable String deviceId, @PathVariable String guardCmdStr) { + public DeferredResult> guardApi(@PathVariable String deviceId, @PathVariable String guardCmdStr) { if (log.isDebugEnabled()) { log.debug("布防/撤防API调用"); } @@ -140,14 +141,14 @@ public class DeviceControl { RequestMessage msg = new RequestMessage(); msg.setId(uuid); msg.setKey(key); - msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", event.statusCode, event.msg)); + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("布防/撤防操作失败,错误码: %s, %s", event.statusCode, event.msg))); resultHolder.invokeResult(msg); },null); } catch (InvalidArgumentException | SipException | ParseException e) { log.error("[命令发送失败] 布防/撤防操作: {}", e.getMessage()); throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送: " + e.getMessage()); } - DeferredResult result = new DeferredResult<>(3 * 1000L); + DeferredResult> result = new DeferredResult<>(3 * 1000L); resultHolder.put(key, uuid, result); result.onTimeout(() -> { log.warn(String.format("布防/撤防操作超时, 设备未返回应答指令")); @@ -155,7 +156,7 @@ public class DeviceControl { RequestMessage msg = new RequestMessage(); msg.setKey(key); msg.setId(uuid); - msg.setData("Timeout. Device did not response to this command."); + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答")); resultHolder.invokeResult(msg); }); @@ -175,7 +176,7 @@ public class DeviceControl { @Parameter(name = "alarmMethod", description = "报警方式") @Parameter(name = "alarmType", description = "报警类型") @GetMapping("/reset_alarm/{deviceId}") - public DeferredResult> resetAlarmApi(@PathVariable String deviceId, String channelId, + public DeferredResult>> resetAlarmApi(@PathVariable String deviceId, String channelId, @RequestParam(required = false) String alarmMethod, @RequestParam(required = false) String alarmType) { if (log.isDebugEnabled()) { @@ -189,21 +190,21 @@ public class DeviceControl { RequestMessage msg = new RequestMessage(); msg.setId(uuid); msg.setKey(key); - msg.setData(String.format("报警复位操作失败,错误码: %s, %s", event.statusCode, event.msg)); + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("操作失败,错误码: %s, %s", event.statusCode, event.msg))); resultHolder.invokeResult(msg); },null); } catch (InvalidArgumentException | SipException | ParseException e) { log.error("[命令发送失败] 报警复位: {}", e.getMessage()); throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); } - DeferredResult> result = new DeferredResult>(3 * 1000L); + DeferredResult>> result = new DeferredResult<>(3 * 1000L); result.onTimeout(() -> { log.warn(String.format("报警复位操作超时, 设备未返回应答指令")); // 释放rtpserver RequestMessage msg = new RequestMessage(); msg.setId(uuid); msg.setKey(key); - msg.setData("Timeout. Device did not response to this command."); + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答")); resultHolder.invokeResult(msg); }); resultHolder.put(key, uuid, result); @@ -255,7 +256,7 @@ public class DeviceControl { @Parameter(name = "presetIndex", description = "调用预置位编号") @Parameter(name = "resetTime", description = "自动归位时间间隔 单位:秒") @GetMapping("/home_position") - public DeferredResult homePositionApi(String deviceId, String channelId, Boolean enabled, + public DeferredResult> homePositionApi(String deviceId, String channelId, Boolean enabled, @RequestParam(required = false) Integer resetTime, @RequestParam(required = false) Integer presetIndex) { if (log.isDebugEnabled()) { @@ -269,25 +270,21 @@ public class DeviceControl { RequestMessage msg = new RequestMessage(); msg.setId(uuid); msg.setKey(key); - msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", event.statusCode, event.msg)); + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("操作失败,错误码: %s, %s", event.statusCode, event.msg))); resultHolder.invokeResult(msg); },null); } catch (InvalidArgumentException | SipException | ParseException e) { log.error("[命令发送失败] 看守位控制: {}", e.getMessage()); throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); } - DeferredResult result = new DeferredResult<>(3 * 1000L); + DeferredResult> result = new DeferredResult<>(3 * 1000L); result.onTimeout(() -> { log.warn(String.format("看守位控制操作超时, 设备未返回应答指令")); // 释放rtpserver RequestMessage msg = new RequestMessage(); msg.setId(uuid); msg.setKey(key); - JSONObject json = new JSONObject(); - json.put("DeviceID", deviceId); - json.put("Status", "Timeout"); - json.put("Description", "看守位控制操作超时, 设备未返回应答指令"); - msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令"); + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), "操作超时, 设备未应答")); //("看守位控制操作超时, 设备未返回应答指令"); resultHolder.invokeResult(msg); }); resultHolder.put(key, uuid, result); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlResponseMessageHandler.java index ef3531a8..f3f48978 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceControlResponseMessageHandler.java @@ -8,7 +8,8 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; -import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; +import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import gov.nist.javax.sip.message.SIPRequest; import lombok.extern.slf4j.Slf4j; import org.dom4j.Element; @@ -51,14 +52,19 @@ public class DeviceControlResponseMessageHandler extends SIPRequestProcessorPare } JSONObject json = new JSONObject(); String channelId = getText(element, "DeviceID"); - XmlUtil.node2Json(element, json); - if (log.isDebugEnabled()) { - log.debug(json.toJSONString()); - } + String result = getText(element, "Result"); + RequestMessage msg = new RequestMessage(); String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + device.getDeviceId() + channelId; msg.setKey(key); - msg.setData(json); + if ("OK".equalsIgnoreCase(result)) { + msg.setData(WVPResult.success()); + }else { + msg.setData(WVPResult.fail(ErrorCode.ERROR100)); + } + if (log.isDebugEnabled()) { + log.debug(json.toJSONString()); + } deferredResultHolder.invokeAllResult(msg); }