Browse Source

健康推荐计算服务

shilin 3 years ago
parent
commit
0fe2ac84cd

+ 27 - 1
realtime/healthmodel-server-cph/pom.xml

@@ -10,11 +10,19 @@
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>healthmodel-server-cph</artifactId>
+
+
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
-        <java.version>1.8</java.version>
+        <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>
         <commons.io.version>2.5</commons.io.version>
+        <groovy.version>3.0.8</groovy.version>
+        <spring-boot.version>2.3.7.RELEASE</spring-boot.version>
+
     </properties>
     <dependencies>
 
@@ -110,6 +118,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 - 25
realtime/healthmodel-server-cph/src/main/java/com/gyee/healthmodel/task/SaticScheduleTask.java

@@ -4,11 +4,11 @@ package com.gyee.healthmodel.task;
 import com.gyee.healthmodel.service.HealthJudgeService;
 import com.gyee.healthmodel.service.LosspowerratesService;
 import com.gyee.healthmodel.service.RecommenmainsService;
+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;
 
@@ -18,8 +18,7 @@ import javax.annotation.Resource;
  * @Date: 2021/1/21 19:43
  * @Description : 调度
  */
-@Configuration      //1.主要用于标记配置类,兼备Component的效果。
-@EnableScheduling   // 2.开启定时任务
+@Component
 public class SaticScheduleTask {
 
     private static Logger logger = LoggerFactory.getLogger(SaticScheduleTask.class);
@@ -35,13 +34,14 @@ public class SaticScheduleTask {
     /**
      * 风机损失率统计
      */
-    @Scheduled(cron = "0 37 1 * * ?")
+    //@Scheduled(cron = "0 37 1 * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks1()  {
+    @XxlJob("healthmodel-wtLossRateStatistics")
+    public void configureTasks1()  {
 
 
-        logger.info("风机损失率统计调度程序执行开始!........");
+        XxlJobHelper.log("风机损失率统计调度程序执行开始!........");
 
         try {
 
@@ -51,19 +51,20 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("风机损失率统计调度任务处理完成!........");
+        XxlJobHelper.log("风机损失率统计调度任务处理完成!........");
     }
 
     /**
      * 风机健康诊断
      */
-    @Scheduled(cron = "0 45 7 * * ?")
+    //@Scheduled(cron = "0 45 7 * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks2()  {
+    @XxlJob("healthmodel-wtHealthDiagnosis")
+    public void configureTasks2()  {
 
 
-        logger.info("风机健康诊断调度程序执行开始!........");
+        XxlJobHelper.log("风机健康诊断调度程序执行开始!........");
 
         try {
 
@@ -73,19 +74,20 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("风机健康诊断调度任务处理完成!........");
+        XxlJobHelper.log("风机健康诊断调度任务处理完成!........");
     }
 
     /**
      * 风机健康推荐检修
      */
-    @Scheduled(cron = "0 20 8 * * ?")
+    //@Scheduled(cron = "0 20 8 * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks3()  {
+    @XxlJob("healthmodel-wtHealthRecommended")
+    public void configureTasks3()  {
 
 
-        logger.info("风机健康推荐检修调度程序执行开始!........");
+        XxlJobHelper.log("风机健康推荐检修调度程序执行开始!........");
 
         try {
 
@@ -95,20 +97,21 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("风机健康推荐检修调度任务处理完成!........");
+        XxlJobHelper.log("风机健康推荐检修调度任务处理完成!........");
     }
 
 
     /**
      * 风机报警统计
      */
-    @Scheduled(cron = "0 0 2 * * ?")
+    //@Scheduled(cron = "0 0 2 * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks4()  {
+    @XxlJob("healthmodel-wtAlarmStatistics")
+    public void configureTasks4()  {
 
 
-        logger.info("风机报警统计调度程序执行开始!........");
+        XxlJobHelper.log("风机报警统计调度程序执行开始!........");
 
         try {
 
@@ -118,7 +121,7 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("风机报警统计调度任务处理完成!........");
+        XxlJobHelper.log("风机报警统计调度任务处理完成!........");
     }
 
 
@@ -126,13 +129,14 @@ public class SaticScheduleTask {
     /**
      * 部件报警统计
      */
-    @Scheduled(cron = "0 0 3 * * ?")
+    //@Scheduled(cron = "0 0 3 * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
-    private void configureTasks5()  {
+    @XxlJob("healthmodel-partAlarmStatistics")
+    public void configureTasks5()  {
 
 
-        logger.info("部件报警统计调度程序执行开始!........");
+        XxlJobHelper.log("部件报警统计调度程序执行开始!........");
 
         try {
 
@@ -142,6 +146,6 @@ public class SaticScheduleTask {
             e.printStackTrace();
         }
 
-        logger.info("部件报警统计调度任务处理完成!........");
+        XxlJobHelper.log("部件报警统计调度任务处理完成!........");
     }
 }

+ 2 - 4
realtime/healthmodel-server-cph/src/main/java/com/gyee/healthmodel/util/IRealTimeDataBaseUtil.java

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

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

@@ -156,7 +156,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);
@@ -165,7 +165,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);
@@ -174,7 +174,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);
@@ -231,7 +231,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);
@@ -240,7 +240,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);
@@ -443,7 +443,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);
@@ -452,7 +452,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);
@@ -461,7 +461,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);
@@ -612,7 +612,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);
@@ -627,32 +627,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();
@@ -757,7 +750,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);
@@ -781,27 +774,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()) {
@@ -1037,7 +1022,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);
@@ -1046,7 +1031,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);
@@ -1055,7 +1040,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);
@@ -1470,7 +1455,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 {
@@ -1497,57 +1489,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 {
@@ -1653,20 +1675,5 @@ public class EdosUtil implements IRealTimeDataBaseUtil {
 
     }
 
-    @Override
-    public void sendSinglePoint(PointData point) throws Exception {
-
-    }
-
-    @Override
-    public void sendMultiPoint(List<PointData> pointls) throws Exception {
-
-    }
-
-    @Override
-    public void sendMultiPoint(String[] realvalue, DNAVal[] pointls) throws Exception {
-
-    }
-
 
 }