Browse Source

bug修复

xujuanning 3 months ago
parent
commit
40304d1054

+ 30 - 23
generationXK-service/src/main/java/com/gyee/generation/util/realtimesource/EdosUtil.java

@@ -13,8 +13,7 @@ import com.gyee.generation.model.vo.RealTimeParameterVo;
 import com.gyee.generation.util.realtimesource.timeseries.ErrorRequest;
 import com.gyee.generation.util.realtimesource.timeseries.JsonObjectHelper;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
+import org.springframework.http.*;
 import org.springframework.stereotype.Component;
 import org.springframework.web.client.HttpClientErrorException;
 import org.springframework.web.client.RestTemplate;
@@ -704,39 +703,47 @@ public class EdosUtil implements IEdosUtil {
     }
 
     @Override
-    public List<PointData> getRealData(String... pointids) throws Exception {
+//    public List<PointData> getRealData(String... pointids) throws Exception {
+    public List<PointData> getRealDataPost(List<String> pointids) throws Exception {
 
-
-        String pointIdString = StringUtil.join(pointids, ",");
-        Optional<String> keys = Optional.ofNullable(pointIdString);
-        String url = baseURL + "/latest?null=0";
-        if (pointIdString.startsWith("GF-")) {
-            url = baseURL2 + "/latest?null=0";
-        }
+//        String pointIdString = StringUtil.join(pointids, ",");
+//        Optional<String> keys = Optional.ofNullable(pointIdString);
+        String url = baseURL + "/latest";
+//        if (pointIdString.startsWith("GF-")) {
+//            url = baseURL2 + "/latest?null=0";
+//        }
         try {
-            if (keys.isPresent())
-                url = url + "&keys=" + keys.get();
-            else {
-                return ErrorRequest.RequestListError(pointids);
-            }
-            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+            HttpHeaders headers = new HttpHeaders();
+            headers.setContentType(MediaType.APPLICATION_JSON);
+
+            // 将请求体和头部信息整合到HttpEntity中
+            HttpEntity<List<String>> requestEntity = new HttpEntity<>(pointids,headers);
+
+            // 发起POST请求
+            ResponseEntity<JSONObject> resp = restTemplate.exchange(url,HttpMethod.POST,requestEntity,JSONObject.class);
+//            if (keys.isPresent())
+//                url = url + "&keys=" + keys.get();
+//            else {
+//                return ErrorRequest.RequestListError(pointids.toString());
+//            }
+//            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
             JSONObject jsonObject = resp.getBody();
             if (jsonObject != null) {
                 //对结果进行有序返回
-                int len = pointids.length;
+                int len = pointids.size();
                 List<PointData> result = new ArrayList<>();
                 HashMap<String, PointData> pointDataHashMap = new HashMap<>();
                 for (int i = 0; i < len; i++) {
 
-                    if (pointDataHashMap.containsKey(pointids[i]) == false) {
+                    if (pointDataHashMap.containsKey(pointids.get(i)) == false) {
                         PointData pd = new PointData();
-                        pd.setPointName(pointids[i]);
-                        pd.setEdnaId(pointids[i]);
+                        pd.setPointName(pointids.get(i));
+                        pd.setEdnaId(pointids.get(i));
                         result.add(pd);
 
                         pointDataHashMap.put(pd.getPointName(), pd);
                     } else {
-                        result.add(pointDataHashMap.get(pointids[i]));
+                        result.add(pointDataHashMap.get(pointids.get(i)));
                     }
 
                 }
@@ -779,13 +786,13 @@ public class EdosUtil implements IEdosUtil {
                 return result;
 
             } else {
-                return ErrorRequest.RequestListError(pointids);
+                return ErrorRequest.RequestListError(pointids.toString());
             }
 
         } catch (HttpClientErrorException exception) {
             if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
                 //System.out.println("404请求错误");
-                return ErrorRequest.RequestListError(pointids);
+                return ErrorRequest.RequestListError(pointids.toString());
             } else {
                 throw exception;
             }

+ 2 - 1
generationXK-service/src/main/java/com/gyee/generation/util/realtimesource/IEdosUtil.java

@@ -115,7 +115,8 @@ public interface IEdosUtil {
      * @return 列表集合
      * @throws Exception
      */
-    public List<PointData> getRealData(String... pointids) throws Exception;
+//    public List<PointData> getRealData(String... pointids) throws Exception;
+    public List<PointData> getRealDataPost(List<String> pointids) throws Exception;
 
     /**
      * 通过全局点名获得测点实时数据 读取多个点