|
|
@@ -1,6 +1,7 @@
|
|
|
package com.gyee.runeconomy.util.realtimesource;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.gyee.common.model.DNAStatVal;
|
|
|
@@ -18,6 +19,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.HttpClientErrorException;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
@@ -101,8 +103,8 @@ public class EdosUtil implements IEdosUtil {
|
|
|
|
|
|
List<String> ls = new ArrayList<>();
|
|
|
ls.add(point.getNemCode());
|
|
|
- HttpEntity<List<String>> requestEntity = new HttpEntity<>(ls,headers);
|
|
|
- ResponseEntity<JSONObject> resp = restTemplate.exchange(url,HttpMethod.POST,requestEntity,JSONObject.class);
|
|
|
+ HttpEntity<List<String>> requestEntity = new HttpEntity<>(ls, headers);
|
|
|
+ ResponseEntity<JSONObject> resp = restTemplate.exchange(url, HttpMethod.POST, requestEntity, JSONObject.class);
|
|
|
|
|
|
JSONObject jsonArray = resp.getBody();
|
|
|
if (StringUtils.isNotEmpty(jsonArray)) {
|
|
|
@@ -359,39 +361,39 @@ public class EdosUtil implements IEdosUtil {
|
|
|
|
|
|
@Override
|
|
|
public List<PointData> getHistoryDatasSnap(String pointid, Long beginDate, Long endDate, Integer pried) throws Exception {
|
|
|
- if (StringUtils.notEmp(pointid) && !initialcode.equals(pointid)) {
|
|
|
- Optional<String> tagName = Optional.ofNullable(pointid);
|
|
|
- Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
|
|
|
- Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
|
|
|
-
|
|
|
- //通过时间区间和时间间隔获取点数
|
|
|
- int finalInterval;
|
|
|
- if (pried != null)
|
|
|
- finalInterval = pried;
|
|
|
- else
|
|
|
- return ErrorRequest.RequestListError(pointid);
|
|
|
- Optional<Integer> interval = Optional.ofNullable(finalInterval);
|
|
|
+ if (StringUtils.notEmp(pointid) && !initialcode.equals(pointid)) {
|
|
|
+ Optional<String> tagName = Optional.ofNullable(pointid);
|
|
|
+ Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
|
|
|
+ Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
|
|
|
|
|
|
- try {
|
|
|
- String url = baseURL + "/history/snap?null=0";
|
|
|
- if (pointid.startsWith("GF-")) {
|
|
|
- url = baseURL2 + "/history/snap?null=0";
|
|
|
- }
|
|
|
- //tagName 或thingType,thingId,uniformCode可以确定一个标签点
|
|
|
- if (tagName.isPresent())
|
|
|
- url = url + "&tagName=" + tagName.get();
|
|
|
-
|
|
|
- if (startTs.isPresent())
|
|
|
- url = url + "&startTs=" + startTs.get();
|
|
|
- if (endTs.isPresent())
|
|
|
- url = url + "&endTs=" + endTs.get();
|
|
|
- if (interval.isPresent())
|
|
|
- url = url + "&interval=" + interval.get();
|
|
|
-
|
|
|
- ResponseEntity<JSONArray> resp = restTemplate.getForEntity(url, JSONArray.class);
|
|
|
- JSONArray jsonArray = resp.getBody();
|
|
|
- if (jsonArray != null) {
|
|
|
- List<PointData> list = JsonObjectHelper.phrasePointData(jsonArray, tagName.get());
|
|
|
+ //通过时间区间和时间间隔获取点数
|
|
|
+ int finalInterval;
|
|
|
+ if (pried != null)
|
|
|
+ finalInterval = pried;
|
|
|
+ else
|
|
|
+ return ErrorRequest.RequestListError(pointid);
|
|
|
+ Optional<Integer> interval = Optional.ofNullable(finalInterval);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String url = baseURL + "/history/snap?null=0";
|
|
|
+ if (pointid.startsWith("GF-")) {
|
|
|
+ url = baseURL2 + "/history/snap?null=0";
|
|
|
+ }
|
|
|
+ //tagName 或thingType,thingId,uniformCode可以确定一个标签点
|
|
|
+ if (tagName.isPresent())
|
|
|
+ url = url + "&tagName=" + tagName.get();
|
|
|
+
|
|
|
+ if (startTs.isPresent())
|
|
|
+ url = url + "&startTs=" + startTs.get();
|
|
|
+ if (endTs.isPresent())
|
|
|
+ url = url + "&endTs=" + endTs.get();
|
|
|
+ if (interval.isPresent())
|
|
|
+ url = url + "&interval=" + interval.get();
|
|
|
+
|
|
|
+ ResponseEntity<JSONArray> resp = restTemplate.getForEntity(url, JSONArray.class);
|
|
|
+ JSONArray jsonArray = resp.getBody();
|
|
|
+ if (jsonArray != null) {
|
|
|
+ List<PointData> list = JsonObjectHelper.phrasePointData(jsonArray, tagName.get());
|
|
|
// List<PointData> resultList = new ArrayList<>();
|
|
|
//
|
|
|
// if (list.isEmpty()) {
|
|
|
@@ -445,31 +447,31 @@ public class EdosUtil implements IEdosUtil {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- return list;
|
|
|
- } else {
|
|
|
- return ErrorRequest.RequestListError(pointid);
|
|
|
- }
|
|
|
+ return list;
|
|
|
+ } else {
|
|
|
+ return ErrorRequest.RequestListError(pointid);
|
|
|
+ }
|
|
|
|
|
|
- } catch (HttpClientErrorException exception) {
|
|
|
- if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
|
- //System.out.println("404请求错误");
|
|
|
- return ErrorRequest.RequestListError(pointid);
|
|
|
- } else {
|
|
|
- throw exception;
|
|
|
- }
|
|
|
+ } catch (HttpClientErrorException exception) {
|
|
|
+ if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
|
|
|
+ //System.out.println("404请求错误");
|
|
|
+ return ErrorRequest.RequestListError(pointid);
|
|
|
+ } else {
|
|
|
+ throw exception;
|
|
|
}
|
|
|
- } else {
|
|
|
- List<PointData> pols = new ArrayList<>();
|
|
|
- PointData po = new PointData();
|
|
|
- po.setEdnaId(pointid);
|
|
|
- po.setPointValueInDouble(0.0);
|
|
|
- po.setPointTime(0l);
|
|
|
- pols.add(po);
|
|
|
- return pols;
|
|
|
}
|
|
|
-
|
|
|
+ } else {
|
|
|
+ List<PointData> pols = new ArrayList<>();
|
|
|
+ PointData po = new PointData();
|
|
|
+ po.setEdnaId(pointid);
|
|
|
+ po.setPointValueInDouble(0.0);
|
|
|
+ po.setPointTime(0l);
|
|
|
+ pols.add(po);
|
|
|
+ return pols;
|
|
|
}
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void getHistsnapSameTiem(String pointid, Long beginDate, Long pried,
|
|
|
List<PointData> resultList) {
|
|
|
@@ -974,13 +976,13 @@ public class EdosUtil implements IEdosUtil {
|
|
|
|
|
|
// 将请求体和头部信息整合到HttpEntity中
|
|
|
// HttpEntity<List<String>> requestEntity = new HttpEntity<>(pointids,headers);
|
|
|
- HttpEntity<String> requestEntity = new HttpEntity<>(join,headers);
|
|
|
+ HttpEntity<String> requestEntity = new HttpEntity<>(join, headers);
|
|
|
|
|
|
// 发起POST请求
|
|
|
- ResponseEntity<JSONObject> resp = restTemplate.exchange(url,HttpMethod.POST,requestEntity,JSONObject.class);
|
|
|
+ ResponseEntity<JSONObject> resp = restTemplate.exchange(url, HttpMethod.POST, requestEntity, JSONObject.class);
|
|
|
JSONObject jsonObject = resp.getBody();
|
|
|
|
|
|
- if (jsonObject != null&&!jsonObject.isEmpty()) {
|
|
|
+ if (jsonObject != null && !jsonObject.isEmpty()) {
|
|
|
//对结果进行有序返回
|
|
|
int len = pointids.size();
|
|
|
List<PointData> result = new ArrayList<>();
|
|
|
@@ -1049,7 +1051,6 @@ public class EdosUtil implements IEdosUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
// @Override
|
|
|
// public List<PointData> getRealData(List<String> pointids) throws Exception {
|
|
|
//
|
|
|
@@ -2103,6 +2104,41 @@ public class EdosUtil implements IEdosUtil {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public List<PointData> getHistMatrixPost(List<String> nameList, long tTime) {
|
|
|
+ if (nameList == null || nameList.isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ String url = baseURL + "/history/section?ts=" + tTime * 1000;
|
|
|
+ String tagNamesString = String.join(",", nameList);
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ headers.set("Content-Type", "application/json;charset=UTF-8"); // 明确指定
|
|
|
+
|
|
|
+ HttpEntity<String> requestEntity = new HttpEntity<>(tagNamesString, headers);
|
|
|
+
|
|
|
+ ResponseEntity<String> response = restTemplate.exchange(
|
|
|
+ url,
|
|
|
+ HttpMethod.POST,
|
|
|
+ requestEntity,
|
|
|
+ String.class
|
|
|
+ );
|
|
|
+
|
|
|
+ if (response.getStatusCode().is2xxSuccessful() && response.hasBody()) {
|
|
|
+ String responseBody = response.getBody();
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSON.parseObject(responseBody);
|
|
|
+ return JsonObjectHelper.phrasePointData(jsonObject, nameList);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public PointData getHistMatrix(String id, long tTime) throws Exception {
|
|
|
|
|
|
if (StringUtils.notEmp(id) && !id.equals(initialcode)) {
|