From e805e2ce3283d9dc721da0c49fc9b981e75b0d7c Mon Sep 17 00:00:00 2001 From: "Mr.Wang" Date: Thu, 20 Jun 2024 11:36:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=B8=E6=9C=BA=E5=A2=9E=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=A2=84=E7=BD=AE=E4=BD=8D=E5=88=97=E8=A1=A8=E3=80=81?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A2=84=E7=BD=AE=E4=BD=8D=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/controller/VideoController.java | 153 +++++++++++------- 1 file changed, 94 insertions(+), 59 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/VideoController.java b/zc-business/src/main/java/com/zc/business/controller/VideoController.java index 35152f2c..8cdba975 100644 --- a/zc-business/src/main/java/com/zc/business/controller/VideoController.java +++ b/zc-business/src/main/java/com/zc/business/controller/VideoController.java @@ -166,9 +166,6 @@ public class VideoController extends BaseController { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); - - JSONObject jsonResult = null; - // 1000 米 String distance = "1000"; @@ -194,19 +191,7 @@ public class VideoController extends BaseController { .data(requestParams) // 请求参数 .get(); // 请求方法 - if (response.body() != null) { - jsonResult = JSONObject.parseObject(response.body().string()); - - if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { - getToken(); - okHttp.get(); - if (response.body() != null) { - jsonResult = JSONObject.parseObject(response.body().string()); - } - } - } - - return jsonResult; + return getJsonResult(response,okHttp); } @@ -348,9 +333,6 @@ public class VideoController extends BaseController { public JSONObject synchronizeCameraData() throws HttpException, IOException { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); - JSONObject jsonResult = null; - - OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(); @@ -370,19 +352,7 @@ public class VideoController extends BaseController { .data(requestParams) // 请求参数 .get(); // 请求方法 - if (response.body() != null) { - jsonResult = JSONObject.parseObject(response.body().string()); - - if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { - getToken(); - okHttp.get(); - if (response.body() != null) { - jsonResult = JSONObject.parseObject(response.body().string()); - } - } - } - - return jsonResult; + return getJsonResult(response,okHttp); } @@ -532,26 +502,61 @@ public class VideoController extends BaseController { return jsonResult; } - /** - * 云平台控制 + * 新增预置位 */ - @ApiOperation("云平台控制") - @GetMapping(value = "/PTZControl") - public JSONObject PTZControl(@ApiParam(value = "相机id", name = "camId", required = true) String camId, - @ApiParam(value = "指令类型", name = "cmdType", required = true) String cmdType, - @ApiParam(value = "速度", name = "speed", required = true) String speed) throws HttpException, IOException { + @ApiOperation("新增预置位") + @GetMapping(value = "/addPreset") + public JSONObject addPreset(@ApiParam(value = "相机id", name = "camId", required = true) String camId, + @ApiParam(value = "预置位名称", name = "presetName", required = true) String presetName) throws HttpException, IOException { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); + OkHttp okHttp = new OkHttp(); - JSONObject jsonResult = null; + RequestParams requestParams = new RequestParams(); + requestParams.put("camId", camId); + requestParams.put("presetName", presetName); + + Map header = new HashMap<>(); + + if (VideoController.TOKEN == null) { + getToken(); + } + + header.put("Authorization", TOKEN); + + Response response // 请求响应 + = okHttp + .headers(header) + .url(cameraInfo.getString("URL") + "/preset/addPreset") // 请求地址 + .data(requestParams) // 请求参数 + .post(); // 请求方法 + + // 新增预置位 + JSONObject addPresetResult = getJsonResult(response, okHttp); + if (addPresetResult.get("code").equals(200)) { + JSONObject data = JSON.parseObject(addPresetResult.get("data").toString()); + return PTZControl(camId, "8", data.getString("presetId")); + }else { + JSONObject error = new JSONObject(); + error.put("code",500); + error.put("msg","新增预置位失败"); + return error; + } + + } + + /** + * 查询预置位列表 + */ + @ApiOperation("查询预置位列表") + @GetMapping(value = "/presetList") + public JSONObject presetList(@ApiParam(value = "相机id", name = "camId", required = true) String camId) throws HttpException, IOException { + JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(); - requestParams.put("msgType", "3"); requestParams.put("camId", camId); - requestParams.put("cmdType", cmdType); - requestParams.put("speed", speed); Map header = new HashMap<>(); @@ -564,10 +569,17 @@ public class VideoController extends BaseController { Response response // 请求响应 = okHttp .headers(header) - .url(cameraInfo.getString("URL") + "/videoInfo/api/PTZControl") // 请求地址 + .url(cameraInfo.getString("URL") + "/preset/presetList") // 请求地址 .data(requestParams) // 请求参数 .get(); // 请求方法 + return getJsonResult(response,okHttp); + } + /** + * 返回结果处理 + */ + public JSONObject getJsonResult(Response response, OkHttp okHttp) throws HttpException, IOException { + JSONObject jsonResult = null; if (response.body() != null) { jsonResult = JSONObject.parseObject(response.body().string()); @@ -579,11 +591,47 @@ public class VideoController extends BaseController { } } } - return jsonResult; } + /** + * 云平台控制 + */ + @ApiOperation("云平台控制") + @GetMapping(value = "/PTZControl") + public JSONObject PTZControl(@ApiParam(value = "相机id", name = "camId", required = true) String camId, + @ApiParam(value = "指令类型", name = "cmdType", required = true) String cmdType, + @ApiParam(value = "速度", name = "speed", required = true) String speed) throws HttpException, IOException { + JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + requestParams.put("msgType", "3"); + requestParams.put("camId", camId); + requestParams.put("cmdType", cmdType); + requestParams.put("speed", speed); + + Map header = new HashMap<>(); + + if (VideoController.TOKEN == null) { + getToken(); + } + + header.put("Authorization", TOKEN); + + Response response // 请求响应 + = okHttp + .headers(header) + .url(cameraInfo.getString("URL") + "/videoInfo/api/PTZControl") // 请求地址 + .data(requestParams) // 请求参数 + .get(); // 请求方法 + + return getJsonResult(response,okHttp); + } + + public void getToken() throws HttpException, IOException { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); @@ -618,8 +666,6 @@ public class VideoController extends BaseController { public JSONObject getCamByDept() throws HttpException, IOException { JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); - JSONObject jsonResult = null; - OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(); @@ -639,19 +685,8 @@ public class VideoController extends BaseController { .url(cameraInfo.getString("URL") + "/system/camera/camList") // 请求地址 .data(requestParams) // 请求参数 .get(); // 请求方法 - if (response.body() != null) { - jsonResult = JSONObject.parseObject(response.body().string()); - if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { - getToken(); - okHttp.get(); - if (response.body() != null) { - jsonResult = JSONObject.parseObject(response.body().string()); - } - } - } - - return jsonResult; + return getJsonResult(response,okHttp); } /**