package com.iailab.sdk.demo; import com.iailab.sdk.auth.client.IailabAuthClient; import com.iailab.sdk.auth.client.dto.ApiDataQueryDTO; import com.iailab.sdk.auth.client.dto.TokenDTO; import org.springframework.web.bind.annotation.RestController; import java.text.SimpleDateFormat; import java.util.*; /** * @author iailab */ @RestController public class HttpClientDemo { /** * 获取平台授权token及refreshToken */ public void authenticate() { TokenDTO authenticate = IailabAuthClient.authenticate(); System.out.println(authenticate); } /** * 根据refreshToken刷新授权token * @throws Exception */ public void refreshToken() throws Exception { IailabAuthClient.authenticate(); TokenDTO authenticate = IailabAuthClient.refreshToken(); System.out.println(authenticate); } public Map queryPointsRealValue() throws Exception { List pointNos = new ArrayList<>(); pointNos.add("111"); return IailabAuthClient.getInstance().queryPointsRealValue(pointNos); } public Map queryPlanChart() throws Exception { ApiDataQueryDTO apiDataQueryDTO = new ApiDataQueryDTO(); List 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 */ public void doHttpPost() throws Exception { Map params = new HashMap<>(); List itemNos = new ArrayList<>(); params.put("start", "2024-06-11 07:24:00"); params.put("end", "2024-06-13 00:00:00"); params.put("itemNo", null); params.put("granularity", null); itemNos.add("P0000100010"); params.put("itemNos", itemNos); String s = IailabAuthClient.doHttp("POST", "http://172.16.8.100/admin-api/data/api/query-plans/chart", params); System.out.println(s); } /** * 测试doHttp get请求 * @throws Exception */ public void doHttpGet() throws Exception { Map params = new HashMap<>(); params.put("pointNos", "M0000101158,M0000101157,M0000101156,M0000101155,F0000120026"); String s = IailabAuthClient.doHttp("get", "http://172.16.8.100/admin-api/data/api/device-value", params); System.out.println(s); } }