Sfoglia il codice sorgente

故障统计计算服务

shilin 3 anni fa
parent
commit
d95fc15598

+ 29 - 0
realtime/failurestatistics-server-cph/pom.xml

@@ -11,7 +11,18 @@
 
     <artifactId>failurestatistics-server-cph</artifactId>
 
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <maven.compiler.encoding>UTF-8</maven.compiler.encoding>
+        <maven.compiler.source>1.8</maven.compiler.source>
+        <maven.compiler.target>1.8</maven.compiler.target>
+        <maven.test.skip>true</maven.test.skip>
 
+        <groovy.version>3.0.8</groovy.version>
+        <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
+
+    </properties>
     <dependencies>
 
         <dependency>
@@ -106,6 +117,24 @@
             </exclusions>
 
         </dependency>
+
+
+        <!-- ********************** plugin ********************** -->
+        <!-- groovy-all -->
+        <dependency>
+            <groupId>org.codehaus.groovy</groupId>
+            <artifactId>groovy</artifactId>
+            <version>${groovy.version}</version>
+        </dependency>
+
+        <!-- xxl-job-core -->
+        <dependency>
+            <groupId>com.xuxueli</groupId>
+            <artifactId>xxl-job-core</artifactId>
+            <version>2.3.1-SNAPSHOT</version>
+            <scope>system</scope>
+            <systemPath>${basedir}/lib/xxl-job-core-2.3.1-SNAPSHOT.jar</systemPath>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 29 - 27
realtime/failurestatistics-server-cph/src/main/java/com/gyee/failurestatistics/task/SaticScheduleTask.java

@@ -1,15 +1,13 @@
 package com.gyee.failurestatistics.task;
 
 
-
-
 import com.gyee.common.util.DateUtils;
 import com.gyee.failurestatistics.service.*;
+import com.xxl.job.core.context.XxlJobHelper;
+import com.xxl.job.core.handler.annotation.XxlJob;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.util.Date;
@@ -20,8 +18,7 @@ import java.util.Date;
  * @Date: 2021/1/21 19:43
  * @Description : 调度
  */
-@Configuration      //1.主要用于标记配置类,兼备Component的效果。
-@EnableScheduling   // 2.开启定时任务
+@Component
 public class SaticScheduleTask {
 
     private static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class);
@@ -41,13 +38,14 @@ public class SaticScheduleTask {
     /**
      * 故障统计
      */
-    @Scheduled(cron = "0 40 0 * * ?")
+    //@Scheduled(cron = "0 40 0 * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks1()  {
+    @XxlJob("failurestatistics-faultStatistics")
+    public void configureTasks1()  {
 
 
-        logger.info("故障统计调度程序执行开始!........");
+        XxlJobHelper.log("故障统计调度程序执行开始!........");
 
         try {
 
@@ -58,19 +56,20 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("故障统计调度任务处理完成!........");
+        XxlJobHelper.log("故障统计调度任务处理完成!........");
     }
 
     /**
      * 报警统计
      */
-    @Scheduled(cron = "0 50 0 * * ?")
+    //@Scheduled(cron = "0 50 0 * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks2()  {
+    @XxlJob("failurestatistics-alarmStatistics")
+    public void configureTasks2()  {
 
 
-        logger.info("报警统计调度程序执行开始!........");
+        XxlJobHelper.log("报警统计调度程序执行开始!........");
 
         try {
 
@@ -81,20 +80,21 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("报警统计调度任务处理完成!........");
+        XxlJobHelper.log("报警统计调度任务处理完成!........");
     }
 
 
     /**
      * 部件功率统计
      */
-    @Scheduled(cron = "0 20 1 * * ?")
+    //@Scheduled(cron = "0 20 1 * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks3()  {
+    @XxlJob("failurestatistics-componentPowerStatistics")
+    public void configureTasks3()  {
 
 
-        logger.info("部件功率统计调度程序执行开始!........");
+        XxlJobHelper.log("部件功率统计调度程序执行开始!........");
 
         try {
 
@@ -105,19 +105,20 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("部件功率统计调度任务处理完成!........");
+        XxlJobHelper.log("部件功率统计调度任务处理完成!........");
     }
 
     /**
      * 部件健康状态统计
      */
-    @Scheduled(cron = "0 30 1 * * ?")
+    //@Scheduled(cron = "0 30 1 * * ?")
     //或直接指定时间间隔,例如:5 秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks4()  {
+    @XxlJob("failurestatistics-componentHealthStatistics")
+    public void configureTasks4()  {
 
 
-        logger.info("部件健康状态统计调度程序执行开始!........");
+        XxlJobHelper.log("部件健康状态统计调度程序执行开始!........");
 
         try {
 
@@ -128,19 +129,20 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("部件健康状态统计调度任务处理完成!........");
+        XxlJobHelper.log("部件健康状态统计调度任务处理完成!........");
     }
 
     /**
      * 部件温度统计
      */
-    @Scheduled(cron = "0 40 1 * * ?")
+    //@Scheduled(cron = "0 40 1 * * ?")
     //或直接指定时间间隔,例如:5 秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks5()  {
+    @XxlJob("failurestatistics-componentTemperatureStatistics")
+    public void configureTasks5()  {
 
 
-        logger.info("部件温度统计调度程序执行开始!........");
+        XxlJobHelper.log("部件温度统计调度程序执行开始!........");
 
         try {
 
@@ -151,7 +153,7 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("部件温度统计调度任务处理完成!........");
+        XxlJobHelper.log("部件温度统计调度任务处理完成!........");
     }
 
 }

+ 5 - 0
realtime/failurestatistics-server-cph/src/main/java/com/gyee/failurestatistics/util/IRealTimeDataBaseUtil.java

@@ -207,4 +207,9 @@ public interface IRealTimeDataBaseUtil {
      * @throws Exception
      */
     public DNAVal[] getHistMatrix(String[] nameList, long tTime) throws Exception;
+
+
+    public void sendSinglePoint(PointData point) throws Exception;
+
+    public void sendMultiPoint(List<PointData> pointls) throws Exception;
 }

+ 120 - 98
realtime/failurestatistics-server-cph/src/main/java/com/gyee/failurestatistics/util/realtimesource/EdosUtil.java

@@ -155,7 +155,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                                     else{
                                         PointData data = new PointData();
                                         data.setEdnaId(point.getCode());
-                                        data.setPointTime(snapItem.getPointTime());
+                                        data.setPointTime(0L);
                                         data.setPointValue("0");
                                         data.setPointName("1");
                                         data.setPointValueInDouble(0.0);
@@ -164,7 +164,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                                 } else {
                                     PointData data = new PointData();
                                     data.setEdnaId(point.getCode());
-                                    data.setPointTime(snapItem.getPointTime());
+                                    data.setPointTime(0l);
                                     data.setPointValue("0");
                                     data.setPointName("1");
                                     data.setPointValueInDouble(0.0);
@@ -173,7 +173,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                             } else {
                                 PointData data = new PointData();
                                 data.setEdnaId(point.getCode());
-                                data.setPointTime(snapItem.getPointTime());
+                                data.setPointTime(0l);
                                 data.setPointValue("0");
                                 data.setPointName("1");
                                 data.setPointValueInDouble(0.0);
@@ -230,7 +230,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                 else{
                     PointData data = new PointData();
                     data.setEdnaId(pointid);
-                    data.setPointTime(sectionlist.get(0).getPointTime());
+                    data.setPointTime(0L);
                     data.setPointValue("0");
                     data.setPointName("1");
                     data.setPointValueInDouble(0.0);
@@ -239,7 +239,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
             } else {
                 PointData data = new PointData();
                 data.setEdnaId(pointid);
-                data.setPointTime(sectionlist.get(0).getPointTime());
+                data.setPointTime(0L);
                 data.setPointValue("0");
                 data.setPointName("1");
                 data.setPointValueInDouble(0.0);
@@ -442,7 +442,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                                     else{
                                         PointData data = new PointData();
                                         data.setEdnaId(point.getCode());
-                                        data.setPointTime(snapItem.getPointTime());
+                                        data.setPointTime(0L);
                                         data.setPointValue("0");
                                         data.setPointName("1");
                                         data.setPointValueInDouble(0.0);
@@ -451,7 +451,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                                 } else {
                                     PointData data = new PointData();
                                     data.setEdnaId(point.getCode());
-                                    data.setPointTime(snapItem.getPointTime());
+                                    data.setPointTime(0l);
                                     data.setPointValue("0");
                                     data.setPointName("1");
                                     data.setPointValueInDouble(0.0);
@@ -460,7 +460,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                             } else {
                                 PointData data = new PointData();
                                 data.setEdnaId(point.getCode());
-                                data.setPointTime(snapItem.getPointTime());
+                                data.setPointTime(0l);
                                 data.setPointValue("0");
                                 data.setPointName("1");
                                 data.setPointValueInDouble(0.0);
@@ -611,7 +611,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                     idls.add(str);
                 }
             }
-            if(!idls.isEmpty()  )
+            if(!idls.isEmpty() )
             {
                 String pointIdString = StringUtil.join(idls.toArray(), ",");
                 Optional<String> keys = Optional.ofNullable(pointIdString);
@@ -626,32 +626,25 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                     JSONObject jsonObject = resp.getBody();
                     if (jsonObject != null) {
                         //对结果进行有序返回
-                        int len = idls.size();
+                        int len = pointids.length;
                         List<PointData> result = new ArrayList<>();
                         HashMap<String, PointData> pointDataHashMap = new HashMap<>();
                         for (int i = 0; i < len; i++) {
 
 
-                            PointData pd = new PointData();
-                            pd.setPointName(pointids[i]);
-                            pd.setEdnaId(pointids[i]);
-                            pd.setPointValueInDouble(0.0);
-                            pd.setPointTime(0l);
-                            result.add(pd);
-
-                            pointDataHashMap.put(pd.getPointName(), pd);
+                            if (pointDataHashMap.containsKey(pointids[i]) == false){
+                                PointData pd = new PointData();
+                                pd.setPointName(idls.get(i));
+                                pd.setEdnaId(idls.get(i));
+                                pd.setPointValueInDouble(0.0);
+                                pd.setPointTime(0l);
+                                result.add(pd);
 
-//                            if (pointDataHashMap.containsKey(idls.get(i)) == false){
-//                                PointData pd = new PointData();
-//                                pd.setPointName(idls.get(i));
-//                                pd.setEdnaId(idls.get(i));
-//                                result.add(pd);
-//
-//                                pointDataHashMap.put(pd.getPointName(), pd);
-//                            }
-//                            else{
-//                                result.add(pointDataHashMap.get(idls.get(i)));
-//                            }
+                                pointDataHashMap.put(pd.getPointName(), pd);
+                            }
+                            else{
+                                result.add(pointDataHashMap.get(idls.get(i)));
+                            }
 
                         }
                         Iterator<String> sIterator = jsonObject.keySet().iterator();
@@ -756,7 +749,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                     idls.add(str);
                 }
             }
-            if(!idls.isEmpty()   )
+            if(!idls.isEmpty())
             {
                 String pointIdString = StringUtil.join(idls.toArray(), ",");
                 Optional<String> keys = Optional.ofNullable(pointIdString);
@@ -780,27 +773,19 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                         HashMap<String, PointData> pointDataHashMap = new HashMap<>();
                         for (int i = 0; i < len; i++) {
 
-                            PointData pd = new PointData();
-                            pd.setPointName(pointids.get(i));
-                            pd.setEdnaId(pointids.get(i));
-                            pd.setPointValueInDouble(0.0);
-                            pd.setPointTime(0l);
-                            result.add(pd);
-
-                            pointDataHashMap.put(pd.getPointName(), pd);
+                            if (pointDataHashMap.containsKey(pointids.get(i)) == false){
+                                PointData pd = new PointData();
+                                pd.setPointName(idls.get(i));
+                                pd.setEdnaId(idls.get(i));
+                                pd.setPointValueInDouble(0.0);
+                                pd.setPointTime(0l);
+                                result.add(pd);
 
-
-//                            if (pointDataHashMap.containsKey(idls.get(i)) == false){
-//                                PointData pd = new PointData();
-//                                pd.setPointName(idls.get(i));
-//                                pd.setEdnaId(idls.get(i));
-//                                result.add(pd);
-//
-//                                pointDataHashMap.put(pd.getPointName(), pd);
-//                            }
-//                            else{
-//                                result.add(pointDataHashMap.get(idls.get(i)));
-//                            }
+                                pointDataHashMap.put(pd.getPointName(), pd);
+                            }
+                            else{
+                                result.add(pointDataHashMap.get(idls.get(i)));
+                            }
                         }
                         Iterator<String> sIterator = jsonObject.keySet().iterator();
                         while (sIterator.hasNext()) {
@@ -1036,7 +1021,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                                     else{
                                         PointData data = new PointData();
                                         data.setEdnaId(pointid);
-                                        data.setPointTime(snapItem.getPointTime());
+                                        data.setPointTime(0L);
                                         data.setPointValue("0");
                                         data.setPointName("1");
                                         data.setPointValueInDouble(0.0);
@@ -1045,7 +1030,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                                 } else {
                                     PointData data = new PointData();
                                     data.setEdnaId(pointid);
-                                    data.setPointTime(snapItem.getPointTime());
+                                    data.setPointTime(0l);
                                     data.setPointValue("0");
                                     data.setPointName("1");
                                     data.setPointValueInDouble(0.0);
@@ -1054,7 +1039,7 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                             } else {
                                 PointData data = new PointData();
                                 data.setEdnaId(pointid);
-                                data.setPointTime(snapItem.getPointTime());
+                                data.setPointTime(0l);
                                 data.setPointValue("0");
                                 data.setPointName("1");
                                 data.setPointValueInDouble(0.0);
@@ -1469,7 +1454,14 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
                     PointData po = getRealData(tagNames[i]);
                     DNAVal val = new DNAVal();
                     val.DValue = po.getPointValueInDouble();
-                    val.Time = Integer.valueOf(String.valueOf(po.getPointTime()));
+                    if(StringUtils.notEmp(po.getPointTime()))
+                    {
+                        val.Time = Integer.valueOf(String.valueOf(po.getPointTime()));
+                    }else
+                    {
+                        val.Time = 0;
+                    }
+
                     val.Status = 1;
                     result[i] = val;
                 } else {
@@ -1496,57 +1488,87 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
     @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));
+        if(StringUtils.notEmp(pointls) )
+        {
+            for(PointData entity:pointls)
+            {
+                if(StringUtils.notEmp(entity) && !V2Config.getInitialcode().equals(entity.getEdnaId()))
+                {
+                    writeList.add(convertPointData(entity));
+                }
+            }
+            if(!writeList.isEmpty())
+            {
+                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;
+                    }
+                }
+
+            }
         }
-        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";
+
+        if(StringUtils.notEmp(point) && StringUtils.notEmp(point.getEdnaId()) && !V2Config.getInitialcode().equals(point.getEdnaId()))
+        {
+            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 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(List<PointData> pointls) throws Exception {
+
+        String url = baseURL + "/latest/batch";
+
+        List<JSONObject> writeList = new ArrayList<>();
+
+        if(StringUtils.notEmp(pointls) )
+        {
+            for(PointData entity:pointls)
+            {
+                if(StringUtils.notEmp(entity) && !V2Config.getInitialcode().equals(entity.getEdnaId()))
+                {
+                    writeList.add(convertPointData(entity));
+                }
+            }
+            if(!writeList.isEmpty())
+            {
+                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 {