|
|
@ -1,8 +1,14 @@ |
|
|
|
package cn.iocoder.yudao.module.alert.utils; |
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.*; |
|
|
|
import cn.hutool.http.HttpUtil; |
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAHistoryReqVO; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAHttp; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.EXAPageReqVO; |
|
|
|
import cn.iocoder.yudao.module.alert.controller.admin.exa.vo.Point; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.fasterxml.jackson.core.type.TypeReference; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.google.gson.GsonBuilder; |
|
|
|
import com.google.gson.reflect.TypeToken; |
|
|
@ -11,27 +17,21 @@ import org.apache.http.client.fluent.Request; |
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
import org.apache.http.client.methods.HttpDelete; |
|
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
import org.apache.http.client.utils.URIBuilder; |
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
import org.apache.http.entity.StringEntity; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
|
import org.apache.http.util.EntityUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
|
|
|
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 { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 根据分页条件和测点名称测点描述模糊查询 |
|
|
|
* |
|
|
@ -154,63 +154,41 @@ public class EXAUtils { |
|
|
|
* @param exaHistoryReqVo 传入对象,点号、开始时间、结束时间 |
|
|
|
* @return exa列表 |
|
|
|
*/ |
|
|
|
public List<String> getHistory(String EXA_IP,EXAHistoryReqVO exaHistoryReqVo) { |
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
public List<List<Double>> getHistory(String EXA_IP, EXAHistoryReqVO exaHistoryReqVo) { |
|
|
|
List<List<Double>> result = new ArrayList<>(); |
|
|
|
try { |
|
|
|
// 目标 RPC 服务的 URL
|
|
|
|
String url = "http://"+EXA_IP+":9000/exawebapi/exatime/GetRawValueArrayFloat"; |
|
|
|
//创建HttpClient对象
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
/* |
|
|
|
* 由于GET请求的参数都是拼装在URL地址后方,所以我们要构建一个URL,带参数 |
|
|
|
*/ |
|
|
|
URIBuilder uriBuilder = new URIBuilder(url); |
|
|
|
String url = "http://" + EXA_IP + ":9000/exawebapi/exatime/GetSamplingValueArrayFloat"; |
|
|
|
|
|
|
|
/** 添加参数 */ |
|
|
|
uriBuilder.addParameter("ItemName", exaHistoryReqVo.getItemName()); |
|
|
|
uriBuilder.addParameter("StartingTime", exaHistoryReqVo.getStartTime()); |
|
|
|
uriBuilder.addParameter("TerminalTime", exaHistoryReqVo.getEndTime()); |
|
|
|
|
|
|
|
//创建请求对象
|
|
|
|
HttpGet httpGet = new HttpGet(uriBuilder.build()); |
|
|
|
Map<String,Object> params=new HashMap<>(); |
|
|
|
params.put("ItemName", exaHistoryReqVo.getItemName()); |
|
|
|
params.put("StartingTime", exaHistoryReqVo.getStartTime()); |
|
|
|
params.put("TerminalTime", exaHistoryReqVo.getEndTime()); |
|
|
|
params.put("SamplingPeriod", exaHistoryReqVo.getInterval() * 1000); |
|
|
|
String body = HttpUtil.createGet(url).form(params) |
|
|
|
.header("Content-Type", "application/json") |
|
|
|
.execute().body(); |
|
|
|
|
|
|
|
// 传输的类型
|
|
|
|
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(); |
|
|
|
result = JsonUtils.parseObject(body, new TypeReference<List<List<Double>>>(){}); |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public List<List<String>> getHistorys(String EXA_IP,EXAHistoryReqVO exaHistoryReqVo) { |
|
|
|
List<List<String>> results = new ArrayList<>(); |
|
|
|
public List<List<List<Double>>> getHistorys(String EXA_IP, EXAHistoryReqVO exaHistoryReqVo) { |
|
|
|
List<List<List<Double>>> results = new ArrayList<>(); |
|
|
|
|
|
|
|
try { |
|
|
|
String itemNames = exaHistoryReqVo.getItemName(); |
|
|
|
List<String> pointName = Arrays.asList(itemNames.split(",")); |
|
|
|
pointName.forEach(entity -> { |
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
List<List<Double>> result = new ArrayList<>(); |
|
|
|
exaHistoryReqVo.setItemName(entity); |
|
|
|
result = getHistory(EXA_IP, exaHistoryReqVo); |
|
|
|
results.add(result); |
|
|
|