| | |
| | | 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 com.iailab.sdk.auth.client.common.pojo.CommonResult; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | | * @author iailab |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/demo") |
| | | 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<String, Object> queryPointsRealValue() throws Exception { |
| | | List<String> pointNos = new ArrayList<>(); |
| | | pointNos.add("111"); |
| | | @PostMapping("/query-points/history-value") |
| | | public CommonResult<Map<String, Object>> queryPointsRealValue(@RequestBody List<String> pointNos) { |
| | | 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 |
| | | */ |
| | | public void doHttpPost() throws Exception { |
| | | Map<String, Object> params = new HashMap<>(); |
| | | List<String> 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<String, Object> 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); |
| | | } |
| | | } |