|
|
|
@ -1,5 +1,9 @@ |
|
|
|
package cn.iocoder.yudao.module.alert.utils; |
|
|
|
|
|
|
|
import cn.hutool.core.lang.TypeReference; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.*; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
@ -24,9 +28,7 @@ import java.io.IOException; |
|
|
|
import java.lang.reflect.Type; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.nio.charset.Charset; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
public class EXAUtils { |
|
|
|
|
|
|
|
@ -177,57 +179,45 @@ public class EXAUtils { |
|
|
|
* @param exaHistoryReqVo 传入对象,点号、开始时间、结束时间 |
|
|
|
* @return exa列表 |
|
|
|
*/ |
|
|
|
public List<List<Double>> getHistory(String EXA_IP, EXAHistoryReqVO exaHistoryReqVo) { |
|
|
|
List<List<Double>> result = new ArrayList<>(); |
|
|
|
public List<List<Double>> getHistory(String exaIp, EXAHistoryReqVO req) { |
|
|
|
List<List<Double>> result = Collections.emptyList(); |
|
|
|
|
|
|
|
try { |
|
|
|
// 目标 RPC 服务的 URL
|
|
|
|
// String url = "http://"+EXA_IP+":9000/exawebapi/exatime/GetRawValueArrayFloat";
|
|
|
|
String url = "http://" + EXA_IP + ":9000/exawebapi/exatime/GetSamplingValueArrayFloat"; |
|
|
|
String url = String.format( |
|
|
|
"http://%s:9000/exawebapi/EXATime/GetSamplingValueArrayFloat", |
|
|
|
exaIp |
|
|
|
); |
|
|
|
|
|
|
|
// 拼接参数
|
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("ItemName", req.getItemName()); |
|
|
|
paramMap.put("StartingTime", req.getStartTime()); |
|
|
|
paramMap.put("TerminalTime", req.getEndTime()); |
|
|
|
paramMap.put("SamplingPeriod", 1000 * req.getInterval()); |
|
|
|
|
|
|
|
// 发送 GET 请求
|
|
|
|
String body = HttpUtil.createGet(url) |
|
|
|
.form(paramMap) |
|
|
|
.header("Content-Type", "application/json") |
|
|
|
.timeout(5000) |
|
|
|
.execute() |
|
|
|
.body(); |
|
|
|
|
|
|
|
System.out.println("服务端返回的数据为:" + body); |
|
|
|
|
|
|
|
//创建HttpClient对象
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
/* |
|
|
|
* 由于GET请求的参数都是拼装在URL地址后方,所以我们要构建一个URL,带参数 |
|
|
|
*/ |
|
|
|
URIBuilder uriBuilder = new URIBuilder(url); |
|
|
|
// 处理转义字符 \\
|
|
|
|
body = StrUtil.replace(body, "\\", ""); |
|
|
|
|
|
|
|
/** 添加参数 */ |
|
|
|
uriBuilder.addParameter("ItemName", exaHistoryReqVo.getItemName()); |
|
|
|
uriBuilder.addParameter("StartingTime", exaHistoryReqVo.getStartTime()); |
|
|
|
uriBuilder.addParameter("TerminalTime", exaHistoryReqVo.getEndTime()); |
|
|
|
uriBuilder.addParameter("SamplingPeriod", String.valueOf(1000 * exaHistoryReqVo.getInterval())); |
|
|
|
// 去除首尾双引号
|
|
|
|
body = StrUtil.unWrap(body, '\"'); |
|
|
|
|
|
|
|
// 反序列化
|
|
|
|
result = JSONUtil.toBean(body, new TypeReference<List<List<Double>>>() {}, true); |
|
|
|
|
|
|
|
//创建请求对象
|
|
|
|
HttpGet httpGet = new HttpGet(uriBuilder.build()); |
|
|
|
|
|
|
|
// 传输的类型
|
|
|
|
httpGet.addHeader("Content-Type", "application/json"); |
|
|
|
//发送请求,请求响应结果
|
|
|
|
CloseableHttpResponse response = httpClient.execute(httpGet); |
|
|
|
//获取服务器返回的状态码
|
|
|
|
int statusCode = response.getStatusLine().getStatusCode(); |
|
|
|
System.out.println("服务端返回成功的状态码为:" + statusCode); |
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
String body = EntityUtils.toString(entity).replaceAll("\\\\", ""); |
|
|
|
System.out.println("服务端返回的数据为:" + body); |
|
|
|
|
|
|
|
if (body.startsWith("\"") && body.endsWith("\"")) { |
|
|
|
// 步骤3:去掉双引号
|
|
|
|
body = body.substring(1, body.length() - 1); // 去掉首尾的双引号
|
|
|
|
} |
|
|
|
Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create(); |
|
|
|
Type listType = new TypeToken<List<List<Double>>>() { |
|
|
|
}.getType(); |
|
|
|
result = gson.fromJson(body, listType); |
|
|
|
|
|
|
|
//关闭资源
|
|
|
|
response.close(); |
|
|
|
httpClient.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
System.err.println("请求历史数据失败:" + e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
|