Browse Source

相机增加查询预置位列表、新增预置位操作

develop
Mr.Wang 5 months ago
parent
commit
e805e2ce32
  1. 153
      zc-business/src/main/java/com/zc/business/controller/VideoController.java

153
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 cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo"));
JSONObject jsonResult = null;
// 1000 米 // 1000 米
String distance = "1000"; String distance = "1000";
@ -194,19 +191,7 @@ public class VideoController extends BaseController {
.data(requestParams) // 请求参数 .data(requestParams) // 请求参数
.get(); // 请求方法 .get(); // 请求方法
if (response.body() != null) { return getJsonResult(response,okHttp);
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;
} }
@ -348,9 +333,6 @@ public class VideoController extends BaseController {
public JSONObject synchronizeCameraData() throws HttpException, IOException { public JSONObject synchronizeCameraData() throws HttpException, IOException {
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo"));
JSONObject jsonResult = null;
OkHttp okHttp = new OkHttp(); OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(); RequestParams requestParams = new RequestParams();
@ -370,19 +352,7 @@ public class VideoController extends BaseController {
.data(requestParams) // 请求参数 .data(requestParams) // 请求参数
.get(); // 请求方法 .get(); // 请求方法
if (response.body() != null) { return getJsonResult(response,okHttp);
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;
} }
@ -532,26 +502,61 @@ public class VideoController extends BaseController {
return jsonResult; return jsonResult;
} }
/** /**
* 云平台控制 * 新增预置位
*/ */
@ApiOperation("云平台控制") @ApiOperation("新增预置位")
@GetMapping(value = "/PTZControl") @GetMapping(value = "/addPreset")
public JSONObject PTZControl(@ApiParam(value = "相机id", name = "camId", required = true) String camId, public JSONObject addPreset(@ApiParam(value = "相机id", name = "camId", required = true) String camId,
@ApiParam(value = "指令类型", name = "cmdType", required = true) String cmdType, @ApiParam(value = "预置位名称", name = "presetName", required = true) String presetName) throws HttpException, IOException {
@ApiParam(value = "速度", name = "speed", required = true) String speed) throws HttpException, IOException {
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); 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<String, String> 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(); OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(); RequestParams requestParams = new RequestParams();
requestParams.put("msgType", "3");
requestParams.put("camId", camId); requestParams.put("camId", camId);
requestParams.put("cmdType", cmdType);
requestParams.put("speed", speed);
Map<String, String> header = new HashMap<>(); Map<String, String> header = new HashMap<>();
@ -564,10 +569,17 @@ public class VideoController extends BaseController {
Response response // 请求响应 Response response // 请求响应
= okHttp = okHttp
.headers(header) .headers(header)
.url(cameraInfo.getString("URL") + "/videoInfo/api/PTZControl") // 请求地址 .url(cameraInfo.getString("URL") + "/preset/presetList") // 请求地址
.data(requestParams) // 请求参数 .data(requestParams) // 请求参数
.get(); // 请求方法 .get(); // 请求方法
return getJsonResult(response,okHttp);
}
/**
* 返回结果处理
*/
public JSONObject getJsonResult(Response response, OkHttp okHttp) throws HttpException, IOException {
JSONObject jsonResult = null;
if (response.body() != null) { if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string()); jsonResult = JSONObject.parseObject(response.body().string());
@ -579,11 +591,47 @@ public class VideoController extends BaseController {
} }
} }
} }
return jsonResult; 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<String, String> 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 { public void getToken() throws HttpException, IOException {
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo"));
@ -618,8 +666,6 @@ public class VideoController extends BaseController {
public JSONObject getCamByDept() throws HttpException, IOException { public JSONObject getCamByDept() throws HttpException, IOException {
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo")); JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo"));
JSONObject jsonResult = null;
OkHttp okHttp = new OkHttp(); OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams(); RequestParams requestParams = new RequestParams();
@ -639,19 +685,8 @@ public class VideoController extends BaseController {
.url(cameraInfo.getString("URL") + "/system/camera/camList") // 请求地址 .url(cameraInfo.getString("URL") + "/system/camera/camList") // 请求地址
.data(requestParams) // 请求参数 .data(requestParams) // 请求参数
.get(); // 请求方法 .get(); // 请求方法
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
if (jsonResult.containsKey("code") && UNAUTHORIZED.equals(jsonResult.getInteger("code"))) { return getJsonResult(response,okHttp);
getToken();
okHttp.get();
if (response.body() != null) {
jsonResult = JSONObject.parseObject(response.body().string());
}
}
}
return jsonResult;
} }
/** /**

Loading…
Cancel
Save