From 5461b8ebf2f8bf66a9d34351eb8783484304958a Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期一, 22 八月 2022 16:17:28 +0800
Subject: [PATCH] 支持全局异常和统一返回结果,未完待续

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java
index 615e644..30320e6 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java
@@ -8,12 +8,14 @@
 package com.genersoft.iot.vmp.vmanager.gb28181.device;
 
 import com.alibaba.fastjson.JSONObject;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -22,6 +24,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
+import org.springframework.util.ObjectUtils;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.context.request.async.DeferredResult;
@@ -50,14 +53,10 @@
      * 
      * @param deviceId 璁惧ID
      */
-//	 //@ApiOperation("杩滅▼鍚姩鎺у埗鍛戒护")
-//	@ApiImplicitParams({
-//			@ApiImplicitParam(name = "deviceId", value ="璁惧ID", required = true, dataTypeClass = String.class),
-//	})
 	@Operation(summary = "杩滅▼鍚姩鎺у埗鍛戒护")
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
     @GetMapping("/teleboot/{deviceId}")
-    public ResponseEntity<String> teleBootApi(@PathVariable String deviceId) {
+    public String teleBootApi(@PathVariable String deviceId) {
         if (logger.isDebugEnabled()) {
             logger.debug("璁惧杩滅▼鍚姩API璋冪敤");
         }
@@ -67,10 +66,10 @@
             JSONObject json = new JSONObject();
             json.put("DeviceID", deviceId);
             json.put("Result", "OK");
-            return new ResponseEntity<>(json.toJSONString(), HttpStatus.OK);
+            return json.toJSONString();
         } else {
             logger.warn("璁惧杩滅▼鍚姩API璋冪敤澶辫触锛�");
-            return new ResponseEntity<String>("璁惧杩滅▼鍚姩API璋冪敤澶辫触锛�", HttpStatus.INTERNAL_SERVER_ERROR);
+			throw new ControllerException(ErrorCode.ERROR100.getCode(), "璁惧杩滅▼鍚姩API璋冪敤澶辫触锛�");
         }
     }
 
@@ -255,7 +254,7 @@
         if (logger.isDebugEnabled()) {
 			logger.debug("鎶ヨ澶嶄綅API璋冪敤");
 		}
-		String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId);
+		String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
 		String uuid = UUID.randomUUID().toString();
 		Device device = storager.queryVideoDevice(deviceId);
 		cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> {

--
Gitblit v1.8.0