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/ptz/PtzController.java |   18 ++++++------------
 1 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java
index 489396b..6903e4d 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java
@@ -7,8 +7,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 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;
@@ -46,7 +45,6 @@
 	 * @param horizonSpeed	姘村钩绉诲姩閫熷害
 	 * @param verticalSpeed	鍨傜洿绉诲姩閫熷害
 	 * @param zoomSpeed	    缂╂斁閫熷害
-	 * @return String 鎺у埗缁撴灉
 	 */
 
 	@Operation(summary = "浜戝彴鎺у埗")
@@ -57,7 +55,7 @@
 	@Parameter(name = "verticalSpeed", description = "鍨傜洿閫熷害", required = true)
 	@Parameter(name = "zoomSpeed", description = "缂╂斁閫熷害", required = true)
 	@PostMapping("/control/{deviceId}/{channelId}")
-	public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){
+	public void ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){
 
 		if (logger.isDebugEnabled()) {
 			logger.debug(String.format("璁惧浜戝彴鎺у埗 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s 锛宑ommand锛�%s 锛宧orizonSpeed锛�%d 锛寁erticalSpeed锛�%d 锛寊oomSpeed锛�%d",deviceId, channelId, command, horizonSpeed, verticalSpeed, zoomSpeed));
@@ -96,13 +94,11 @@
 				cmdCode = 32;
 				break;
 			case "stop":
-				cmdCode = 0;
 				break;
 			default:
 				break;
 		}
 		cmder.frontEndCmd(device, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed);
-		return new ResponseEntity<String>("success",HttpStatus.OK);
 	}
 
 
@@ -114,7 +110,7 @@
 	@Parameter(name = "parameter2", description = "鏁版嵁浜�", required = true)
 	@Parameter(name = "combindCode2", description = "缁勫悎鐮佷簩", required = true)
 	@PostMapping("/front_end_command/{deviceId}/{channelId}")
-	public ResponseEntity<String> frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){
+	public void frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){
 
 		if (logger.isDebugEnabled()) {
 			logger.debug(String.format("璁惧浜戝彴鎺у埗 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s 锛宑mdCode锛�%d parameter1锛�%d parameter2锛�%d",deviceId, channelId, cmdCode, parameter1, parameter2));
@@ -122,7 +118,6 @@
 		Device device = storager.queryVideoDevice(deviceId);
 
 		cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2);
-		return new ResponseEntity<String>("success",HttpStatus.OK);
 	}
 
 
@@ -130,14 +125,14 @@
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
 	@Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true)
 	@GetMapping("/preset/query/{deviceId}/{channelId}")
-	public DeferredResult<ResponseEntity<String>> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
+	public DeferredResult<String> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
 		if (logger.isDebugEnabled()) {
 			logger.debug("璁惧棰勭疆浣嶆煡璇PI璋冪敤");
 		}
 		Device device = storager.queryVideoDevice(deviceId);
 		String uuid =  UUID.randomUUID().toString();
-		String key =  DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (StringUtils.isEmpty(channelId) ? deviceId : channelId);
-		DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L);
+		String key =  DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
+		DeferredResult<String> result = new DeferredResult<String> (3 * 1000L);
 		result.onTimeout(()->{
 			logger.warn(String.format("鑾峰彇璁惧棰勭疆浣嶈秴鏃�"));
 			// 閲婃斁rtpserver
@@ -158,7 +153,6 @@
 			msg.setData(String.format("鑾峰彇璁惧棰勭疆浣嶅け璐ワ紝閿欒鐮侊細 %s, %s", event.statusCode, event.msg));
 			resultHolder.invokeResult(msg);
 		});
-
 		return result;
 	}
 }

--
Gitblit v1.8.0