Browse Source

简单矩阵功能调整

xieshengjie 3 years ago
parent
commit
22c39f9d08

+ 6 - 0
common/pom.xml

@@ -102,6 +102,12 @@
             <version>1.9.13</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+            <version>3.1</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
 </project>

+ 172 - 0
common/src/main/java/com/gyee/common/util/HttpClientUtil.java

@@ -0,0 +1,172 @@
+package com.gyee.common.util;
+
+import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
+
+import java.io.*;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * @ClassName : HttpClientUtil
+ * @Author : xieshengjie
+ * @Date: 2021/12/22 15:52
+ * @Description :
+ */
+public class HttpClientUtil {
+    public static String doGet(String url) {
+        // 输入流
+        InputStream is = null;
+        BufferedReader br = null;
+        String result = null;
+        // 创建httpClient实例
+        HttpClient httpClient = new HttpClient();
+        // 设置http连接主机服务超时时间:15000毫秒
+        // 先获取连接管理器对象,再获取参数对象,再进行参数的赋值
+        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(15000);
+        // 创建一个Get方法实例对象
+        GetMethod getMethod = new GetMethod(url);
+        // 设置get请求超时为60000毫秒
+        getMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 60000);
+        // 设置请求重试机制,默认重试次数:3次,参数设置为true,重试机制可用,false相反
+        getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, true));
+        try {
+            // 执行Get方法
+            int statusCode = httpClient.executeMethod(getMethod);
+            // 判断返回码
+            if (statusCode != HttpStatus.SC_OK) {
+                // 如果状态码返回的不是ok,说明失败了,打印错误信息
+                System.err.println("Method faild: " + getMethod.getStatusLine());
+            } else {
+                // 通过getMethod实例,获取远程的一个输入流
+                is = getMethod.getResponseBodyAsStream();
+                // 包装输入流
+                br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+
+                StringBuffer sbf = new StringBuffer();
+                // 读取封装的输入流
+                String temp = null;
+                while ((temp = br.readLine()) != null) {
+                    sbf.append(temp).append("\r\n");
+                }
+
+                result = sbf.toString();
+            }
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            // 关闭资源
+            if (null != br) {
+                try {
+                    br.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (null != is) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            // 释放连接
+            getMethod.releaseConnection();
+        }
+        return result;
+    }
+
+    public static String doPost(String url, Map<String, Object> paramMap) {
+        // 获取输入流
+        InputStream is = null;
+        BufferedReader br = null;
+        String result = null;
+        // 创建httpClient实例对象
+        HttpClient httpClient = new HttpClient();
+        // 设置httpClient连接主机服务器超时时间:15000毫秒
+        httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(15000);
+        // 创建post请求方法实例对象
+        PostMethod postMethod = new PostMethod(url);
+        // 设置post请求超时时间
+        postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT, 60000);
+
+        NameValuePair[] nvp = null;
+        // 判断参数map集合paramMap是否为空
+        if (null != paramMap && paramMap.size() > 0) {// 不为空
+            // 创建键值参数对象数组,大小为参数的个数
+
+            nvp = new NameValuePair[paramMap.size()];
+            // 循环遍历参数集合map
+            Set<Entry<String, Object>> entrySet = paramMap.entrySet();
+            // 获取迭代器
+            Iterator<Entry<String, Object>> iterator = entrySet.iterator();
+
+            int index = 0;
+            while (iterator.hasNext()) {
+                Entry<String, Object> mapEntry = iterator.next();
+                // 从mapEntry中获取key和value创建键值对象存放到数组中
+                try {
+                    nvp[index] = new NameValuePair(mapEntry.getKey(),
+                            new String(mapEntry.getValue().toString().getBytes("UTF-8"), "UTF-8"));
+                } catch (UnsupportedEncodingException e) {
+                    e.printStackTrace();
+                }
+                index++;
+            }
+        }
+        // 判断nvp数组是否为空
+        if (null != nvp && nvp.length > 0) {
+            // 将参数存放到requestBody对象中
+            postMethod.setRequestBody(nvp);
+        }
+        // 执行POST方法
+        try {
+            int statusCode = httpClient.executeMethod(postMethod);
+            // 判断是否成功
+            if (statusCode != HttpStatus.SC_OK) {
+                System.err.println("Method faild: " + postMethod.getStatusLine());
+            }
+            // 获取远程返回的数据
+            is = postMethod.getResponseBodyAsStream();
+            // 封装输入流
+            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+
+            StringBuffer sbf = new StringBuffer();
+            String temp = null;
+            while ((temp = br.readLine()) != null) {
+                sbf.append(temp).append("\r\n");
+            }
+
+            result = sbf.toString();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            // 关闭资源
+            if (null != br) {
+                try {
+                    br.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            if (null != is) {
+                try {
+                    is.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+            // 释放连接
+            postMethod.releaseConnection();
+        }
+        return result;
+    }
+}

+ 8 - 6
web/monitor-web/src/main/java/com/gyee/monitor/service/matrix/MatrixService.java

@@ -32,12 +32,14 @@ public class MatrixService {
     @Resource
     private IEdosUtil edosUtil;
 
+//    private IEdosUtil edosUtil = new MongoEdosUtil();
+
 
     public Map<String,Object> matrixDatas()  {
         Map<String,Object> resultMap = new HashMap<>();
         Map<String,Map<String,Object>> wpresultMap = new HashMap<>();
 
-        Map<String,List<MatrixVo>> wtMap = Collections.synchronizedMap(new HashMap<>());
+        Map<String,List<MatrixVo>> wtMap = new HashMap<>();
 
 
         Map<String, Map<String, Windpowerstationpointnew>> wpPointmap = CacheContext.wpPointmap;
@@ -63,7 +65,7 @@ public class MatrixService {
         }
         SortUtils.sort(wpls,"ordernum",SortUtils.ASC);
         wpls.stream().forEach(wp-> {
-            Map<String,Object> wpMap = Collections.synchronizedMap(new HashMap<>());
+            Map<String,Object> wpMap = new HashMap<>();
             wpMap.put("JRTS",wp.getQuantity());
             wpMap.put("WPNAME",wp.getName());
             List<String> pointList = new ArrayList<>();
@@ -81,7 +83,7 @@ public class MatrixService {
             });
             try {
                 List<PointData> realData = edosUtil.getRealData(pointList);
-                realData.parallelStream().forEach(i -> {
+                realData.stream().forEach(i -> {
                     String uniform = pointMap.get(i.getEdnaId());
                     if (uniform.equals(Contant.TPOINT_WP_BZGL) || uniform.equals(Contant.TPOINT_WP_YFGL))
                         wpMap.put(pointMap.get(i.getEdnaId()), i.getPointValueInDouble()/1000);
@@ -105,9 +107,9 @@ public class MatrixService {
 
 
         List<Windturbine> wtls = CacheContext.wtls;
-        List<String> synchronizedList = Collections.synchronizedList(new ArrayList<>());
-        Map<String,String> synchronizedMap = Collections.synchronizedMap(new HashMap<>());
-        wtls.parallelStream().forEach(wt->{
+        List<String> synchronizedList = new ArrayList<>();
+        Map<String,String> synchronizedMap = new HashMap<>();
+        wtls.stream().forEach(wt->{
             Windturbinetestingpointnew windturbinetestingpointnew = wtPointmap.get(wt.getId()).get(Contant.TPOINT_WT_FJZT);
             if (!windturbinetestingpointnew.getCode().trim().equals("INITIAL")){
                 synchronizedList.add(windturbinetestingpointnew.getCode());

+ 2 - 2
web/monitor-web/src/main/java/com/gyee/monitor/task/MonitorTask.java

@@ -1,6 +1,6 @@
 package com.gyee.monitor.task;
 
-import com.gyee.common.util.JSONUtil;
+import com.alibaba.fastjson.JSON;
 import com.gyee.monitor.service.matrix.MatrixService;
 import com.gyee.monitor.websocket.MonitorSocket;
 import org.slf4j.Logger;
@@ -37,7 +37,7 @@ public class MonitorTask {
             try {
                 if (webSocketSet.get(k).getSession().isOpen()) {
                     if (k.equals("matrix"))
-                    webSocketSet.get(k).sendMessage(JSONUtil.objectToJson(matrixService.matrixDatas()));
+                    webSocketSet.get(k).sendMessage(JSON.toJSONString(matrixService.matrixDatas()));
                 }
             } catch (IOException e) {
                 e.printStackTrace();

+ 789 - 0
web/monitor-web/src/main/java/com/gyee/monitor/util/realtimesource/MongoEdosUtil.java

@@ -0,0 +1,789 @@
+package com.gyee.monitor.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.common.util.HttpClientUtil;
+import com.gyee.monitor.model.auto.Windpowerstationpointnew;
+import com.gyee.monitor.model.auto.Windturbinetestingpointnew;
+import com.gyee.monitor.util.realtimesource.timeseries.ErrorRequest;
+import com.gyee.monitor.util.realtimesource.timeseries.JsonObjectHelper;
+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 MongoEdosUtil implements IEdosUtil {
+
+    private RestTemplate restTemplate =new RestTemplate();
+    private static String baseURL = "http://10.83.68.97:8090/mogodb";
+    @Override
+    public PointData getRealData(Windpowerstationpointnew point) throws Exception {
+        try {
+            Optional<String> keys = Optional.ofNullable(point.getCode());
+
+
+            String url = baseURL + "/getRealData.action?";
+            if (keys.isPresent())
+                url = url + "point=" + keys.get();
+            String s = HttpClientUtil.doGet(url);
+            JSONObject jsonObject=JSONObject.parseObject(s);
+            PointData pointData = JSONObject.toJavaObject(jsonObject, PointData.class);
+            return pointData;
+        } catch (HttpClientErrorException exception) {
+            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
+                System.out.println("404请求错误");
+                return ErrorRequest.RequestError(point.getCode());
+            } else {
+                throw exception;
+            }
+        }
+    }
+
+
+
+
+    @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);
+        Optional<Long> endTs = Optional.ofNullable(endDate);
+        Optional<Long> counts = Optional.ofNullable(count);
+        Optional<Long> prieds = Optional.ofNullable(pried);
+        //通过时间区间和时间间隔获取点数
+
+
+        try {
+            String url = baseURL + "/getHistoryDatasSnap.action?";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "point=" + tagName.get();
+            if (startTs.isPresent())
+                url = url + "&begin=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&end=" + endTs.get();
+            if (counts.isPresent())
+                url = url + "&count=" + counts.get();
+            if (prieds.isPresent())
+                url = url + "&pried=" + prieds.get();
+            String s = HttpClientUtil.doGet(url);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+
+            return pointDatas;
+
+
+
+
+        } 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> 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);
+        Optional<Long> endTs = Optional.ofNullable(endDate);
+
+        try {
+            String url = baseURL + "/getHistoryDatasRaw.action?";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "point=" + tagName.get();
+
+
+            if (startTs.isPresent())
+                url = url + "&begin=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&end=" + endTs.get();
+
+            String s = HttpClientUtil.doGet(url);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+           return pointDatas;
+
+        } 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 + "/getRealData.action?";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (keys.isPresent())
+                url = url + "point=" + keys.get();
+
+            String s = HttpClientUtil.doGet(url);
+            JSONObject jsonObject=JSONObject.parseObject(s);
+            PointData pointData = JSONObject.toJavaObject(jsonObject, PointData.class);
+            return pointData;
+
+        } 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 {
+
+        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);
+        Optional<Long> counts = Optional.ofNullable(count);
+        Optional<Long> prieds = Optional.ofNullable(pried);
+        //通过时间区间和时间间隔获取点数
+
+        try {
+            String url = baseURL + "/getHistoryDatasSnap.action?";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "point=" + tagName.get();
+
+            if (startTs.isPresent())
+                url = url + "&begin=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&end=" + endTs.get();
+            if (counts.isPresent())
+                url = url + "&count=" + counts.get();
+            if (prieds.isPresent())
+                url = url + "&pried=" + prieds.get();
+
+            String s = HttpClientUtil.doGet(url);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+            return pointDatas;
+        } 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.getId());
+        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 + "/getHistoryDatasRaw.action?";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "point=" + tagName.get();
+            if (startTs.isPresent())
+                url = url + "&begin=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&end=" + endTs.get();
+
+            String s = HttpClientUtil.doGet(url);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+            return pointDatas;
+        } 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 + "/getRealData.action?";
+        try {
+            if (keys.isPresent())
+                url = url + "point=" + keys.get();
+            else
+                return null;
+
+            String s = HttpClientUtil.doGet(url);
+            JSONObject jsonObject=JSONObject.parseObject(s);
+            PointData pointData = JSONObject.toJavaObject(jsonObject, PointData.class);
+            return pointData;
+
+        } 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 + "/getRealData.action?1=1";
+        try {
+            if (keys.isPresent())
+                url = url + "&point=" + keys.get();
+            else {
+                return ErrorRequest.RequestListError(pointids);
+            }
+            String s = HttpClientUtil.doGet(url);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+            return pointDatas;
+
+
+
+        } 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 + "/getRealDatas.action?";
+        Map<String,Object> paramMap = new HashMap<>();
+        paramMap.put("points",pointIdString);
+        try {
+//            if (keys.isPresent())
+//                url = url + "points=" + keys.get();
+//            else {
+//                String[] arr = new String[pointids.size()];
+//                return ErrorRequest.RequestListError(pointids.toArray(arr));
+//            }
+            String s = HttpClientUtil.doPost(url,paramMap);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+            return pointDatas;
+
+        } 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 {
+        return null;
+    }
+
+
+	  @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);
+	        Optional<Long> endTs = Optional.ofNullable(endDate);
+          Optional<Long> counts = Optional.ofNullable(count);
+          Optional<Long> prieds = Optional.ofNullable(pried);
+
+
+          try {
+              String url = baseURL + "/getHistoryDatasSnap.action?";
+              //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+              if (tagName.isPresent())
+                  url = url + "point=" + tagName.get();
+
+              if (startTs.isPresent())
+                  url = url + "&begin=" + startTs.get();
+              if (endTs.isPresent())
+                  url = url + "&end=" + endTs.get();
+              if (counts.isPresent())
+                  url = url + "&count=" + counts.get();
+              if (prieds.isPresent())
+                  url = url + "&pried=" + prieds.get();
+
+
+              String s = HttpClientUtil.doGet(url);
+              List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+              return pointDatas;
+
+
+	        } 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);
+        Optional<Long> endTs = Optional.ofNullable(endDate);
+        Optional<Long> counts = Optional.ofNullable(count);
+        Optional<Long> prieds = Optional.ofNullable(pried);
+        Optional<Integer> types = Optional.ofNullable(type);
+
+
+        try {
+            String url = baseURL + "/getHistStat.action?";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "point=" + tagName.get();
+            if (startTs.isPresent())
+                url = url + "&begin=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&end=" + endTs.get();
+            if (counts.isPresent())
+                url = url + "&count=" + counts.get();
+            if (prieds.isPresent())
+                url = url + "&pried=" + prieds.get();
+            if (types.isPresent())
+                url = url + "&type=" + types.get();
+
+            String s = HttpClientUtil.doGet(url);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+            return pointDatas;
+        } 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);
+        Optional<Long> counts = Optional.ofNullable(count);
+        Optional<Long> prieds = Optional.ofNullable(pried);
+        Optional<Integer> types = Optional.ofNullable(type);
+
+
+        try {
+            String url = baseURL + "/getHistStat.action?";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "point=" + tagName.get();
+
+            if (startTs.isPresent())
+                url = url + "&begin=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&end=" + endTs.get();
+            if (counts.isPresent())
+                url = url + "&count=" + counts.get();
+            if (prieds.isPresent())
+                url = url + "&pried=" + prieds.get();
+            if (types.isPresent())
+                url = url + "&type=" + types.get();
+
+            String s = HttpClientUtil.doGet(url);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+            return pointDatas;
+        } 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);
+        Optional<Long> counts = Optional.ofNullable(count);
+        Optional<Long> prieds = Optional.ofNullable(pried);
+        Optional<Integer> types = Optional.ofNullable(type);
+
+
+        try {
+            String url = baseURL + "/getHistStat.action?";
+            //tagName 或thingType,thingId,uniformCode可以确定一个标签点
+            if (tagName.isPresent())
+                url = url + "point=" + tagName.get();
+
+            if (startTs.isPresent())
+                url = url + "&begin=" + startTs.get();
+            if (endTs.isPresent())
+                url = url + "&end=" + endTs.get();
+            if (counts.isPresent())
+                url = url + "&count=" + counts.get();
+            if (prieds.isPresent())
+                url = url + "&pried=" + prieds.get();
+            if (types.isPresent())
+                url = url + "&type=" + types.get();
+
+            String s = HttpClientUtil.doGet(url);
+            List<PointData> pointDatas = JSONArray.parseArray(s, PointData.class);
+            return pointDatas;
+        } 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()*1000);
+        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;
+        }
+    }
+
+
+}

+ 14 - 6
web/monitor-web/src/main/java/com/gyee/monitor/websocket/MonitorSocket.java

@@ -1,5 +1,8 @@
 package com.gyee.monitor.websocket;
 
+import com.alibaba.druid.support.logging.Log;
+import com.alibaba.druid.support.logging.LogFactory;
+import com.alibaba.fastjson.JSON;
 import org.springframework.stereotype.Component;
 
 import javax.websocket.*;
@@ -17,6 +20,8 @@ import java.util.concurrent.ConcurrentHashMap;
 @ServerEndpoint(value = "/monitor/{module}")
 @Component
 public class MonitorSocket {
+
+    private Log log = LogFactory.getLog(MonitorSocket.class);
     /**
      * 静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
      */
@@ -34,7 +39,6 @@ public class MonitorSocket {
     private Session session;
 
 
-    private  String module;
     /**
      * 连接建立成功调用的方法
      * <p>
@@ -42,18 +46,19 @@ public class MonitorSocket {
      */
     @OnOpen
     public void onOpen(@PathParam("module") String module, Session session) {
+
         this.session = session;
-        this.module = module;
         webSocketSet.put(module,this);    //加入set中
         addOnlineCount();           //在线数加1
-        System.out.println("有新连接加入!当前在线人数为" + getOnlineCount());
+        System.out.println("有个傻屌来了,!  当前在线人数为" + getOnlineCount());
         try {
-            sendMessage("连接已建立成功.");
+            sendMessage(JSON.toJSONString("连接已建立成功."));
         } catch (Exception e) {
             System.out.println("IO异常");
         }
     }
 
+
     /**
      * 连接关闭调用的方法
      * <p>
@@ -63,7 +68,9 @@ public class MonitorSocket {
     public void onClose() {
         webSocketSet.remove(this);  //连接关闭后,将此websocket从set中删除
         subOnlineCount();           //在线数减1
-        System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
+        System.out.println("有个傻屌走了!   当前在线人数为"+ getOnlineCount());
+
+
     }
 
     /**
@@ -85,7 +92,8 @@ public class MonitorSocket {
 
     // 发送消息,在定时任务中会调用此方法
     public void sendMessage(String message) throws IOException {
-        this.session.getBasicRemote().sendText(message);
+        if (webSocketSet.containsKey(this))
+            this.session.getBasicRemote().sendText(message);
 
     }
 

+ 1 - 1
web/monitor-web/src/main/resources/application-test.yml

@@ -98,4 +98,4 @@ logging:
 
 
 golden:
-  baseURL: http://10.83.68.205:8011/ts
+  baseURL: http://10.83.68.97:8011/ts

+ 2 - 2
web/monitor-web/src/main/resources/application.yml

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

+ 1 - 1
web/pom.xml

@@ -24,7 +24,7 @@
         <module>healthmanagement-web-hb</module>
         <module>monitor-web</module>
         <module>monitor-web-hbnew</module>
-        <module>monitor-web-hb</module>
+<!--        <module>monitor-web-hb</module>-->
 
     </modules>