com.dahuatech.icc.multiinone.admin.OperateDirectSDK Maven / Gradle / Ivy
The newest version!
package com.dahuatech.icc.multiinone.admin;
import com.dahuatech.hutool.http.Method;
import com.dahuatech.hutool.json.JSONObject;
import com.dahuatech.hutool.log.Log;
import com.dahuatech.hutool.log.LogFactory;
import com.dahuatech.icc.exception.ClientException;
import com.dahuatech.icc.multiinone.Constants;
import com.dahuatech.icc.multiinone.admin.constant.AdminConstant;
import com.dahuatech.icc.multiinone.admin.vo.OperateDirectRequest;
import com.dahuatech.icc.multiinone.admin.vo.OperateDirectResponse;
import com.dahuatech.icc.oauth.exception.BusinessException;
import com.dahuatech.icc.oauth.http.IClient;
import com.dahuatech.icc.oauth.http.IccClient;
import com.dahuatech.icc.oauth.model.v202010.GeneralRequest;
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigBaseInfo;
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
/**
* program:java-sdk
*
* Author: 312013
* Date:2022-08-11 10:06
* Description: 云台控制封装开启与停止操作
*/
public class OperateDirectSDK {
private final Log logger = LogFactory.get();
/**
* 开启云台SDK,在200ms后自动关闭云台,防止云台一直处于开启状态
* **/
public OperateDirectResponse operateDirect(OperateDirectRequest request){
logger.info("OperateDirectSDK,operateDirect,param:{}",new JSONObject(request).toJSONString(0));
OperateDirectResponse operateDirectResponse = null;
GeneralResponse generalResponse = null;
try{
//参数校验
request.baseCheck();
request.businessValid();
}catch (BusinessException businessException){
operateDirectResponse = new OperateDirectResponse();
operateDirectResponse.setErrMsg(businessException.getErrorMsg());
operateDirectResponse.setArgs(businessException.getArgs());
operateDirectResponse.setSuccess(false);
operateDirectResponse.setCode(businessException.getCode());
return operateDirectResponse;
}
//调用云台控制开启云台
try{
IClient iccClient = new IccClient(request.getOauthConfigBaseInfo());
String url = AdminConstant.OPERATE_DIRECT_START_CLOSE;
GeneralRequest generalRequest = new GeneralRequest(request.getOauthConfigBaseInfo().getHttpConfigInfo(),url, Method.POST);
JSONObject jsonObject = new JSONObject();
jsonObject.put("data",request.getData());
generalRequest.setBody(jsonObject.toString());
generalResponse = iccClient.doAction(generalRequest,generalRequest.getResponseClass());
}catch (Exception e){
logger.error("Failed to open cloud platform.");
operateDirectResponse = new OperateDirectResponse();
operateDirectResponse.setCode(generalResponse.getCode());
operateDirectResponse.setErrMsg(generalResponse.getErrMsg());
operateDirectResponse.setSuccess(false);
operateDirectResponse.setArgs(null);
return operateDirectResponse;
}
if(!"1000".equals(generalResponse.getCode())){
logger.error("Failed to open cloud platform.");
operateDirectResponse = new OperateDirectResponse();
operateDirectResponse.setCode(generalResponse.getCode());
operateDirectResponse.setErrMsg(generalResponse.getErrMsg());
operateDirectResponse.setSuccess(false);
operateDirectResponse.setArgs(null);
return operateDirectResponse;
}
//若为开启云台命令,200ms后调用云台控制关闭云台
String command = request.getData().getCommand();
if(command != null && ("1").equals(command)) {
try{
Thread.sleep(200);
}catch (Exception e){
logger.info("Execute sleep function to sleep 200 millis occured a Exception.");
e.printStackTrace();
}
//关闭云台
try{
IClient iccClient = new IccClient(request.getOauthConfigBaseInfo());
String url = AdminConstant.OPERATE_DIRECT_START_CLOSE;
request.getData().setCommand("0");//关闭
GeneralRequest generalRequest = new GeneralRequest(request.getOauthConfigBaseInfo().getHttpConfigInfo(),url, Method.POST);
JSONObject jsonObject = new JSONObject();
jsonObject.put("data",request.getData());
generalRequest.setBody(jsonObject.toString());
generalResponse = iccClient.doAction(generalRequest,generalRequest.getResponseClass());
}catch (Exception e){
logger.error("Failed to close cloud platform.");
operateDirectResponse = new OperateDirectResponse();
operateDirectResponse.setCode(generalResponse.getCode());
operateDirectResponse.setErrMsg(generalResponse.getErrMsg());
operateDirectResponse.setSuccess(false);
operateDirectResponse.setArgs(null);
return operateDirectResponse;
}
}
return operateDirectResponse;
}
}