天天看點

使用大華API擷取裝置線上狀态

作者:IT男的秘密
<icc.sdk.version>1.0.9</icc.sdk.version>
<dependency>
    <groupId>com.dahuatech.icc</groupId>
    <artifactId>java-sdk-oauth</artifactId>
      <version>${icc.sdk.version}</version>
</dependency>
<!-- ICC基礎資源SDK -->
<dependency>
    <groupId>com.dahuatech.icc</groupId>
    <artifactId>java-sdk-brm</artifactId>
    <version>${icc.sdk.version}</version>
</dependency>
<!-- ICC 事件中心sdk -->
<dependency>
    <groupId>com.dahuatech.icc</groupId>
    <artifactId>java-sdk-event</artifactId>
    <version>${icc.sdk.version}</version>
</dependency>           
@GetMapping("/newCk3/newCkzx")
@ResponseBody
public String newCkzx( String id,String zl,String org, ModelMap mmap)throws ClientException {
    JSONObject jsonObject1 =new JSONObject();
    log.info("----開始執行----{}------", "裝置查詢");
    IClient iClient = new DefaultClient();
    SubsystemRequest rtspUrlRequest = new SubsystemRequest(org, "1");//0離線  1線上
    SubsystemResponse response = iClient.doAction(rtspUrlRequest, rtspUrlRequest.getResponseClass());
    JSONObject jsonObject = JSON.parseObject(response.getResult());
    log.info("----結束執行{}", "擷取線上裝置資訊:"+jsonObject);
    log.info("----開始執行----{}------", "裝置查詢");
    IClient iClientLx = new DefaultClient();
    SubsystemRequest rtspUrlRequestLx = new SubsystemRequest(org, "0");//0離線  1線上
    SubsystemResponse responseLx = iClientLx.doAction(rtspUrlRequestLx, rtspUrlRequestLx.getResponseClass());
    JSONObject jsonObjectLx = JSON.parseObject(responseLx.getResult());
    jsonObject1.put("zx",jsonObject);
    jsonObject1.put("lx",jsonObjectLx);
    log.info("----結束執行{}", "擷取掉線裝置資訊:"+jsonObjectLx);
    return jsonObject1.toJSONString();
}           
public class SubsystemRequest extends AbstractIccRequest<SubsystemResponse> {
  /**
   * 碼流類型。
   *
   * <p>1-主碼流,2-輔碼流
   */
  private String streamType;
  /**
   * 通道編碼
   *
   * <p>例 1000150$7$0$0
   */
  private String channelId;

  public SubsystemRequest(String org, String streamType) throws ClientException {
    super(IccProfile.URL_SCHEME +"/evo-apigw/evo-brm/1.2.0/device/channel/subsystem/page", Method.POST);


    JSONObject jsonObject = new JSONObject();
    jsonObject.put("pageNum",1);
    jsonObject.put("pageSize",10);
    ArrayList arrayList = new ArrayList();
   if(StringUtils.isNotEmpty(org)){
     jsonObject.put("ownerCode",org);//所屬組織編碼
   }


    arrayList.add(1);//1 攝像頭
    jsonObject.put("unitTypeList",arrayList);
    jsonObject.put("isOnline",Integer.valueOf(streamType));//0離線  1線上
    jsonObject.put("includeSubOwnerCodeFlag",true);

    System.out.println("入參-----------------------------"+jsonObject.toJSONString());
    httpRequest.body(jsonObject.toJSONString());
  }

  @Override
  public Class<SubsystemResponse> getResponseClass() {
    return SubsystemResponse.class;
  }
}           

繼續閱讀