xieshengjie 3 سال پیش
والد
کامیت
ad58e26973

+ 3 - 0
realtime/generation-service/src/main/java/com/gyee/generation/service/StatusService.java

@@ -41,6 +41,8 @@ public class StatusService {
     public static Map<String,List<Windturbine>> linewtmap;
     @Resource
     private IEdosUtil edosUtil;
+    @Resource
+    private IEdosUtil edosUtilTd;
     @Value("${clauStatus.ai}")
     private String clauStatusAi;
     @Value("${clauStatus.di}")
@@ -225,6 +227,7 @@ public class StatusService {
                 }
             });
         });
+//        edosUtilTd.sendMultiPoint(resultList);
         edosUtil.sendMultiPoint(resultList);
     }
 

+ 1316 - 0
realtime/generation-service/src/main/java/com/gyee/generation/util/realtimesource/EdosUtilTd.java

@@ -0,0 +1,1316 @@
+package com.gyee.generation.util.realtimesource;
+
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.gyee.common.model.DNAStatVal;
+import com.gyee.common.model.DNAVal;
+import com.gyee.common.model.PointData;
+import com.gyee.common.model.StringUtils;
+import com.gyee.generation.model.auto.Windpowerstationpointnew;
+import com.gyee.generation.model.auto.Windturbinetestingpointnew;
+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.stereotype.Component;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.*;
+
+/**
+ */
+@Component
+public class EdosUtilTd implements IEdosUtil {
+
+    private RestTemplate restTemplate =new RestTemplate();
+    @Value("${td.url}")
+    private String baseURL;
+    @Override
+    public PointData getRealData(Windpowerstationpointnew point) throws Exception {
+        try {
+            Optional<String> keys = Optional.ofNullable(point.getCode());
+            Optional<String> thingType = Optional.ofNullable("station");
+            Optional<String> thingId = Optional.ofNullable(point.getWindpowerstationid());
+            Optional<String> uniformCodes = Optional.ofNullable(point.getUniformcode());
+
+            String url = baseURL + "/latest?null=0";
+            if (keys.isPresent())
+                url = url + "&keys=" + keys.get();
+            if (thingType.isPresent())
+                url = url + "&thingType=" + thingType.get();
+            if (thingId.isPresent())
+                url = url + "&thingId=" + thingId.get();
+            if (uniformCodes.isPresent())
+                url = url + "&uniformCodes=" + uniformCodes.get();
+
+            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+            JSONObject jsonArray = resp.getBody();
+             if (StringUtils.isNotEmpty(jsonArray)){
+                List<PointData> list = JsonObjectHelper.phrasePointData(jsonArray);
+                if (list.size() > 0)
+                    return list.get(0);
+                else
+                    return ErrorRequest.RequestError(point.getCode());
+            } else {
+                return ErrorRequest.RequestError(point.getCode());
+            }
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestError(point.getCode());
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public PointData getSectionData(String point, Long date) throws Exception {
+        String rawUrl = baseURL + "/history/section?null=0&tagNames=" + point + "&ts=" + date;
+
+        ResponseEntity<JSONObject> resp = restTemplate.getForEntity(rawUrl, JSONObject.class);
+        JSONObject jsonArray = resp.getBody();
+        if (StringUtils.isNotEmpty(jsonArray)){
+            List<PointData> list = JsonObjectHelper.phrasePointData(jsonArray);
+            if (list.size() > 0)
+                return list.get(0);
+            else
+                return ErrorRequest.RequestError(point);
+        } else {
+            return ErrorRequest.RequestError(point);
+        }
+    }
+
+    @Override
+    public PointData getSectionData(Windpowerstationpointnew point, Long date) throws Exception {
+        String rawUrl = baseURL + "/history/section?null=0&tagNames=" + point.getCode() + "&ts=" + date;
+
+        ResponseEntity<JSONObject> resp = restTemplate.getForEntity(rawUrl, JSONObject.class);
+        JSONObject jsonArray = resp.getBody();
+        if (StringUtils.isNotEmpty(jsonArray)){
+            List<PointData> list = JsonObjectHelper.phrasePointData(jsonArray);
+            if (list.size() > 0)
+                return list.get(0);
+            else
+                return ErrorRequest.RequestError(point.getCode());
+        } else {
+            return ErrorRequest.RequestError(point.getCode());
+        }
+    }
+
+    @Override
+    public PointData getSectionData(Windturbinetestingpointnew point, Long date) throws Exception {
+        String rawUrl = baseURL + "/history/section?null=0&tagNames=" + point.getCode() + "&ts=" + date;
+
+        ResponseEntity<JSONObject> resp = restTemplate.getForEntity(rawUrl, JSONObject.class);
+        JSONObject jsonArray = resp.getBody();
+        if (StringUtils.isNotEmpty(jsonArray)){
+            List<PointData> list = JsonObjectHelper.phrasePointData(jsonArray);
+            if (list.size() > 0)
+                return list.get(0);
+            else
+                return ErrorRequest.RequestError(point.getCode());
+        } else {
+            return ErrorRequest.RequestError(point.getCode());
+        }
+    }
+
+
+    @Override
+    public List<PointData> getHistoryDatasSnap(Windpowerstationpointnew point, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+        Optional<String> tagName = Optional.ofNullable(point.getCode());
+        Optional<String> thingId = Optional.ofNullable(point.getWindpowerstationid());
+        Optional<String> thingType = Optional.ofNullable(point.getModelid());
+        Optional<String> uniformCode = Optional.ofNullable(point.getUniformcode());
+        Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
+        Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
+        //通过时间区间和时间间隔获取点数
+        Long finalInterval;
+        if (pried != null)
+            finalInterval = pried;
+        else if (count != null)
+            finalInterval = (endDate - beginDate) / count;
+        else
+            return ErrorRequest.RequestListError(point.getCode());
+        Optional<Integer> interval = Optional.ofNullable(Integer.parseInt(finalInterval.toString()));
+
+        try {
+            String url = baseURL + "/history/snap?null=0";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "&tagName=" + tagName.get();
+            else {
+                if (thingType.isPresent())
+                    url = url + "&thingType=" + thingType.get();
+                if (thingId.isPresent())
+                    url = url + "&thingId=" + thingId.get();
+                if (uniformCode.isPresent())
+                    url = url + "&uniformCodes=" + uniformCode.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> snapList = JsonObjectHelper.phrasePointData(jsonArray, point.getCode());
+                List<PointData> resultList = new ArrayList<>();
+
+                if(snapList.isEmpty())
+                {
+
+                	getHistsnapSameTiem(point.getCode(), beginDate, pried, resultList);
+                }else
+                {
+                	 for (PointData snapItem : snapList) {
+
+                         long subTime = snapItem.getPointTime() - pried;
+                         //查询时间区间的截面值(截面值为传入时间节点的上一个最近值,返回时间为值的真实时间),
+                         // 再进行比较,若截面值的时间戳在以快照时间节点前推一个单位的时间区间中,
+                         // 则代表该时间节点快照有效,否则为0
+                         String rawUrl = baseURL + "/history/section?null=0&tagNames=" + point.getCode() + "&ts=" + snapItem.getPointTime() + "000";
+                         ResponseEntity<JSONObject> sectionResp = restTemplate.getForEntity(rawUrl, JSONObject.class);
+                         JSONObject jsonObjectSection = sectionResp.getBody();
+
+                         if (jsonObjectSection != null) {
+                             List<PointData> sectionlist = JsonObjectHelper.phrasePointData(jsonObjectSection);
+                             if (sectionlist.size() > 0) {
+                                 if(sectionlist.get(0).getPointTime()>=subTime&&sectionlist.get(0).getPointTime()<=snapItem.getPointTime()){
+                                     resultList.add(snapItem);
+                                 }
+                                 else{
+                                     PointData data = new PointData();
+                                     data.setEdnaId(point.getCode());
+                                     data.setPointTime(snapItem.getPointTime());
+                                     data.setPointValue("0");
+                                     data.setPointName("1");
+                                     data.setPointValueInDouble(0.0);
+                                     resultList.add(data);
+                                 }
+                             } else {
+                                 PointData data = new PointData();
+                                 data.setEdnaId(point.getCode());
+                                 data.setPointTime(snapItem.getPointTime());
+                                 data.setPointValue("0");
+                                 data.setPointName("1");
+                                 data.setPointValueInDouble(0.0);
+                                 resultList.add(data);
+                             }
+                         } else {
+                             PointData data = new PointData();
+                             data.setEdnaId(point.getCode());
+                             data.setPointTime(snapItem.getPointTime());
+                             data.setPointValue("0");
+                             data.setPointName("1");
+                             data.setPointValueInDouble(0.0);
+                             resultList.add(data);
+                         }
+                     }
+                }
+
+
+                return resultList;
+
+
+            } else {
+                return ErrorRequest.RequestListError(point.getCode());
+            }
+
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestListError(point.getCode());
+            } else {
+                throw exception;
+            }
+        }
+
+    }
+
+
+	private void getHistsnapSameTiem(String pointid, Long beginDate, Long pried,
+			List<PointData> resultList) {
+		long subTime =beginDate - pried;
+		  String rawUrl = baseURL + "/history/section?null=0&tagNames=" + pointid + "&ts=" + beginDate + "000";
+		  ResponseEntity<JSONObject> sectionResp = restTemplate.getForEntity(rawUrl, JSONObject.class);
+		  JSONObject jsonObjectSection = sectionResp.getBody();
+		  if (jsonObjectSection != null) {
+		      List<PointData> sectionlist = JsonObjectHelper.phrasePointData(jsonObjectSection);
+		      if (sectionlist.size() > 0) {
+		          if(sectionlist.get(0).getPointTime()>=subTime&&sectionlist.get(0).getPointTime()<=beginDate){
+		              resultList.add(sectionlist.get(0));
+		          }
+		          else{
+		              PointData data = new PointData();
+		              data.setEdnaId(pointid);
+		              data.setPointTime(sectionlist.get(0).getPointTime());
+		              data.setPointValue("0");
+		              data.setPointName("1");
+		              data.setPointValueInDouble(0.0);
+		              resultList.add(data);
+		          }
+		      } else {
+		          PointData data = new PointData();
+		          data.setEdnaId(pointid);
+		          if (sectionlist!=null && sectionlist.size()>0){
+                      data.setPointTime(sectionlist.get(0).getPointTime());
+                  }
+		          data.setPointValue("0");
+		          data.setPointName("1");
+		          data.setPointValueInDouble(0.0);
+		          resultList.add(data);
+		      }
+		  } else {
+		      PointData data = new PointData();
+		      data.setEdnaId(pointid);
+		      data.setPointTime(beginDate);
+		      data.setPointValue("0");
+		      data.setPointName("1");
+		      data.setPointValueInDouble(0.0);
+		      resultList.add(data);
+		  }
+	}
+
+
+    @Override
+    public List<PointData> getHistoryDatasRaw(Windpowerstationpointnew point, Long beginDate, Long endDate) throws Exception {
+        Optional<String> tagName = Optional.ofNullable(point.getCode());
+        Optional<String> thingId = Optional.ofNullable(point.getWindpowerstationid());
+        Optional<String> thingType = Optional.ofNullable(point.getModelid());
+        Optional<String> uniformCode = Optional.ofNullable(point.getUniformcode());
+        Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
+        Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
+
+        try {
+            String url = baseURL + "/history/snap?null=0";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "&tagName=" + tagName.get();
+            else {
+                if (thingType.isPresent())
+                    url = url + "&thingType=" + thingType.get();
+                if (thingId.isPresent())
+                    url = url + "&thingId=" + thingId.get();
+                if (uniformCode.isPresent())
+                    url = url + "&uniformCodes=" + uniformCode.get();
+            }
+
+            if (startTs.isPresent())
+                url = url + "&startTs=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&endTs=" + endTs.get();
+
+            ResponseEntity<JSONArray> resp = restTemplate.getForEntity(url, JSONArray.class);
+            JSONArray jsonArray = resp.getBody();
+            if (jsonArray != null)
+                return JsonObjectHelper.phrasePointData(jsonArray, point.getCode());
+            else {
+                return ErrorRequest.RequestListError(point.getCode());
+            }
+
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestListError(point.getCode());
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public PointData getRealData(Windturbinetestingpointnew point) throws Exception {
+        Optional<String> keys = Optional.ofNullable(point.getCode());
+        Optional<String> thingType = Optional.ofNullable(point.getModelid());
+        Optional<String> thingId = Optional.ofNullable(point.getWindpowerstationid());
+        Optional<String> uniformCodes = Optional.ofNullable(point.getUniformcode());
+
+        try {
+            String url = baseURL + "/latest?null=0";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (keys.isPresent())
+                url = url + "&keys=" + keys.get();
+            else {
+                if (thingType.isPresent())
+                    url = url + "&thingType=" + thingType.get();
+                if (thingId.isPresent())
+                    url = url + "&thingId=" + thingId.get();
+                if (uniformCodes.isPresent())
+                    url = url + "&uniformCodes=" + uniformCodes.get();
+            }
+            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+            JSONObject jsonArray = resp.getBody();
+             if (StringUtils.isNotEmpty(jsonArray)){
+                List<PointData> list = JsonObjectHelper.phrasePointData(jsonArray);
+                if (list.size() > 0)
+                    return list.get(0);
+                else
+                    return ErrorRequest.RequestError(point.getId());
+            } else {
+                return ErrorRequest.RequestError(point.getId());
+            }
+
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestError(point.getId());
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public List<PointData> getHistoryDatasSnap(Windturbinetestingpointnew point, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+        if (point==null){
+            System.out.println(1111);
+
+        }else if(point.getId()==null){
+            System.out.println(222);
+        }
+        Optional<String> tagName = Optional.ofNullable(point.getCode());
+        Optional<String> thingId = Optional.ofNullable(point.getWindpowerstationid());
+        Optional<String> thingType = Optional.ofNullable(point.getModelid());
+        Optional<String> uniformCode = Optional.ofNullable(point.getUniformcode());
+        Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
+        Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
+        //通过时间区间和时间间隔获取点数
+        Long finalInterval;
+        if (pried != null)
+            finalInterval = pried;
+        else if (count != null)
+            finalInterval = (endDate - beginDate) / count;
+        else
+            return ErrorRequest.RequestListError(point.getId());
+        Optional<Integer> interval = Optional.ofNullable(Integer.parseInt(finalInterval.toString()));
+
+        try {
+            String url = baseURL + "/history/snap?null=0";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "&tagName=" + tagName.get();
+            else {
+                if (thingType.isPresent())
+                    url = url + "&thingType=" + thingType.get();
+                if (thingId.isPresent())
+                    url = url + "&thingId=" + thingId.get();
+                if (uniformCode.isPresent())
+                    url = url + "&uniformCodes=" + uniformCode.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> snapList = JsonObjectHelper.phrasePointData(jsonArray, point.getId());
+                List<PointData> resultList = new ArrayList<>();
+
+                if(snapList.isEmpty())
+                {
+
+                	getHistsnapSameTiem(point.getId(), beginDate, pried, resultList);
+                }else
+                {
+                	for (PointData snapItem : snapList) {
+                        long subTime = snapItem.getPointTime() - pried;
+                        //查询时间区间的截面值(截面值为传入时间节点的上一个最近值,返回时间为值的真实时间),
+                        // 再进行比较,若截面值的时间戳在以快照时间节点前推一个单位的时间区间中,
+                        // 则代表该时间节点快照有效,否则为0
+                        String rawUrl = baseURL + "/history/section?null=0&tagNames=" + point.getCode() + "&ts=" + snapItem.getPointTime() + "000";
+                        ResponseEntity<JSONObject> sectionResp = restTemplate.getForEntity(rawUrl, JSONObject.class);
+                        JSONObject jsonObjectSection = sectionResp.getBody();
+
+                        if (jsonObjectSection != null) {
+                            List<PointData> sectionlist = JsonObjectHelper.phrasePointData(jsonObjectSection);
+                            if (sectionlist.size() > 0) {
+                                    resultList.add(snapItem);
+
+                            } else {
+                                PointData data = new PointData();
+                                data.setEdnaId(point.getId());
+                                data.setPointTime(snapItem.getPointTime());
+                                data.setPointValue("0");
+                                data.setPointName("1");
+                                data.setPointValueInDouble(0.0);
+                                resultList.add(data);
+                            }
+                        } else {
+                            PointData data = new PointData();
+                            data.setEdnaId(point.getId());
+                            data.setPointTime(snapItem.getPointTime());
+                            data.setPointValue("0");
+                            data.setPointName("1");
+                            data.setPointValueInDouble(0.0);
+                            resultList.add(data);
+                        }
+                    }
+                }
+
+
+                return resultList;
+            } else {
+                return ErrorRequest.RequestListError(point.getId());
+            }
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestListError(point.getId());
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+
+    @Override
+    public List<PointData> getHistoryDatasRaw(Windturbinetestingpointnew point, Long beginDate, Long endDate) throws Exception {
+        Optional<String> tagName = Optional.ofNullable(point.getCode());
+        Optional<String> thingId = Optional.ofNullable(point.getWindpowerstationid());
+        Optional<String> thingType = Optional.ofNullable(point.getModelid());
+        Optional<String> uniformCode = Optional.ofNullable(point.getUniformcode());
+        Optional<Long> startTs = Optional.ofNullable(beginDate);
+        Optional<Long> endTs = Optional.ofNullable(endDate);
+        try {
+            String url = baseURL + "/history/snap?null=0";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "&tagName=" + tagName.get();
+            else {
+                if (thingType.isPresent())
+                    url = url + "&thingType=" + thingType.get();
+                if (thingId.isPresent())
+                    url = url + "&thingId=" + thingId.get();
+                if (uniformCode.isPresent())
+                    url = url + "&uniformCodes=" + uniformCode.get();
+            }
+
+            if (startTs.isPresent())
+                url = url + "&startTs=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&endTs=" + endTs.get();
+
+            ResponseEntity<JSONArray> resp = restTemplate.getForEntity(url, JSONArray.class);
+            JSONArray jsonArray = resp.getBody();
+            if (jsonArray != null)
+                return JsonObjectHelper.phrasePointData(jsonArray, point.getId());
+            else {
+                return ErrorRequest.RequestListError(point.getId());
+            }
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestListError(point.getId());
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public PointData getRealData(String pointid) throws Exception {
+        Optional<String> keys = Optional.ofNullable(pointid);
+        String url = baseURL + "/latest?null=0";
+        try {
+            if (keys.isPresent())
+                url = url + "&keys=" + keys.get();
+            else
+                return null;
+
+            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+            JSONObject jsonArray = resp.getBody();
+             if (StringUtils.isNotEmpty(jsonArray)){
+                List<PointData> list = JsonObjectHelper.phrasePointData(jsonArray);
+                if (list.size() > 0)
+                    return list.get(0);
+                else
+                    return ErrorRequest.RequestError(pointid);
+            } else {
+                return ErrorRequest.RequestError(pointid);
+            }
+
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestError(pointid);
+            } else {
+                return ErrorRequest.RequestError(pointid);
+            }
+        }
+    }
+
+    @Override
+    public List<PointData> getRealData(String... pointids) throws Exception {
+        String pointIdString = StringUtil.join(pointids, ",");
+        Optional<String> keys = Optional.ofNullable(pointIdString);
+        String url = baseURL + "/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);
+            JSONObject jsonObject = resp.getBody();
+            if (jsonObject != null) {
+                //对结果进行有序返回
+                int len = pointids.length;
+                List<PointData> result = new ArrayList<>();
+                HashMap<String, PointData> pointDataHashMap = new HashMap<>();
+                for (int i = 0; i < len; i++) {
+
+                    if (pointDataHashMap.containsKey(pointids[i]) == false){
+                        PointData pd = new PointData();
+                        pd.setPointName(pointids[i]);
+                        pd.setEdnaId(pointids[i]);
+                        result.add(pd);
+
+                        pointDataHashMap.put(pd.getPointName(), pd);
+                    }
+                    else{
+                        result.add(pointDataHashMap.get(pointids[i]));
+                    }
+
+                }
+                Iterator<String> sIterator = jsonObject.keySet().iterator();
+                while (sIterator.hasNext()) {
+                    // 获得key
+                    String key = sIterator.next();
+                    PointData pointData = pointDataHashMap.get(key);
+                    if (pointData == null)
+                        continue;
+                    // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
+                    JSONObject jsonData = jsonObject.getJSONObject(key);
+                    Long ts = jsonData.getLong("ts");
+                    String pointValue = null;
+                    if (jsonData.containsKey("doubleValue")) {
+                        pointValue = jsonData.getString("doubleValue");
+                    } else if (jsonData.containsKey("booleanValue")) {
+                        pointValue = jsonData.getString("booleanValue");
+                    } else if (jsonData.containsKey("longValue")) {
+                        pointValue = jsonData.getString("longValue");
+                    } else if (jsonData.containsKey("stringValue")) {
+                        pointValue = jsonData.getString("stringValue");
+                    }
+                    pointData.setPointValue(pointValue);
+                    pointData.setPointValueInDouble(Double.parseDouble(pointValue));
+                   // System.out.println("key= " + key + ", ts = " + ts + ", value = " + pointValue);
+                }
+                return result;
+
+            } else {
+                return ErrorRequest.RequestListError(pointids);
+            }
+
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestListError(pointids);
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+
+
+    @Override
+    public List<PointData> getRealData(List<String> pointids) throws Exception {
+        String pointIdString = StringUtil.join(pointids.toArray(), ",");
+        Optional<String> keys = Optional.ofNullable(pointIdString);
+        String url = baseURL + "/latest?null=0";
+        try {
+            if (keys.isPresent())
+                url = url + "&keys=" + keys.get();
+            else {
+                String[] arr = new String[pointids.size()];
+                return ErrorRequest.RequestListError(pointids.toArray(arr));
+            }
+
+            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+            JSONObject jsonObject = resp.getBody();
+            if (jsonObject != null) {
+
+
+                //对结果进行有序返回
+                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.get(i)) == false){
+                        PointData pd = new PointData();
+                        pd.setPointName(pointids.get(i));
+                        pd.setEdnaId(pointids.get(i));
+                        result.add(pd);
+
+                        pointDataHashMap.put(pd.getPointName(), pd);
+                    }
+                    else{
+                        result.add(pointDataHashMap.get(pointids.get(i)));
+                    }
+                }
+                Iterator<String> sIterator = jsonObject.keySet().iterator();
+                while (sIterator.hasNext()) {
+                    // 获得key
+                    String key = sIterator.next();
+                    PointData pointData = pointDataHashMap.get(key);
+                    if (pointData == null)
+                        continue;
+                    // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
+                    JSONObject jsonData = jsonObject.getJSONObject(key);
+                    Long ts = jsonData.getLong("ts");
+                    String pointValue = null;
+                    if (jsonData.containsKey("doubleValue")) {
+                        pointValue = jsonData.getString("doubleValue");
+                    } else if (jsonData.containsKey("booleanValue")) {
+                        pointValue = jsonData.getString("booleanValue");
+                        if (Boolean.parseBoolean(pointValue)){
+                            pointValue =  "1";
+                        }else {
+                            pointValue =  "0";
+                        }
+
+                    } else if (jsonData.containsKey("longValue")) {
+                        pointValue = jsonData.getString("longValue");
+                    } else if (jsonData.containsKey("stringValue")) {
+                        pointValue = jsonData.getString("stringValue");
+                    }
+                    pointData.setPointTime(ts);
+                    pointData.setPointValue(pointValue);
+
+                    pointData.setPointValueInDouble(Double.parseDouble(pointValue));
+                  //  System.out.println("key= " + key + ", ts = " + ts + ", value = " + pointValue);
+                }
+                return result;
+
+            } else {
+                String[] arr = new String[pointids.size()];
+                return ErrorRequest.RequestListError(pointids.toArray(arr));
+            }
+
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                String[] arr = new String[pointids.size()];
+                return ErrorRequest.RequestListError(pointids.toArray(arr));
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public Map<String, Double> getRealDataMap(String... pointids) throws Exception {
+        String pointIdString = StringUtil.join(pointids, ",");
+        Optional<String> keys = Optional.ofNullable(pointIdString);
+        String url = baseURL + "/latest?null=0";
+        try {
+            if (keys.isPresent())
+                url = url + "&keys=" + keys.get();
+            else
+                return null;
+            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+            JSONObject jsonArray = resp.getBody();
+             if (StringUtils.isNotEmpty(jsonArray)){
+                Iterator<String> sIterator = jsonArray.keySet().iterator();
+                Map<String, Double> resultMap = new HashMap();
+                while (sIterator.hasNext()) {
+                    // 获得key
+                    String key = sIterator.next();
+                    // 根据key获得value, value也可以是JSONObject,JSONArray,使用对应的参数接收即可
+                    JSONObject jsonData = jsonArray.getJSONObject(key);
+                    Long ts = jsonData.getLong("ts");
+                    String pointValue = null;
+                    if (jsonData.containsKey("doubleValue")) {
+                        pointValue = jsonData.getString("doubleValue");
+                    } else if (jsonData.containsKey("booleanValue")) {
+                        pointValue = jsonData.getString("booleanValue");
+                    } else if (jsonData.containsKey("longValue")) {
+                        pointValue = jsonData.getString("longValue");
+                    } else if (jsonData.containsKey("stringValue")) {
+                        pointValue = jsonData.getString("stringValue");
+                    }
+                    resultMap.put(key, Double.parseDouble(pointValue));
+                }
+                return resultMap;
+
+            } else
+                return ErrorRequest.RequestMapError();
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestMapError();
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+
+	  @Override
+	    public List<PointData> getHistoryDatasSnap(String pointid, Long beginDate, Long endDate, Long count, Long pried) throws Exception {
+	        Optional<String> tagName = Optional.ofNullable(pointid);
+	        Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
+	        Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
+
+	        //通过时间区间和时间间隔获取点数
+	        Long finalInterval;
+	        if (pried != null)
+	            finalInterval = pried;
+	        else if (count != null)
+	            finalInterval = (endDate - beginDate) / count;
+	        else
+	            return ErrorRequest.RequestListError(pointid);
+	        Optional<Integer> interval = Optional.ofNullable(Integer.parseInt(finalInterval.toString()));
+
+	        try {
+	            String url = baseURL + "/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())
+	                {
+
+	                	getHistsnapSameTiem(pointid, beginDate, pried, resultList);
+	                }else
+	                {
+	                	 for (PointData snapItem : list) {
+	 	                    long subTime = snapItem.getPointTime() - pried;
+	 	                    //查询时间区间的截面值(截面值为传入时间节点的上一个最近值,返回时间为值的真实时间),
+	 	                    // 再进行比较,若截面值的时间戳在以快照时间节点前推一个单位的时间区间中,
+	 	                    // 则代表该时间节点快照有效,否则为0
+	 	                    String rawUrl = baseURL + "/history/section?null=0&tagNames=" +pointid+ "&ts=" + snapItem.getPointTime() + "000";
+	 	                    ResponseEntity<JSONObject> sectionResp = restTemplate.getForEntity(rawUrl, JSONObject.class);
+	 	                    JSONObject jsonObjectSection = sectionResp.getBody();
+
+	 	                    if (jsonObjectSection != null) {
+	 	                        List<PointData> sectionlist = JsonObjectHelper.phrasePointData(jsonObjectSection);
+	 	                        if (sectionlist.size() > 0) {
+	 	                            if(sectionlist.get(0).getPointTime()>=subTime&&sectionlist.get(0).getPointTime()<=snapItem.getPointTime()){
+	 	                                resultList.add(snapItem);
+	 	                            }
+	 	                            else{
+	 	                                PointData data = new PointData();
+	 	                                data.setEdnaId(pointid);
+	 	                                data.setPointTime(snapItem.getPointTime());
+	 	                                data.setPointValue("0");
+	 	                                data.setPointName("1");
+	 	                                data.setPointValueInDouble(0.0);
+	 	                                resultList.add(data);
+	 	                            }
+	 	                        } else {
+	 	                            PointData data = new PointData();
+	 	                            data.setEdnaId(pointid);
+	 	                            data.setPointTime(snapItem.getPointTime());
+	 	                            data.setPointValue("0");
+	 	                            data.setPointName("1");
+	 	                            data.setPointValueInDouble(0.0);
+	 	                            resultList.add(data);
+	 	                        }
+	 	                    } else {
+	 	                        PointData data = new PointData();
+	 	                        data.setEdnaId(pointid);
+	 	                        data.setPointTime(snapItem.getPointTime());
+	 	                        data.setPointValue("0");
+	 	                        data.setPointName("1");
+	 	                        data.setPointValueInDouble(0.0);
+	 	                        resultList.add(data);
+	 	                    }
+	 	                }
+	                }
+
+	                return resultList;
+	            } 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;
+	            }
+	        }
+
+	    }
+
+
+    @Override
+    public List<PointData> getHistoryDatasRaw(String pointid, Long beginDate, Long endDate) throws Exception {
+        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/raw?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();
+
+            ResponseEntity<JSONArray> resp = restTemplate.getForEntity(url, JSONArray.class);
+
+            JSONArray jsonArray = resp.getBody();
+            if (jsonArray != null)
+                return JsonObjectHelper.phrasePointData(jsonArray, pointid);
+            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;
+            }
+        }
+    }
+
+    @Override
+    public List<PointData> getHistStat(Windturbinetestingpointnew point, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+        Optional<String> tagName = Optional.ofNullable(point.getCode());
+        Optional<String> thingId = Optional.ofNullable(point.getWindpowerstationid());
+        Optional<String> thingType = Optional.ofNullable(point.getModelid());
+        Optional<String> uniformCode = Optional.ofNullable(point.getUniformcode());
+        Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
+        Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
+
+//        Calendar cal = Calendar.getInstance();
+//        cal.setTime(new Date(startTs.get()));
+//        cal.add(Calendar.SECOND, -pried.intValue());
+//        startTs= Optional.ofNullable(cal.getTime().getTime());
+//        count++;
+
+        //通过时间区间和时间间隔获取点数
+        Long finalInterval;
+        if (pried != null)
+            finalInterval = pried;
+        else if (count != null)
+            finalInterval = (endDate - beginDate) / count;
+        else
+            return ErrorRequest.RequestListError(point.getId());
+        Optional<Integer> interval = Optional.ofNullable(Integer.parseInt(finalInterval.toString()));
+
+        try {
+            String url = baseURL + "/history/stat?null=0";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "&tagName=" + tagName.get();
+            else {
+                if (thingType.isPresent())
+                    url = url + "&thingType=" + thingType.get();
+                if (thingId.isPresent())
+                    url = url + "&thingId=" + thingId.get();
+                if (uniformCode.isPresent())
+                    url = url + "&uniformCodes=" + uniformCode.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)
+                return JsonObjectHelper.GeneralTsDataToPointDataByStat(jsonArray, point.getId(), type);
+            else {
+                return ErrorRequest.RequestListError(point.getId());
+            }
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestListError(point.getId());
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public List<PointData> getHistStat(Windpowerstationpointnew point, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+        Optional<String> tagName = Optional.ofNullable(point.getCode());
+        Optional<String> thingId = Optional.ofNullable(point.getWindpowerstationid());
+        Optional<String> thingType = Optional.ofNullable(point.getModelid());
+        Optional<String> uniformCode = Optional.ofNullable(point.getUniformcode());
+        Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
+        Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
+        //通过时间区间和时间间隔获取点数
+        Long finalInterval;
+        if (pried != null)
+            finalInterval = pried;
+        else if (count != null)
+            finalInterval = (endDate - beginDate) / count;
+        else
+            return ErrorRequest.RequestListError(point.getCode());
+        Optional<Integer> interval = Optional.ofNullable(Integer.parseInt(finalInterval.toString()));
+
+        try {
+            String url = baseURL + "/history/stat?null=0";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "&tagName=" + tagName.get();
+            else {
+                if (thingType.isPresent())
+                    url = url + "&thingType=" + thingType.get();
+                if (thingId.isPresent())
+                    url = url + "&thingId=" + thingId.get();
+                if (uniformCode.isPresent())
+                    url = url + "&uniformCodes=" + uniformCode.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)
+                return JsonObjectHelper.GeneralTsDataToPointDataByStat(jsonArray, point.getCode(), type);
+            else {
+                return ErrorRequest.RequestListError(point.getCode());
+            }
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestListError(point.getCode());
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public List<PointData> getHistStat(String pointid, Long beginDate, Long endDate, Long count, Long pried, int type) throws Exception {
+        Optional<String> tagName = Optional.ofNullable(pointid);
+        Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
+        Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
+        //通过时间区间和时间间隔获取点数
+        Long finalInterval;
+        if (count != null)
+            finalInterval = (endDate - beginDate) / count;
+        else if (pried != null)
+            finalInterval = pried;
+        else
+            return null;
+        Optional<Integer> interval = Optional.ofNullable(Integer.parseInt(finalInterval.toString()));
+        try {
+            String url = baseURL + "/history/stat?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)
+                return JsonObjectHelper.GeneralTsDataToPointDataByStat(jsonArray, pointid, type);
+            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;
+            }
+        }
+    }
+
+    @Override
+    public DNAStatVal[] getHistStat(String point, Long beginDate, Long endDate, Integer pried) throws Exception {
+        Optional<String> tagName = Optional.ofNullable(point);
+        Optional<Long> startTs = Optional.ofNullable(beginDate * 1000);
+        Optional<Long> endTs = Optional.ofNullable(endDate * 1000);
+        //通过时间区间和时间间隔获取点数
+        Optional<Integer> interval = Optional.ofNullable(pried);
+
+        try {
+            String url = baseURL + "/history/stat?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();
+
+            //System.out.println(restTemplate.getForEntity(url, JSONArray.class));
+            ResponseEntity<JSONArray> resp = restTemplate.getForEntity(url, JSONArray.class);
+            if (resp != null) {
+                JSONArray jsonArray = resp.getBody();
+                if (jsonArray == null || jsonArray.size() <= 0) {
+                    DNAStatVal[] dnaVal = new DNAStatVal[1];
+                    DNAVal errorData = new DNAVal();
+                    errorData.Status = 0;
+
+                    DNAStatVal val = new DNAStatVal();
+                    val.avg = errorData;
+                    val.max = errorData;
+                    val.min = errorData;
+                    dnaVal[0] = val;
+                    return dnaVal;
+                } else {
+                    return JsonObjectHelper.phraseDNAVal(jsonArray);
+                }
+            } else {
+                return null;
+            }
+
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                DNAStatVal val = new DNAStatVal();
+                DNAStatVal[] dnaVal = new DNAStatVal[1];
+                DNAVal errorData = new DNAVal();
+                errorData.Status = 0;
+                val.avg = errorData;
+                val.max = errorData;
+                val.min = errorData;
+                dnaVal[0] = val;
+                return dnaVal;
+
+            } else {
+                DNAStatVal val = new DNAStatVal();
+                DNAStatVal[] dnaVal = new DNAStatVal[1];
+                DNAVal errorData = new DNAVal();
+                errorData.Status = 0;
+                val.avg = errorData;
+                val.max = errorData;
+                val.min = errorData;
+                dnaVal[0] = val;
+                return dnaVal;
+            }
+        }
+    }
+
+    private JSONObject convertPointData(PointData pd) {
+        JSONObject jo = new JSONObject();
+        jo.put("tagName", pd.getEdnaId());
+        JSONObject joo = new JSONObject();
+        joo.put("ts", pd.getPointTime());
+        joo.put("status", 0);
+        joo.put("doubleValue", pd.getPointValueInDouble());
+        jo.put("tsData", joo);
+        return jo;
+    }
+
+    @Override
+    public void updatePoint(PointData point) throws Exception {
+        String url = baseURL + "/history";
+        try {
+            String result = restTemplate.postForObject(url, convertPointData(point), String.class);
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                return;
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public DNAVal[] getRealtimeTagValues(String... tagNames) throws Exception {
+        String pointIdString = StringUtil.join(tagNames, ",");
+        Optional<String> keys = Optional.ofNullable(pointIdString);
+        String url = baseURL + "/latest?null=0";
+        try {
+            if (keys.isPresent())
+                url = url + "&keys=" + keys.get();
+            else
+                return null;
+
+            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+            JSONObject jsonObject = resp.getBody();
+            if (StringUtils.isNotEmpty(jsonObject) && !jsonObject.isEmpty()){
+                return JsonObjectHelper.phraseDNAVal(jsonObject,tagNames);
+            } else {
+            	  DNAVal[] errorResult = new DNAVal[tagNames.length];
+                  for(int i=0;i<tagNames.length;i++)
+                  {
+                  	 DNAVal val = new DNAVal();
+                       val.Status = 0;
+                       errorResult[i] = val;
+                  }
+                  return errorResult;
+            }
+
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                DNAVal[] errorResult = new DNAVal[tagNames.length];
+                for(int i=0;i<tagNames.length;i++)
+                {
+                	 DNAVal val = new DNAVal();
+                     val.Status = 0;
+                     errorResult[i] = val;
+                }
+                return errorResult;
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public void updatePoint(List<PointData> pointls) throws Exception {
+        String url = baseURL + "/history/batch";
+        List<JSONObject> writeList = new ArrayList<>();
+
+        for (PointData entity : pointls) {
+            writeList.add(convertPointData(entity));
+        }
+        try {
+            String result = restTemplate.postForObject(url, writeList, String.class);
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                return;
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public void sendSinglePoint(PointData point) throws Exception {
+        String url = baseURL + "/latest";
+
+
+        try {
+            String result = restTemplate.postForObject(url, convertPointData(point), String.class);
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                return;
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public void sendMultiPoint(List<PointData> pointls) throws Exception {
+
+        String url = baseURL + "/latest/batch";
+        List<JSONObject> writeList = new ArrayList<>();
+
+        for (PointData entity : pointls) {
+            writeList.add(convertPointData(entity));
+        }
+        try {
+            String result = restTemplate.postForObject(url, writeList, String.class);
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+    @Override
+    public void sendMultiPoint(String[] realvalue, DNAVal[] pointls) throws Exception {
+        String url = baseURL + "/latest/batch";
+
+        List<JSONObject> writeDataList = new ArrayList<>();
+        if (realvalue != null && pointls != null & realvalue.length == pointls.length) {
+            for (int i = 0; i < realvalue.length; i++) {
+                PointData writeData = new PointData();
+                writeData.setEdnaId(realvalue[i]);
+                writeData.setPointValueInDouble(pointls[i].DValue);
+                writeData.setPointTime((long)pointls[i].Time);
+                JSONObject jsonObject=convertPointData(writeData);
+                writeDataList.add(jsonObject);
+            }
+
+            try {
+                String result = restTemplate.postForObject(url, writeDataList, String.class);
+            } catch (HttpClientErrorException exception) {
+                if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                    System.out.println("404请求错误");
+                } else {
+                    throw exception;
+                }
+            }
+        } else
+            return;
+    }
+
+    //多点切面数据
+    @Override
+    public DNAVal[] getHistMatrix(String[] nameList, int tTime) throws Exception {
+        String tagNameString = StringUtil.join(nameList, ",");
+        Long time = Long.valueOf(tTime);
+        Optional<String> tagName = Optional.ofNullable(tagNameString);
+        Optional<Long> ts = Optional.ofNullable(time * 1000);
+        String url = baseURL + "/history/section?tagNames=" + tagName.get() + "&ts=" + ts.get();
+        try {
+            ResponseEntity<JSONObject> resp = restTemplate.getForEntity(url, JSONObject.class);
+            JSONObject jsonObject = resp.getBody();
+            if (StringUtils.isNotEmpty(jsonObject) && !jsonObject.isEmpty())
+            {
+            	 return JsonObjectHelper.phraseDNAVal(jsonObject,nameList);
+            }
+            else {
+                DNAVal[] errorResult = new DNAVal[nameList.length];
+                for(int i=0;i<nameList.length;i++)
+                {
+                	 DNAVal val = new DNAVal();
+                     val.Status = 0;
+                     errorResult[i] = val;
+                }
+                return errorResult;
+            }
+        } catch (Exception e) {
+        	  DNAVal[] errorResult = new DNAVal[nameList.length];
+              for(int i=0;i<nameList.length;i++)
+              {
+              	 DNAVal val = new DNAVal();
+                   val.Status = 0;
+                   errorResult[i] = val;
+              }
+              return errorResult;
+        }
+    }
+
+
+}

+ 24 - 19
realtime/generation-service/src/main/resources/application-td.yml

@@ -1,5 +1,5 @@
 server:
-  port: 7011
+  port: 7012
   servlet:
     context-path: /
 
@@ -9,16 +9,16 @@ spring:
     allow-bean-definition-overriding: true #当遇到同样名字的时候,是否允许覆盖注册
   #redis集群
   redis:
-    host: 10.83.68.151
+    host: 10.81.3.155
     port: 6379
     timeout: 100000
     #    集群环境打开下面注释,单机不需要打开
-    cluster:
-      #集群信息
-      nodes: 10.83.68.151:6379,10.83.68.152:6379,10.83.68.153:6379,10.83.68.154:6379,10.83.68.155:6379,10.83.68.156:6379,10.83.68.157:6379,10.83.68.158:6379,10.83.68.159:6379
-      #默认值是5 一般当此值设置过大时,容易报:Too many Cluster redirections
-      maxRedirects: 3
-    password: Dsjpt@2021
+    #    cluster:
+    #      #集群信息
+    #      nodes: 10.83.68.151:6379,10.83.68.152:6379,10.83.68.153:6379,10.83.68.154:6379,10.83.68.155:6379,10.83.68.156:6379,10.83.68.157:6379,10.83.68.158:6379,10.83.68.159:6379
+    #      #默认值是5 一般当此值设置过大时,容易报:Too many Cluster redirections
+    #      maxRedirects: 3
+    password:
     application:
       name: test
     jedis:
@@ -32,9 +32,8 @@ spring:
     exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
-    driver-class-name: oracle.jdbc.OracleDriver
-    #外网
-    url: jdbc:oracle:thin:@10.83.68.165:1521:gdsj
+    driver-class-name: org.postgresql.Driver
+    url: jdbc:postgresql://10.81.3.151:5432/wisdom
     username: gdprod
     password: gd123
     oracle-schema=:
@@ -84,21 +83,27 @@ logging:
     com.example: debug
 #db url
 db:
-  url: http://10.83.68.159:8011/ts
+  url: http://10.81.3.152:8011/ts
+td:
+  url: http://localhost:8011/ts
 #参与计算的场站
-runWindpowerstation: CL_FDC,KB_FDC,DX_FDC,SY_FDC
+runWindpowerstation: YLZ_FDC
 #计算状态用ai或者di
 clauStatus:
-  ai: CL_FDC,KB_FDC,DX_FDC,SY_FDC   #配置期次
-  di:
-
+  ai: GJY03_GC,YLZ01_GC,PTZ02_GC   #配置期次
+  di: GJY01_GC,GJY02_GC,DJY01_GC,DJY02_GC,YF01_GC,YF02_GC,HSM01_GC,PTZ01_GC,ZK01_GC,NJL01_GC
 #判断数据终端
-second: 90
+second: 1800
 #判断降出力
-AI134: 17.4
-AI178: 17.4
+AI134: 17.4    #叶轮转速给定
+AI178: 17.4    #转矩给定
 #AI443:容量
 
+#计算电量直接取,如果不是1就是相减算
+typeOfElectric:
+  #直接取
+  direct: GJY02_GC,YF01_GC,YF02_GC,HSM01_GC,PTZ01_GC,ZK01_GC
+
 
 
 

+ 2 - 2
realtime/generation-service/src/main/resources/application.yml

@@ -1,4 +1,4 @@
 spring:
   profiles:
-    active: jn
-#    active: dev
+#    active: jn
+    active: td

+ 2 - 2
realtime/generation-service/src/test/java/com/gyee/generation/GenerationTest.java

@@ -49,8 +49,8 @@ public class GenerationTest {
     @Test
     public void test1() throws Exception {
 //        averageAndGeneratingService.saveAvespeedAndAvepowerAndScada();
-//        statusService.calculateStatus();
-        realtimeSpeedPowerService.calculateRealtimeSpeedPower();
+        statusService.calculateStatus();
+//        realtimeSpeedPowerService.calculateRealtimeSpeedPower();
 //        generationService.saveMeterpointValueRealtime();
 //        theorypowerService.fittingPower();
 //        theorypowerService.theropower();

+ 1 - 1
web/adapter-td-hb/src/main/java/com/gyee/adapter/common/config/OracleConfiguration.java

@@ -19,7 +19,7 @@ public class OracleConfiguration {
     @Value("${windturbine.point.table_name:view_tspoint}")
     public String tableName;
 
-    @Value("${springdatasource.url:jdbc:oracle:thin:@10.83.68.165:1521:gdsj}")
+    @Value("${spring.datasource.url:jdbc:oracle:thin:@10.83.68.165:1521:gdsj}")
     private String url;
 
     @Value("${spring.datasource.driver-class-name:oracle.jdbc.OracleDriver}")

+ 5 - 5
web/adapter-td-hb/src/main/java/com/gyee/adapter/dao/TaosHistoryDao.java

@@ -78,7 +78,7 @@ public class TaosHistoryDao implements IHistoryDao {
 
         try {
             Statement st = connect.createStatement();
-            String point = tsQuery.getTsPoint().getId();
+            String point = tsQuery.getTsPoint().getId().replace(".","_");
 
             StringBuilder sb = new StringBuilder();
             sb.append("select avg(value_double),max(value_double),min(value_double) from ").append(point);
@@ -117,7 +117,7 @@ public class TaosHistoryDao implements IHistoryDao {
             sb.append("insert into ");
             for (TsPointData obj : dataList) {
                 long time = obj.getTsData().getTs();
-                String point = obj.getTagName();
+                String point = obj.getTagName().replace(".","_");
                 double value = obj.getTsData().getDoubleValue().get();
 //                sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
                 sb.append(point).append(" values (");
@@ -288,7 +288,7 @@ public class TaosHistoryDao implements IHistoryDao {
      * @throws WisdomException
      */
     private String getHistory(TsQuery tsQuery) throws WisdomException {
-        String point = tsQuery.getTsPoint().getId();
+        String point = tsQuery.getTsPoint().getId().replace(".","_");
         StringBuilder sb = new StringBuilder();
         if (tsQuery.getInterpolation() == Interpolation.RAW) {
             sb.append("select * from ").append(point);
@@ -323,9 +323,9 @@ public class TaosHistoryDao implements IHistoryDao {
      */
     private String getSectionSql(String tag, long ts) {
 //        String point = TaosCovertUtil.coverStationPrefix(tag) + "." + tag.replace(".", "_");
-
+        String point = tag.replace(".", "_");
         StringBuilder sb = new StringBuilder();
-        sb.append("select last_row(*) from ").append(tag);
+        sb.append("select last_row(*) from ").append(point);
         sb.append(" where point_time>='");
         sb.append(DateFormatUtils.format(ts - half_year_time, "yyyy-MM-dd HH:mm:ss:SSS") + "'");
         sb.append(" and point_time <='" + DateFormatUtils.format(ts, "yyyy-MM-dd HH:mm:ss:SSS") + "'");

+ 2 - 2
web/adapter-td-hb/src/main/java/com/gyee/adapter/dao/TaosLatestDao.java

@@ -807,11 +807,11 @@ public class TaosLatestDao implements ILatestDao {
             sb.append("insert into ");
             for (TsPointData obj : list) {
                 long time = obj.getTsData().getTs();
-                String point = obj.getTagName();
+                String point = obj.getTagName().replace(".","_");
                 double value = obj.getTsData().getDoubleValue().get();
 //                sb.append(TaosCovertUtil.coverStationPrefix(point)).append(".");
                 sb.append(point).append(" values (");
-                sb.append(time).append(",").append(value).append(")");
+                sb.append(time).append(",").append(value).append(") ");
             }
 
             flag = st.execute(sb.toString());

+ 6 - 6
web/adapter-td-hb/src/main/java/com/gyee/adapter/init/RestInsertExample.java

@@ -32,10 +32,10 @@ public class RestInsertExample {
 //        INSERT INTO d1001 VALUES (1538548685000, 10.3, 219, 0.31) (1538548695000, 12.6, 218, 0.33)
 //        d1002 VALUES (1538548696800, 12.3, 221, 0.31);
         StringBuilder sb = new StringBuilder();
-        String replace = name.replace(".", "_");
-        sb.append("INSERT INTO ").append(database).append(".").append(table).append(" USING ").append(stable);
+        String replace = table.replace(".", "_");
+        sb.append("INSERT INTO ").append(database).append(".").append(replace).append(" USING ").append(database).append(".").append(stable);
         sb.append(" TAGS (\"").append(table).append("\",\"");
-        sb.append(replace).append("\") VALUES (now, 0.0)");
+        sb.append(name).append("\") VALUES (now, 0.0)");
         return String.valueOf(sb);
     }
 
@@ -79,7 +79,7 @@ public class RestInsertExample {
             String sql = getSQL(stable, database, code,name);
             Connection connection = getConnection();
             Statement statement1 = connection.createStatement();
-            statement1.execute(sql);
+            statement1.executeUpdate(sql);
             connection.close();
             statement1.close();
         }
@@ -89,7 +89,7 @@ public class RestInsertExample {
     }
 
     public static void main(String[] args) throws SQLException {
-        createStable("wisdom","stag_double");
-//        initPoint("windpowerstationpointnew","SXJN.JSFWYLZFC","YLZFCJSFW","wisdom");
+        createStable("wisdom","JSFW");
+        initPoint("windpowerstationpointnew","JSFW","JSFW","wisdom");
     }
 }