Przeglądaj źródła

1.alarm-schedule 修复alertrule2 中ednavalue 相同导致的 诊断报告中风场和风机不一致问题(在针对alarmsnap中添加station的筛选)
2.删除无用的测试代码

wanghs 2 lat temu
rodzic
commit
94dc67001b

+ 2 - 33
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/biz/EarlyReportBiz.java

@@ -72,8 +72,8 @@ public class EarlyReportBiz {
      * @date 2022/8/23
      **/
 
-    public List<AlarmSnap> getAlarmSnap(List<String> alertValueList, String type) {
-        List<AlarmSnap> list = alarmSnapService.list(new QueryWrapper<AlarmSnap>().in("ALERTVALUE", alertValueList).eq("CATEGORY1", type));
+    public List<AlarmSnap> getAlarmSnap(String stationId,List<String> alertValueList, String type) {
+        List<AlarmSnap> list = alarmSnapService.list(new QueryWrapper<AlarmSnap>().in("ALERTVALUE", alertValueList).eq("CATEGORY1", type).eq("STATIONID",stationId));
         return list;
     }
 
@@ -184,35 +184,4 @@ public class EarlyReportBiz {
 
     }
 
-    public static void main(String[] args) {
-        System.out.println(SnowflakeGenerator.generateId());
-        AlarmCount count1 = new AlarmCount();
-        count1.setCount(100);
-        count1.setTime(20.22);
-        count1.setWindturbineId("MG01");
-        AlarmCount count2 = new AlarmCount();
-        count2.setCount(200);
-        count2.setTime(32.22);
-        count2.setWindturbineId("MG01");
-
-        AlarmCount count3 = new AlarmCount();
-        count3.setCount(100);
-        count3.setTime(11.22);
-        count3.setWindturbineId("MG02");
-        AlarmCount count4 = new AlarmCount();
-        count4.setCount(200);
-        count4.setTime(10.22);
-        count4.setWindturbineId("MG03");
-
-        AlarmCount count5 = new AlarmCount();
-        count4.setCount(400);
-        count4.setTime(39.22);
-        count4.setWindturbineId("MG05");
-        List<AlarmCount> alarmCountList = Arrays.asList(count1, count2, count3, count4);
-        EarlyReportBiz earlyReportBiz = new EarlyReportBiz();
-        Map<String, AlarmCount> sumAlarmCountByWindturbine = earlyReportBiz.getSumAlarmCountByWindturbine(alarmCountList, 2);
-        System.out.println("123");
-
-    }
-
 }

+ 61 - 13
schedule-job/alarm-schedule/src/main/java/com/gyee/wisdom/alarm/schedule/biz/EarlyReportTask.java

@@ -11,6 +11,7 @@ import com.gyee.wisdom.alarm.schedule.util.SnowflakeGenerator;
 import com.gyee.wisdom.alarm.schedule.util.SpringContextUtils;
 import com.gyee.wisdom.common.utils.DateUtil;
 import lombok.Data;
+import org.apache.commons.collections.CollectionUtils;
 
 import java.util.*;
 import java.util.concurrent.Callable;
@@ -60,14 +61,14 @@ public class EarlyReportTask implements Callable<TaskResult> {
                 .setStationId(stationId)
                 .setStationName(StationCache.getStationName(stationId))
                 .setRelatedParts(reportParam.getWindturbineParts())
-                .setReportName(StationCache.getStationName(stationId)+"风机"+reportParam.getAnalysisName()+"诊断报告")
+                .setReportName(StationCache.getStationName(stationId) + "风机" + reportParam.getAnalysisName() + "诊断报告")
                 .setStatStartDate(statStartTime)
                 .setStatEndDate(statEndTime)
                 .setReportWindturbineInfoList(new ArrayList<>());
 
         try {
             //获取本次报告最差的风机信息集合
-            List<EarlyReportWindturbine> nowWindturbineInfoList = getNowWindturbineInfo(model, report.getId(), statStartTime, statEndTime, limit);
+            List<EarlyReportWindturbine> nowWindturbineInfoList = getNowWindturbineInfo(stationId,model, report.getId(), statStartTime, statEndTime, limit);
 
             report.getReportWindturbineInfoList().addAll(nowWindturbineInfoList);
             // 获取上次报告
@@ -77,7 +78,7 @@ public class EarlyReportTask implements Callable<TaskResult> {
             if (collect.size() > 0) {
                 //已经进行了排序,因此获取第一个,即为最近一次报告
                 List<EarlyReportWindturbine> reportWindturbineInfoList = collect.get(0).getReportWindturbineInfoList().stream().filter(s -> s.isCompared() == false && !s.getWindturbineId().equals("全场平均")).collect(Collectors.toList());
-                List<EarlyReportWindturbine> compareWindturbineInfoList = getCompareWindturbineInfo(reportWindturbineInfoList, model, report.getId(), statStartTime, statEndTime);
+                List<EarlyReportWindturbine> compareWindturbineInfoList = getCompareWindturbineInfo(stationId,reportWindturbineInfoList, model, report.getId(), statStartTime, statEndTime);
                 report.getReportWindturbineInfoList().addAll(compareWindturbineInfoList);
             }
 
@@ -103,13 +104,13 @@ public class EarlyReportTask implements Callable<TaskResult> {
      * @description 获取本次报告风机信息
      * @date 2022/8/29
      **/
-    private List<EarlyReportWindturbine> getNowWindturbineInfo(String model, String reportId, Date statStartTime, Date statEndTime, int limit) {
+    private List<EarlyReportWindturbine> getNowWindturbineInfo(String stationId,String model, String reportId, Date statStartTime, Date statEndTime, int limit) {
 
         List<EarlyReportWindturbine> resultList = new ArrayList<>();
 
         List<AlertRule2> alertRule2List = earlyReportBiz.getAlertRule2(reportParam.getCustomRuleId());
 
-        List<AlarmSnap> customAlarmSnapList = earlyReportBiz.getAlarmSnap(alertRule2List.stream().map(s -> String.valueOf(s.getEdnaValue())).collect(Collectors.toList()), "custom");
+        List<AlarmSnap> customAlarmSnapList = earlyReportBiz.getAlarmSnap(stationId,alertRule2List.stream().map(s -> String.valueOf(s.getEdnaValue())).collect(Collectors.toList()), "custom");
 
         List<AlarmCount> customAlarmCountList = earlyReportBiz.getAlarmCount(customAlarmSnapList.stream().map(s -> s.getId()).collect(Collectors.toList()), statStartTime, statEndTime);
 
@@ -187,7 +188,9 @@ public class EarlyReportTask implements Callable<TaskResult> {
             resultList.add(reportWindturbine);
         }
 
-        return getConclusion(alertRule2List,resultList);
+        List<EarlyReportWindturbine> earlyReportWindturbineList = checkAndFixData(resultList, alertRule2List);
+
+        return getConclusion(alertRule2List, earlyReportWindturbineList);
 
     }
 
@@ -204,7 +207,7 @@ public class EarlyReportTask implements Callable<TaskResult> {
      * @date 2022/8/29
      **/
 
-    private List<EarlyReportWindturbine> getCompareWindturbineInfo(List<EarlyReportWindturbine> windturbineInfoList, String model, String reportId, Date startTime, Date endTime) {
+    private List<EarlyReportWindturbine> getCompareWindturbineInfo(String stationId,List<EarlyReportWindturbine> windturbineInfoList, String model, String reportId, Date startTime, Date endTime) {
 
         List<EarlyReportWindturbine> resultList = new ArrayList<>();
         List<String> windturbineIdList = windturbineInfoList.stream().map(s -> s.getWindturbineId()).collect(Collectors.toList());
@@ -213,7 +216,7 @@ public class EarlyReportTask implements Callable<TaskResult> {
             reportAlarmList.addAll(s.getAlarmInfoList());
         });
         List<AlertRule2> alertRule2List = earlyReportBiz.getAlertRule2(reportAlarmList.stream().map(s -> s.getRuleId()).collect(Collectors.toList()));
-        List<AlarmSnap> customAlarmSnapList = earlyReportBiz.getAlarmSnap(alertRule2List.stream().map(s -> String.valueOf(s.getEdnaValue())).collect(Collectors.toList()), "custom");
+        List<AlarmSnap> customAlarmSnapList = earlyReportBiz.getAlarmSnap(stationId,alertRule2List.stream().map(s -> String.valueOf(s.getEdnaValue())).collect(Collectors.toList()), "custom");
         List<AlarmCount> customAlarmCountList = earlyReportBiz.getAlarmCount(customAlarmSnapList.stream().map(s -> s.getId()).collect(Collectors.toList()), startTime, endTime);
         Map<String, List<AlarmCount>> windturbineAlarmCountMap = customAlarmCountList.stream().filter(s -> windturbineIdList.contains(s.getWindturbineId())).collect(Collectors.groupingBy(AlarmCount::getWindturbineId));
 
@@ -256,7 +259,9 @@ public class EarlyReportTask implements Callable<TaskResult> {
             }
             resultList.add(reportWindturbine);
         }
-        return resultList;
+
+        List<EarlyReportWindturbine> earlyReportWindturbineList = checkAndFixData(resultList, alertRule2List);
+        return earlyReportWindturbineList;
     }
 
     private List<EarlyReportWindturbine> getConclusion(List<AlertRule2> alertRule2List, List<EarlyReportWindturbine> reportWindturbineList) {
@@ -265,8 +270,8 @@ public class EarlyReportTask implements Callable<TaskResult> {
 
         for (EarlyReportWindturbine windturbineData :
                 reportWindturbineList) {
-            if(!windturbineData.getWindturbineId().equals("全场平均")){
-                StringBuilder firstStr = new StringBuilder("风机"+windturbineData.getWindturbineCode()+":发生");
+            if (!windturbineData.getWindturbineId().equals("全场平均")) {
+                StringBuilder firstStr = new StringBuilder("风机" + windturbineData.getWindturbineCode() + ":发生");
                 for (int i = 0; i < windturbineData.getAlarmInfoList().size(); i++) {
                     EarlyReportAlarm earlyReportAlarm = windturbineData.getAlarmInfoList().get(i);
                     firstStr.append(earlyReportAlarm.getRuleName());
@@ -281,13 +286,13 @@ public class EarlyReportTask implements Callable<TaskResult> {
                     secondStr.append("\b");
                     secondStr.append("\b");
                     secondStr.append("\b");
-                    secondStr.append("-"+listByPart.get(i).getHiddanger());
+                    secondStr.append("-" + listByPart.get(i).getHiddanger());
                     secondStr.append("\n");
 
                     thridStr.append("\b");
                     thridStr.append("\b");
                     thridStr.append("\b");
-                    thridStr.append("-"+listByPart.get(i).getCheckmatter());
+                    thridStr.append("-" + listByPart.get(i).getCheckmatter());
                     thridStr.append("\n");
                 }
                 StringBuilder resultStr = new StringBuilder();
@@ -303,4 +308,47 @@ public class EarlyReportTask implements Callable<TaskResult> {
         return reportWindturbineList;
 
     }
+
+    //数据校验,避免部分规则没有数据的情况
+    public List<EarlyReportWindturbine> checkAndFixData(List<EarlyReportWindturbine> earlyReportWindturbineList,List<AlertRule2> rule2List){
+
+        List<String> ruleIdList = rule2List.stream().map(s -> s.getId()).collect(Collectors.toList());
+        earlyReportWindturbineList.forEach(s -> {
+//            if (!s.getWindturbineId().equals("全场平均") ) {
+                List<EarlyReportAlarm> alarmInfoList = s.getAlarmInfoList();
+                if (alarmInfoList.size() < reportParam.getCustomRuleId().size()) {
+
+                    Collection subtract = CollectionUtils.subtract(ruleIdList, alarmInfoList.stream().map(k -> k.getRuleId()).collect(Collectors.toList()));
+
+                    List<String> arrayList = new ArrayList<String>(subtract);
+
+                    if (arrayList.size() > 0) {
+                        arrayList.stream().forEach(l -> {
+
+                            Optional<AlertRule2> first = rule2List.stream().filter(m -> m.getId().equals(l)).findFirst();
+                            if (first.isPresent()) {
+                                EarlyReportAlarm alarmInfo = new EarlyReportAlarm()
+                                        .setId(String.valueOf(SnowflakeGenerator.generateId()))
+                                        .setRuleId(first.get().getId())
+                                        .setAlarmType("custom")
+                                        .setRuleName(first.get().getName())
+                                        .setRuleDescription(first.get().getDescription())
+                                        .setRank(first.get().getRank())
+                                        .setCount(0)
+                                        .setKeepTime(0)
+                                        .setReportWindturbineId(s.getId());
+                                alarmInfoList.add(alarmInfo);
+                            }
+
+                        });
+                    }
+
+
+                }
+//            }
+
+        });
+
+        return earlyReportWindturbineList;
+    }
 }