Quellcode durchsuchen

task和配置文件修改

chenminghua vor 3 Jahren
Ursprung
Commit
923bb81c67

+ 3 - 0
gyee-sample-impala/src/main/java/com/gyee/impala/common/config/GyeeConfig.java

@@ -19,6 +19,9 @@ public class GyeeConfig {
     /** 获取配置服务器*/
     private String hostUrl;
 
+    /** 样本数据统计开始时间**/
+    private String initTime;
+
     /***数据模板路径  windows*/
     private String templatePathWindow;
 

+ 98 - 86
gyee-sample-impala/src/main/java/com/gyee/impala/schdule/TaskPerformance.java

@@ -1,5 +1,6 @@
 package com.gyee.impala.schdule;
 
+import com.gyee.impala.common.config.GyeeConfig;
 import com.gyee.impala.common.constant.Constants;
 import com.gyee.impala.common.feign.RemoteServiceBuilder;
 import com.gyee.impala.common.spring.InitialRunner;
@@ -15,19 +16,26 @@ import com.gyee.impala.service.master.WindturbinepointService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
+/**
+ * 基于欠发矩阵的统计
+ */
 //@Component
 @Slf4j
 public class TaskPerformance {
 
-    /**  等间隔查询   分钟 * 秒 **/
-    private final Integer interval = 5 * 60;
-    private final String START_TIME = "2021-01-01 00:00:00";
+    /**  等间隔查询   秒 **/
+    private final Integer interval = 1;
 
     @Autowired
+    private GyeeConfig gyeeConfig;
+    @Autowired
     private RemoteServiceBuilder remoteService;
     @Autowired
     private WindturbinepointService windturbinepointService;
@@ -35,28 +43,34 @@ public class TaskPerformance {
     private CaseperformanceService performanceService;
 
 
-//    @Scheduled(initialDelay = 10 * 1000, fixedRate = 2 * 86400000 * 1000)
+    @Scheduled(initialDelay = 10 * 1000, fixedRate = 2 * 86400000 * 1000)
+//    @Scheduled(cron = "0 40 2 * * ?")
     public void performanceNSS(){
-        InitialRunner.wpMap.forEach((k, v) -> {
-            if (!k.equals("NSS_FDC"))
-                return;
+        if (InitialRunner.wpMap.size() == 0)
+            return;
+
+        Calendar cal = Calendar.getInstance();
+        InitialRunner.wpMap.forEach((k, v) -> v.stream().forEach(wt ->{
+            try{
+                /**********************   关系库获取测点名   ******************************/
+                List<Windturbinepoint> wp_zs = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.AI_FDJZS);
+                List<Windturbinepoint> wp_zt = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.DI_FJMXZT);
+                List<Windturbinepoint> wp_qf = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.DI_RSSQFZT);
+                List<Windturbinepoint> wp_jy = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.AI_JYJD);
+                List<Windturbinepoint> wp_xd = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.DI_XDZT);
+                /**********************   关系库获取测点名   ******************************/
 
-            List<Caseperformance> list = new ArrayList<>();
-            for (int i = 0; i < v.size(); i++){
-                Windturbine wt = v.get(i);
-                try{
-                    /**********************   关系库获取测点名   ******************************/
-                    List<Windturbinepoint> wp_zs = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.AI_FDJZS);
-                    List<Windturbinepoint> wp_zt = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.DI_FJMXZT);
-                    List<Windturbinepoint> wp_qf = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.DI_RSSQFZT);
-                    List<Windturbinepoint> wp_jy = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.AI_JYJD);
-                    List<Windturbinepoint> wp_xd = windturbinepointService.getItemByWtIdAndUniformCode(wt.getId(), Constants.DI_XDZT);
-                    /**********************   关系库获取测点名   ******************************/
+                long time = DateUtil.covertDateTimestamp(gyeeConfig.getInitTime());
+                Caseperformance item = performanceService.getOneMaxTimeByWtId(wt.getId());
+                if (item != null)
+                    time = DateUtil.covertDateTimestamp(item.getEndtime());
 
-                    Caseperformance item = performanceService.getOneMaxTimeByWtId(wt.getId());
-                    long st = DateUtil.covertDateTimestamp(START_TIME);
-                    long et = DateUtil.covertDateTimestamp("2021-03-31 00:00:00");
-//                    long et = item == null ? System.currentTimeMillis() : DateUtil.covertDateTimestamp(item.getEndtime());
+                long currentTime = System.currentTimeMillis();
+                while(time < currentTime){
+                    long st = time;
+                    cal.setTime(new Date(time));
+                    cal.add(Calendar.DATE, 30);
+                    long et = cal.getTimeInMillis();
                     /**********************   Golden读取原始数据   ******************************/
                     List<TsDoubleData> zsData = remoteService.adapter().getHistorySnapAI(wp_zs.get(0).getPoint(), st, et, interval);
                     List<TsDoubleData> ztData = remoteService.adapter().getHistorySnapAI(wp_zt.get(0).getPoint(), st, et, interval);
@@ -65,78 +79,76 @@ public class TaskPerformance {
                     List<TsDoubleData> xdData = remoteService.adapter().getHistorySnapAI(wp_xd.get(0).getPoint(), st, et, interval);
                     /**********************   Golden读取原始数据   ******************************/
 
-                    List<String> lt = new ArrayList<>();
-                    List<String> ls = new ArrayList<>();
-                    for (int j = 0; j < zsData.size(); j++) {
-                        /**性能差**/
-                        if (GyeeUtil.convertNum(wt, zsData.get(j).getDoubleValue()) >= 1400
-                                && ztData.get(j).getDoubleValue() == 2
-                                && qfData.get(j).getDoubleValue() > 3
-                                && jdData.get(j).getDoubleValue() == 0
-                                && xdData.get(j).getDoubleValue() == 0) {
-                            lt.add(DateUtil.format(zsData.get(j).getTs(), DateUtil.DATE_TIME_PATTERN));
-                        }
-                        /**性能好**/
-                        if(GyeeUtil.convertNum(wt, zsData.get(j).getDoubleValue()) >= 1400
-                                && ztData.get(j).getDoubleValue() == 2
-                                && qfData.get(j).getDoubleValue() <= 2
-                                && jdData.get(j).getDoubleValue() == 0
-                                && xdData.get(j).getDoubleValue() == 0){
-                            ls.add(DateUtil.format(zsData.get(j).getTs(), DateUtil.DATE_TIME_PATTERN));
-                        }
-                        /**数据整理保存至kudu**/
-                        if (lt.size() > 1 || ls.size() > 1){
-                            Caseperformance obj = new Caseperformance();
-                            // 统计欠发
-                            if (lt.size() > 1) {
-                                obj.setTag(0);
-                                obj.setStarttime(lt.get(0));
-                                obj.setEndtime(lt.get(lt.size() - 1));
-                                obj.setIntervals(Double.valueOf(String.format("%.1f",(double)(lt.size() * interval) / 3600)));
-                                lt.clear();
-                            }
-                            // 统计不欠发
-                            if (ls.size() > 1) {
-                                obj.setTag(1);
-                                obj.setStarttime(ls.get(0));
-                                obj.setEndtime(ls.get(lt.size() - 1));
-                                obj.setIntervals(Double.valueOf(String.format("%.1f",(double)(ls.size() * interval) / 3600)));
-                                ls.clear();
-                            }
-                            obj.setId(SnowFlakeUtil.generateId());
-                            obj.setStationen(k);
-                            obj.setWindturbineid(wt.getId());
-                            obj.setAlgtype("QFMX");
-                            obj.setModel(wt.getModel());
-                            obj.setStationcn(InitialRunner.stationMap.get(k));
-                            obj.setManufacturer(InitialRunner.wpList.get(InitialRunner.wpList.indexOf(k)).getManufacturer());
-
-                            list.add(obj);
-                        }
+                    /** 分析保存至kudu*/
+                    saveCasePerformance(wt, k, zsData, ztData, qfData, jdData, xdData);
+                    time = et;
+                    try {
+                        Thread.sleep(1000);
+                    } catch (InterruptedException e) {
+                        e.printStackTrace();
                     }
-                    performanceService.insertBatch(list);
-                } catch (Exception e){
-                    log.error(e.getMessage());
                 }
+            } catch (Exception e){
+                log.error(e.getMessage());
             }
-        });
+        }));
     }
 
-    public static void main(String[] args){
-        List<String> list = new ArrayList<>();
-        list.add("qq");
-        list.add("ww");
-        list.add("ee");
-        for (String ls : list){
-            try{
-                if (ls.equals("ww")) {
-                    int i = 9 / 0;
+    private void saveCasePerformance(Windturbine wt, String station, List<TsDoubleData> zsData, List<TsDoubleData> ztData,
+                                     List<TsDoubleData> qfData, List<TsDoubleData> jdData, List<TsDoubleData> xdData  ){
+        List<Caseperformance> list = new ArrayList<>();
+        List<String> lt = new ArrayList<>();
+        List<String> ls = new ArrayList<>();
+        for (int j = 0; j < zsData.size(); j++) {
+            /**性能差**/
+            if (GyeeUtil.convertNum(wt, zsData.get(j).getDoubleValue()) >= 1400
+                    && ztData.get(j).getDoubleValue() == 2
+                    && qfData.get(j).getDoubleValue() > 3
+                    && jdData.get(j).getDoubleValue() == 0
+                    && xdData.get(j).getDoubleValue() == 0) {
+                lt.add(DateUtil.format(zsData.get(j).getTs(), DateUtil.DATE_TIME_PATTERN));
+            }
+            /**性能好**/
+            if(GyeeUtil.convertNum(wt, zsData.get(j).getDoubleValue()) >= 1400
+                    && ztData.get(j).getDoubleValue() == 2
+                    && qfData.get(j).getDoubleValue() <= 2
+                    && jdData.get(j).getDoubleValue() == 0
+                    && xdData.get(j).getDoubleValue() == 0){
+                ls.add(DateUtil.format(zsData.get(j).getTs(), DateUtil.DATE_TIME_PATTERN));
+            }
+            /**数据整理保存至kudu**/
+            if (lt.size() > 1 || ls.size() > 1){
+                Caseperformance obj = new Caseperformance();
+                // 统计欠发
+                if (lt.size() > 1) {
+                    obj.setTag(0);
+                    obj.setStarttime(lt.get(0));
+                    obj.setEndtime(lt.get(lt.size() - 1));
+                    obj.setIntervals(Double.valueOf(String.format("%.1f",(double)(lt.size() * interval) / 3600)));
+                    lt.clear();
+                }
+                // 统计不欠发
+                if (ls.size() > 1) {
+                    obj.setTag(1);
+                    obj.setStarttime(ls.get(0));
+                    obj.setEndtime(ls.get(lt.size() - 1));
+                    obj.setIntervals(Double.valueOf(String.format("%.1f",(double)(ls.size() * interval) / 3600)));
+                    ls.clear();
                 }
+                obj.setId(SnowFlakeUtil.generateId());
+                obj.setStationen(station);
+                obj.setWindturbineid(wt.getId());
+                obj.setAlgtype("QFMX");
+                obj.setModel(wt.getModel());
+                obj.setStationcn(InitialRunner.stationMap.get(station));
+                obj.setManufacturer(InitialRunner.wpList.get(InitialRunner.wpList.indexOf(station)).getManufacturer());
 
-                System.out.println(ls);
-            }catch (Exception e){
-                e.getStackTrace();
+                list.add(obj);
             }
         }
+        performanceService.insertBatch(list);
+    }
+
+    public static void main(String[] args){
     }
 }

+ 6 - 5
gyee-sample-impala/src/main/java/com/gyee/impala/schdule/TaskWarning.java

@@ -3,6 +3,7 @@ package com.gyee.impala.schdule;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.gyee.impala.common.config.GyeeConfig;
 import com.gyee.impala.common.feign.RemoteServiceBuilder;
 import com.gyee.impala.common.spring.InitialRunner;
 import com.gyee.impala.common.util.DateUtil;
@@ -31,8 +32,8 @@ public class TaskWarning {
     private CasewarningscadaService scadaService;
     @Autowired
     private RemoteServiceBuilder remoteService;
-
-    private String initTime = "2022-01-01";
+    @Autowired
+    private GyeeConfig gyeeConfig;
 
 
     /**
@@ -47,7 +48,7 @@ public class TaskWarning {
 
         Calendar cal = Calendar.getInstance();
         InitialRunner.stationMap.forEach((k, v) -> {
-            String time = initTime;
+            String time = gyeeConfig.getInitTime();
             Casewarningcustom custom = customService.getOneMaxTimeByStation(k);
             if (custom != null)
                 time = custom.getTime();
@@ -96,7 +97,7 @@ public class TaskWarning {
      * scada报警同步
      * “30 10 1 * * ?” 每天1点40分30触发任务
      */
-    @Scheduled(cron = "0 55 1 * * ?")
+    @Scheduled(cron = "0 10 2 * * ?")
     //@Scheduled(initialDelay = 10 * 1000, fixedRate = 2 * 86400000 * 1000)
     public void scadaWarningTask(){
         if (InitialRunner.stationMap.size() == 0)
@@ -104,7 +105,7 @@ public class TaskWarning {
 
         Calendar cal = Calendar.getInstance();
         InitialRunner.stationMap.forEach((k, v) -> {
-            String time = initTime;
+            String time = gyeeConfig.getInitTime();
             Casewarningscada scada = scadaService.getOneMaxTimeByStation(k);
             if (scada != null)
                 time = scada.getWarntime();

+ 2 - 5
gyee-sample-impala/src/main/java/com/gyee/impala/service/impl/master/CaseperformanceServiceImpl.java

@@ -68,15 +68,13 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
 
     @Override
     public boolean insertBatch(List<Caseperformance> list) {
-        if (list == null || list.size() == 0)
-            return false;
         try{
             insert(list);
+            return true;
         } catch (Exception e) {
             log.error(e.getMessage());
-            throw new CustomException(ResultCode.ERROR_DATA);
         }
-        return true;
+        return false;
     }
 
 
@@ -89,7 +87,6 @@ public class CaseperformanceServiceImpl extends ServiceImpl<CaseperformanceMappe
             log.error(e.getMessage());
             throw new CustomException(ResultCode.ERROR_DATA);
         }
-
     }
 
     @Override

+ 4 - 2
gyee-sample-impala/src/main/resources/application.yaml

@@ -4,9 +4,11 @@ gyee:
   # 报警url
   alert-url: http://192.168.1.14:8075
   host-url: http://10.155.32.14:8520
+  # 样本数据统计开始时间
+  init-time: 2022-01-01 00:00:00
   # 故障样本数据导入模板路径
   template-path-window: D://java//kudu//template//
-  template-path-linux: /gyee/java/template/
+  template-path-linux: /home/gyee/kudu/template/
   # kudu的host
   kudu-host: 192.168.1.65
   # 故障诊断脚本路径
@@ -74,7 +76,7 @@ hiveconfig:
   port: 22
   username: root
   password: Admin@2019
-  path: /gyee/dataprocess
+  path: /home/gyee/kudu/dataprocess
   driver: org.apache.hive.jdbc.HiveDriver
   url: jdbc:hive2://192.168.1.60:10000/default
 ####################三区大数据服务器 SFTP EXEC 配置####################