| | |
| | | package com.iailab.sdk.demo; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.iailab.sdk.auth.client.IailabAuthClient; |
| | | import com.iailab.sdk.auth.client.dto.ApiDataQueryDTO; |
| | | import com.iailab.sdk.auth.client.dto.TokenDTO; |
| | | import com.iailab.sdk.demo.dto.ApiDataQueryDTO; |
| | | import com.iailab.sdk.util.http.IailabHttpUtils; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | |
| | | @RestController |
| | | public class HttpClientDemo { |
| | | |
| | | @Value("${iailab.token.base-url}") |
| | | private String baseUrl; |
| | | |
| | | @Value("${iailab.api.user-simple-list}") |
| | | private String userSimpleList; |
| | | |
| | | @Value("${iailab.api.query-plans-chart}") |
| | | private String queryPlansChart; |
| | | |
| | | @Value("${iailab.api.device-value}") |
| | | private String deviceValue; |
| | | |
| | | /** |
| | | * 无参get请求测试 |
| | | * @throws Exception |
| | | */ |
| | | public void HttpGet() throws Exception { |
| | | String s = IailabHttpUtils.doGet(baseUrl + userSimpleList, null, "utf-8"); |
| | | System.out.println(s); |
| | | } |
| | | |
| | | public void HttpPost() throws Exception { |
| | | ApiDataQueryDTO apiDataQueryDTO = new ApiDataQueryDTO(); |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | List<String> itemNos = new ArrayList<>(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | apiDataQueryDTO.setStart(sdf.parse("2024-06-11 07:24:00")); |
| | | apiDataQueryDTO.setEnd(sdf.parse("2024-06-13 00:00:00")); |
| | | itemNos.add("P0000100010"); |
| | | apiDataQueryDTO.setItemNos(itemNos); |
| | | String jsonString = objectMapper.writeValueAsString(apiDataQueryDTO); |
| | | String s = IailabHttpUtils.doPost(baseUrl + queryPlansChart, jsonString, "utf-8"); |
| | | System.out.println(s); |
| | | } |
| | | |
| | | public void HttpGetDeviceValue() throws Exception { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("pointNos", "M0000101158,M0000101157,M0000101156,M0000101155,F0000120026"); |
| | | String s = IailabHttpUtils.doGet(baseUrl + deviceValue, params, "utf-8"); |
| | | System.out.println(s); |
| | | } |
| | | |
| | | /** |
| | | * 获取平台授权token及refreshToken |
| | |
| | | System.out.println(authenticate); |
| | | } |
| | | |
| | | |
| | | public Map<String, Object> queryPointsRealValue() throws Exception { |
| | | List<String> pointNos = new ArrayList<>(); |
| | | pointNos.add("111"); |
| | | return IailabAuthClient.getInstance().queryPointsRealValue(pointNos); |
| | | } |
| | | |
| | | public Map<String, Object> queryPlanChart() throws Exception { |
| | | ApiDataQueryDTO apiDataQueryDTO = new ApiDataQueryDTO(); |
| | | List<String> itemNos = new ArrayList<>(); |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | apiDataQueryDTO.setStart(sdf.parse("2024-06-11 07:24:00")); |
| | | apiDataQueryDTO.setEnd(sdf.parse("2024-06-13 00:00:00")); |
| | | itemNos.add("P0000100010"); |
| | | apiDataQueryDTO.setItemNos(itemNos); |
| | | return IailabAuthClient.getInstance().queryPlanChart(apiDataQueryDTO); |
| | | } |
| | | |
| | | /** |
| | | * 测试doHttp post请求 |
| | | * @throws Exception |
| | |
| | | params.put("granularity", null); |
| | | itemNos.add("P0000100010"); |
| | | params.put("itemNos", itemNos); |
| | | String s = IailabAuthClient.doHttp("POST", baseUrl + queryPlansChart, params); |
| | | String s = IailabAuthClient.doHttp("POST", "http://172.16.8.100/admin-api/data/api/query-plans/chart", params); |
| | | System.out.println(s); |
| | | } |
| | | |
| | |
| | | public void doHttpGet() throws Exception { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("pointNos", "M0000101158,M0000101157,M0000101156,M0000101155,F0000120026"); |
| | | String s = IailabAuthClient.doHttp("get", baseUrl + deviceValue, params); |
| | | String s = IailabAuthClient.doHttp("get", "http://172.16.8.100/admin-api/data/api/device-value", params); |
| | | System.out.println(s); |
| | | } |
| | | } |