|
|
@ -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,39 +17,33 @@ 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 { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 根据分页条件和测点名称测点描述模糊查询 |
|
|
|
* |
|
|
|
* @param reqVO 传入对象,页数、页数量、查询条件 |
|
|
|
* @return exa列表 |
|
|
|
*/ |
|
|
|
public List<EXAHttp> getPointInfo(String EXA_IP,EXAPageReqVO reqVO) throws URISyntaxException, IOException { |
|
|
|
public List<EXAHttp> getPointInfo(String EXA_IP, EXAPageReqVO reqVO) throws URISyntaxException, IOException { |
|
|
|
// PageResult<EXAHttp> result = new PageResult<>();
|
|
|
|
List<EXAHttp> exaListAll = new ArrayList<EXAHttp>(); |
|
|
|
try { |
|
|
|
// 目标 RPC 服务的 URL
|
|
|
|
String url = "http://"+EXA_IP+":9000/exawebapi/exaitem/getitems"; |
|
|
|
String url = "http://" + EXA_IP + ":9000/exawebapi/exaitem/getitems"; |
|
|
|
//创建HttpClient对象
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
/* |
|
|
@ -104,11 +104,11 @@ public class EXAUtils { |
|
|
|
* @return exa列表 |
|
|
|
*/ |
|
|
|
|
|
|
|
public List<String> getNowData(String EXA_IP,String itemNames) throws URISyntaxException, IOException { |
|
|
|
public List<String> getNowData(String EXA_IP, String itemNames) throws URISyntaxException, IOException { |
|
|
|
List<String> result = new ArrayList<>(); |
|
|
|
try { |
|
|
|
// 目标 RPC 服务的 URL
|
|
|
|
String url = "http://"+EXA_IP+":9000/exawebapi/exanow/getfloatvaluebatch"; |
|
|
|
String url = "http://" + EXA_IP + ":9000/exawebapi/exanow/getfloatvaluebatch"; |
|
|
|
//创建HttpClient对象
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
/* |
|
|
@ -154,65 +154,43 @@ 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()); |
|
|
|
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 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(); |
|
|
|
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); |
|
|
|
result = getHistory(EXA_IP, exaHistoryReqVo); |
|
|
|
results.add(result); |
|
|
|
}); |
|
|
|
} catch (Exception e) { |
|
|
@ -222,8 +200,8 @@ public class EXAUtils { |
|
|
|
} |
|
|
|
|
|
|
|
//写入点号
|
|
|
|
public String setPoint(String EXA_IP,Point point) throws IOException { |
|
|
|
String requestPathAddItem = "http://"+EXA_IP+":9000/exawebapi/exaitem/AddItem"; |
|
|
|
public String setPoint(String EXA_IP, Point point) throws IOException { |
|
|
|
String requestPathAddItem = "http://" + EXA_IP + ":9000/exawebapi/exaitem/AddItem"; |
|
|
|
String param = JSON.toJSONString(point); |
|
|
|
String result = Request.Post(requestPathAddItem) |
|
|
|
.addHeader("Content-type", "application/json") |
|
|
@ -240,7 +218,7 @@ public class EXAUtils { |
|
|
|
List<Object> result = new ArrayList<>(); |
|
|
|
try { |
|
|
|
// 目标 RPC 服务的 URL
|
|
|
|
String url = "http://"+EXA_IP+":9000/exawebapi/exagroup/getgroups"; |
|
|
|
String url = "http://" + EXA_IP + ":9000/exawebapi/exagroup/getgroups"; |
|
|
|
//创建HttpClient对象
|
|
|
|
CloseableHttpClient httpClient = HttpClients.createDefault(); |
|
|
|
/* |
|
|
@ -283,8 +261,8 @@ public class EXAUtils { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public String deletePoint(String EXA_IP,String ItemName){ |
|
|
|
String requestPathDeleteItem ="http://"+EXA_IP+":9000/exawebapi/exaitem/DeleteItem?ItemName="+ItemName; |
|
|
|
public String deletePoint(String EXA_IP, String ItemName) { |
|
|
|
String requestPathDeleteItem = "http://" + EXA_IP + ":9000/exawebapi/exaitem/DeleteItem?ItemName=" + ItemName; |
|
|
|
// 创建HttpClient
|
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) { |
|
|
|
// 创建HttpDelete请求
|
|
|
|