Http 数据查询API调用说明


在使用本功能前,请首先参考 调用方管理 创建调用方,调用方管理提供验证API接口的授权信息、调用量监控等相关功能!

  • 在已创建调用方和申请相应元素授权的情况下,再进行以下操作!
  • 范例代码请参考单元测试:com.dtstep.lighthouse.core.test.api.HttpDataQueryTest
  • Http接口服务地址为集群模式为每个lighthouse-ice服务部署地址(默认为集群每一台服务器),单机模式为当前节点地址。

按照批次时间查询单个维度的统计接口

接口地址:http://10.206.6.31:18101/api/rpc/v1/dataQuery

Header参数:

Caller-Name:调用方名称
Caller-Key:调用方秘钥

包体参数格式如下:

{"batchList":[1725498000000,1725494400000,1725490800000,1725487200000,1725483600000],"dimensValue":"山东省","statId":"1100607"}

Java模拟调用

public void testDataQuery() throws Exception {
        String apiUrl = "http://10.206.6.31:18101/api/rpc/v1/dataQuery";
        Map<String,Object> requestMap = new HashMap<>();
        requestMap.put("statId","1100607");
        List<Long> batchList = new ArrayList<>();
        batchList.add(DateUtil.parseDate("2024-09-05 09:00:00","yyyy-MM-dd HH:mm:ss"));
        batchList.add(DateUtil.parseDate("2024-09-05 08:00:00","yyyy-MM-dd HH:mm:ss"));
        batchList.add(DateUtil.parseDate("2024-09-05 07:00:00","yyyy-MM-dd HH:mm:ss"));
        batchList.add(DateUtil.parseDate("2024-09-05 06:00:00","yyyy-MM-dd HH:mm:ss"));
        batchList.add(DateUtil.parseDate("2024-09-05 05:00:00","yyyy-MM-dd HH:mm:ss"));
        requestMap.put("dimensValue","山东省");
        requestMap.put("batchList",batchList);
        String requestParams = JsonUtil.toJSONString(requestMap);
        System.out.println("Body Params:" + JsonUtil.toJSONString(requestParams));
        RequestBody body = RequestBody.create(MediaType.parse("application/json"),requestParams);
        Request request = new Request.Builder()
                .header("Caller-Name",callerName)
                .header("Caller-Key",callerKey)
                .url(apiUrl)
                .post(body)
                .build();
        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            System.out.println(response.body().string()) ;
        }
    }

按照时间范围查询单个维度的统计结果

接口地址:http://10.206.6.31:18101/api/rpc/v1/dataDurationQuery

Header参数:

Caller-Name:调用方名称
Caller-Key:调用方秘钥

包体参数格式如下:

{"dimensValue":"山东省","endTime":1729439999999,"startTime":1729353600000,"statId":"1100607"}

Java模拟调用

public void testDataDurationQuery() throws Exception {
        String apiUrl = "http://10.206.6.31:18101/api/rpc/v1/dataDurationQuery";
        Map<String,Object> requestMap = new HashMap<>();
        requestMap.put("statId","1100607");
        requestMap.put("startTime", DateUtil.getDayStartTime(System.currentTimeMillis()));
        requestMap.put("endTime", DateUtil.getDayEndTime(System.currentTimeMillis()));
        requestMap.put("dimensValue","山东省");
        String requestParams = JsonUtil.toJSONString(requestMap);
        System.out.println("Body Params:" + JsonUtil.toJSONString(requestParams));
        RequestBody body = RequestBody.create(MediaType.parse("application/json"),requestParams);
        Request request = new Request.Builder()
                .header("Caller-Name",callerName)
                .header("Caller-Key",callerKey)
                .url(apiUrl)
                .post(body)
                .build();
        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            System.out.println(response.body().string()) ;
        }
    }

按照批次时间批量查询多个维度的统计结果

接口地址:http://10.206.6.31:18101/api/rpc/v1/dataQueryWithDimensList

Header参数:

Caller-Name:调用方名称
Caller-Key:调用方秘钥

包体参数格式如下:

{"batchList":[1725498000000,1725494400000,1725490800000,1725487200000,1725483600000],"dimensValueList2":["21","72","36"],"statId":"1100613"}

Java模拟调用

public void testDataQueryWithDimensList() throws Exception {
        String apiUrl = "http://10.206.6.31:18101/api/rpc/v1/dataQueryWithDimensList";
        Map<String,Object> requestMap = new HashMap<>();
        requestMap.put("statId","1100613");
        List<String> list = List.of("21","72","36");
        requestMap.put("dimensValueList",list);
        List<Long> batchList = new ArrayList<>();
        batchList.add(DateUtil.parseDate("2024-09-05 09:00:00","yyyy-MM-dd HH:mm:ss"));
        batchList.add(DateUtil.parseDate("2024-09-05 08:00:00","yyyy-MM-dd HH:mm:ss"));
        batchList.add(DateUtil.parseDate("2024-09-05 07:00:00","yyyy-MM-dd HH:mm:ss"));
        batchList.add(DateUtil.parseDate("2024-09-05 06:00:00","yyyy-MM-dd HH:mm:ss"));
        batchList.add(DateUtil.parseDate("2024-09-05 05:00:00","yyyy-MM-dd HH:mm:ss"));
        requestMap.put("batchList",batchList);
        String requestParams = JsonUtil.toJSONString(requestMap);
        System.out.println("requestParams:" + JsonUtil.toJSONString(requestParams));
        RequestBody body = RequestBody.create(MediaType.parse("application/json"),requestParams);
        Request request = new Request.Builder()
                .header("Caller-Name",callerName)
                .header("Caller-Key",callerKey)
                .url(apiUrl)
                .post(body)
                .build();
        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            System.out.println(response.body().string()) ;
        }
    }

按照时间范围批量查询多个维度的统计结果

接口地址:http://10.206.6.31:18101/api/rpc/v1/dataDurationQueryWithDimensList

Header参数:

Caller-Name:调用方名称
Caller-Key:调用方秘钥

包体参数格式如下:

{"dimensValueList":["21","72","36"],"endTime":1729439999999,"startTime":1729353600000,"statId":"1100613"}
@Test
    public void testDataDurationQueryWithDimensList() throws Exception {
        String apiUrl = "http://10.206.6.31:18101/api/rpc/v1/dataDurationQueryWithDimensList";
        Map<String,Object> requestMap = new HashMap<>();
        requestMap.put("statId","1100613");
        List<String> list = List.of("21","72","36");
        requestMap.put("dimensValueList",list);
        requestMap.put("startTime", DateUtil.getDayStartTime(System.currentTimeMillis()));
        requestMap.put("endTime", DateUtil.getDayEndTime(System.currentTimeMillis()));
        String requestParams = JsonUtil.toJSONString(requestMap);
        System.out.println("requestParams:" + JsonUtil.toJSONString(requestParams));
        RequestBody body = RequestBody.create(MediaType.parse("application/json"),requestParams);
        Request request = new Request.Builder()
                .header("Caller-Name",callerName)
                .header("Caller-Key",callerKey)
                .url(apiUrl)
                .post(body)
                .build();
        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            System.out.println(response.body().string()) ;
        }
    }

按照批次时间查询Limit统计结果

接口地址:http://10.206.6.31:18101/api/rpc/v1/limitQuery

Header参数:

Caller-Name:调用方名称
Caller-Key:调用方秘钥

包体参数格式如下:

{"batchTime":1729415100000,"statId":"1100617"}
public void testLimitQuery() throws Exception{
        String apiUrl = "http://10.206.6.31:18101/api/rpc/v1/limitQuery";
        Map<String,Object> requestMap = new HashMap<>();
        requestMap.put("statId","1100617");
        long batchTime = DateUtil.batchTime(5, TimeUnit.MINUTES,DateUtil.getMinuteBefore(System.currentTimeMillis(),5));
        System.out.println("batchTime:" + DateUtil.formatTimeStamp(batchTime,"yyyy-MM-dd HH:mm:ss"));
        requestMap.put("batchTime", batchTime);
        String requestParams = JsonUtil.toJSONString(requestMap);
        System.out.println("requestParams:" + JsonUtil.toJSONString(requestParams));
        RequestBody body = RequestBody.create(MediaType.parse("application/json"),requestParams);
        Request request = new Request.Builder()
                .header("Caller-Name",callerName)
                .header("Caller-Key",callerKey)
                .url(apiUrl)
                .post(body)
                .build();
        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("Unexpected code " + response);
            }
            System.out.println(response.body().string()) ;
        }
    }

results matching ""

    No results matching ""