|
@@ -1,445 +1,496 @@
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+package com.gyee.alarm.service;
|
|
|
+
|
|
|
+
|
|
|
+import com.gyee.alarm.init.CacheContext;
|
|
|
+import com.gyee.alarm.model.auto.*;
|
|
|
+import com.gyee.alarm.model.vo.AlarmCustomType;
|
|
|
+import com.gyee.alarm.model.vo.AlarmType;
|
|
|
+import com.gyee.alarm.model.vo.AlarmTypeValue;
|
|
|
+import com.gyee.alarm.service.auto.*;
|
|
|
+import com.gyee.alarm.util.SnowflakeGenerator;
|
|
|
+import com.gyee.alarm.util.DateUtils;
|
|
|
+
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.Callable;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class EarlyReportService {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IProEconAlarmInfoService proEconAlarmInfoService;
|
|
|
+ @Resource
|
|
|
+ private IProEconEarlyReportService proEconEarlyReportService;
|
|
|
+ @Resource
|
|
|
+ private IProEconEarlyReportConclusioService proEconEarlyReportConclusioService;
|
|
|
+ @Resource
|
|
|
+ private IAlarmTsService alarmTsService;
|
|
|
+
|
|
|
+
|
|
|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
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public boolean createEarlyReport() {
|
|
|
+
|
|
|
+ boolean result=false;
|
|
|
+
|
|
|
+ Date reportDate = DateUtils.truncate(new Date());
|
|
|
+
|
|
|
+ Date statStartTime = DateUtils.addDays(DateUtils.today(), - interval_day);
|
|
|
+
|
|
|
+ Date statEndTime = DateUtils.today();
|
|
|
+ Map<String,List<ProEconAlarmType>> alarmTypeMap=CacheContext.alarmTypeMap;
|
|
|
+
|
|
|
+ List<ProEconAlarmType> fjtypels=CacheContext.alarmTypeMap.get(AlarmType.FJBJ.getCode());
|
|
|
+
|
|
|
+ List<ProEconAlarmType> gftypels=CacheContext.alarmTypeMap.get(AlarmType.GFBJ.getCode());
|
|
|
+ for(ProBasicEquipment wt: CacheContext.wtls)
|
|
|
+ {
|
|
|
+
|
|
|
+ ProEconEarlyReport report = new ProEconEarlyReport();
|
|
|
+ report.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ report.setReportDate(new Date());
|
|
|
+ report.setStationId(wt.getWindpowerstationId());
|
|
|
+ if(CacheContext.wpmap.containsKey(wt.getWindpowerstationId()))
|
|
|
+ {
|
|
|
+ report.setStationName(CacheContext.wpmap.get(wt.getWindpowerstationId()).getName());
|
|
|
+ }
|
|
|
+ if(wt.getWindpowerstationId().contains("FDC"))
|
|
|
+ {
|
|
|
+ for(ProEconAlarmType fjtype:fjtypels)
|
|
|
+ {
|
|
|
+ report.setRelatedParts(fjtype.getNemCode());
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append(wt.getNemCode()).append(wt.getName()).append(fjtype.getName()).append("诊断报告");
|
|
|
+ report.setReportName(String.valueOf(sb));
|
|
|
+ report.setStatStartDate(statStartTime);
|
|
|
+ report.setStatEndDate(statEndTime);
|
|
|
+ report.setProEconEarlyReportWtList(new ArrayList<>());
|
|
|
+ report.setReportDate(reportDate);
|
|
|
+ report.setStatStartDate(new Date());
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ for(ProEconAlarmType gftype:gftypels)
|
|
|
+ {
|
|
|
+ report.setRelatedParts(gftype.getNemCode());
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
+ sb.append(wt.getNemCode()).append(wt.getName()).append(gftype.getName()).append("诊断报告");
|
|
|
+ report.setReportName(String.valueOf(sb));
|
|
|
+ report.setStatStartDate(statStartTime);
|
|
|
+ report.setStatEndDate(statEndTime);
|
|
|
+ report.setProEconEarlyReportWtList(new ArrayList<>());
|
|
|
+ report.setReportDate(reportDate);
|
|
|
+ report.setStatStartDate(new Date());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ List<ProEconEarlyReportWt> nowWindturbineInfoList = getNowWindturbineInfo(wt,wt.getModelId(), report.getId(),report.getRelatedParts(), statStartTime, statEndTime, limit);
|
|
|
+
|
|
|
+ report.getProEconEarlyReportWtList().addAll(nowWindturbineInfoList);
|
|
|
+
|
|
|
+ List<ProEconEarlyReport> earlyReport = proEconEarlyReportService.findEarlyReportByDate(wt.getId(), DateUtils.addDays(statEndTime, -60), statEndTime);
|
|
|
+ earlyReport=earlyReport.stream().filter(s->s.getRelatedParts().equals(report.getRelatedParts())).collect(Collectors.toList());
|
|
|
+ List<ProEconEarlyReport> collect = earlyReport.stream().sorted(Comparator.comparing(ProEconEarlyReport::getId, Comparator.reverseOrder())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (collect.size() > 0) {
|
|
|
+
|
|
|
+ List<ProEconEarlyReportWt> reportWindturbineInfoList = collect.get(0).getProEconEarlyReportWtList().stream().filter(s -> s.getCompared() == false && !s.getWindturbineId().equals("全场平均")).collect(Collectors.toList());
|
|
|
+ List<ProEconEarlyReportWt> compareWindturbineInfoList = getCompareWindturbineInfo(wt,reportWindturbineInfoList, wt.getModelId(), report.getId(),report.getRelatedParts(), statStartTime, statEndTime);
|
|
|
+ report.getProEconEarlyReportWtList().addAll(compareWindturbineInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ result = proEconEarlyReportService.save(report);
|
|
|
+
|
|
|
+ } catch (RuntimeException ex) {
|
|
|
+
|
|
|
+ } finally {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @param model 风机型号
|
|
|
+ * @param reportId 报告id
|
|
|
+ * @param statStartTime 统计起始时间
|
|
|
+ * @param statEndTime 统计结束时间
|
|
|
+ * @param limit 结果限制数量
|
|
|
+ * @return com.gyee.wisdom.alarm.schedule.entity.ProEconEarlyReportWt
|
|
|
+ **/
|
|
|
+ private List<ProEconEarlyReportWt> getNowWindturbineInfo(ProBasicEquipment wt,String model, String reportId,String relatedParts, Date statStartTime, Date statEndTime, int limit) {
|
|
|
+
|
|
|
+ List<ProEconEarlyReportWt> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<ProEconAlarmRule> alertRule2List = new ArrayList<>();
|
|
|
+ List<String> components= new ArrayList<>();
|
|
|
+ components.add(relatedParts);
|
|
|
+ if(wt.getWindpowerstationId().contains("FDC"))
|
|
|
+ {
|
|
|
+ List<ProEconAlarmRule> rulels=CacheContext.alarmRulesMap.get(AlarmCustomType.WT.getCode());
|
|
|
+
|
|
|
+ if(!rulels.isEmpty())
|
|
|
+ {
|
|
|
+ for(ProEconAlarmRule rule:rulels)
|
|
|
+ {
|
|
|
+ if(rule.getRelatedParts().equals(relatedParts) && rule.getStationId().equals(wt.getWindpowerstationId()) && rule.getModelId().equals(model))
|
|
|
+ {
|
|
|
+ alertRule2List.add(rule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ List<ProEconAlarmRule> rulels=CacheContext.alarmRulesMap.get(AlarmCustomType.IN.getCode());
|
|
|
+
|
|
|
+ if(!rulels.isEmpty())
|
|
|
+ {
|
|
|
+ for(ProEconAlarmRule rule:rulels)
|
|
|
+ {
|
|
|
+ if(rule.getRelatedParts().equals(relatedParts) && rule.getStationId().equals(wt.getWindpowerstationId()) && rule.getModelId().equals(model))
|
|
|
+ {
|
|
|
+ alertRule2List.add(rule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<ProEconAlarmInfo> customAlarmSnapList = proEconAlarmInfoService. queryAlarmInfo(wt.getId(), AlarmTypeValue.CT.getCode());
|
|
|
+ List<String> alarmidls=new ArrayList<>();
|
|
|
+ if(!customAlarmSnapList.isEmpty())
|
|
|
+ {
|
|
|
+ for(ProEconAlarmInfo alarmInfo:customAlarmSnapList)
|
|
|
+ {
|
|
|
+ alarmidls.add(alarmInfo.getAlarmId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<ProBasicFeatureStat> customAlarmCountList = alarmTsService.findCtFeatureStatCustom( statStartTime.getTime(), statEndTime.getTime(),wt.getWindpowerstationId(), wt.getModelId(), components,alarmidls);
|
|
|
+
|
|
|
+ Map<String, List<ProBasicFeatureStat>> alarmCountMapByAlertValue = customAlarmCountList.stream().collect(Collectors.groupingBy(ProBasicFeatureStat::getAlarmid));
|
|
|
+
|
|
|
+ ProEconEarlyReportWt avgWindturbineReport = new ProEconEarlyReportWt();
|
|
|
+ avgWindturbineReport.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ avgWindturbineReport.setWindturbineId("全场平均");
|
|
|
+ avgWindturbineReport.setWindturbineCode("");
|
|
|
+ avgWindturbineReport.setModelId(model);
|
|
|
+ avgWindturbineReport.setCompared(false);
|
|
|
+ avgWindturbineReport.setAlarmInfoList(new ArrayList<>());
|
|
|
+ avgWindturbineReport.setReportId(reportId);
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<ProBasicFeatureStat>> entry :
|
|
|
+ alarmCountMapByAlertValue.entrySet()) {
|
|
|
+ ProBasicFeatureStat avgAlarmCount = proEconEarlyReportService.getAvgAlarmCount(entry.getValue());
|
|
|
+ Optional<ProEconAlarmRule> first = alertRule2List.stream().filter(s -> String.valueOf(s.getId()).equals(entry.getKey())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ ProEconEarlyReportAlarm alarmInfo = new ProEconEarlyReportAlarm();
|
|
|
+ alarmInfo.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ alarmInfo.setRuleId(first.get().getId());
|
|
|
+ alarmInfo.setAlarmType("custom");
|
|
|
+ alarmInfo.setRuleName(first.get().getName());
|
|
|
+ alarmInfo.setRuleDescription(first.get().getDescription());
|
|
|
+ alarmInfo.setRank(String.valueOf(first.get().getRank()));
|
|
|
+ alarmInfo.setCount(avgAlarmCount.getTotal());
|
|
|
+ alarmInfo.setKeepTime(avgAlarmCount.getTotalSeconds());
|
|
|
+ alarmInfo.setReportWindturbineId(avgWindturbineReport.getId());
|
|
|
+
|
|
|
+ avgWindturbineReport.getAlarmInfoList().add(alarmInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ resultList.add(avgWindturbineReport);
|
|
|
+
|
|
|
+ Map<String, ProBasicFeatureStat> sumAlarmCountByWindturbine = proEconEarlyReportService.getSumAlarmCountByWindturbine(customAlarmCountList, limit);
|
|
|
+
|
|
|
+ List<String> windturbineIdList = new ArrayList<>(sumAlarmCountByWindturbine.keySet());
|
|
|
+
|
|
|
+ Map<String, List<ProBasicFeatureStat>> windturbineLimitAlarmCountMap = customAlarmCountList.stream().filter(s -> windturbineIdList.contains(s.getWtId())).collect(Collectors.groupingBy(ProBasicFeatureStat::getWtId));
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<ProBasicFeatureStat>> entry :
|
|
|
+ windturbineLimitAlarmCountMap.entrySet()) {
|
|
|
+ Map<String, Long> sumCountByAlertValue = entry.getValue().stream().collect(Collectors.groupingBy(ProBasicFeatureStat::getAlarmid, Collectors.summingLong(ProBasicFeatureStat::getTotal)));
|
|
|
+ Map<String, Double> sumKeepTimeByAlertValue = entry.getValue().stream().collect(Collectors.groupingBy(ProBasicFeatureStat::getAlarmid, Collectors.summingDouble(ProBasicFeatureStat::getTotalSeconds)));
|
|
|
+
|
|
|
+ ProEconEarlyReportWt reportWindturbine = new ProEconEarlyReportWt();
|
|
|
+ reportWindturbine.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ reportWindturbine.setWindturbineId(entry.getKey());
|
|
|
+ reportWindturbine.setWindturbineCode(wt.getNemCode());
|
|
|
+ reportWindturbine.setModelId(model);
|
|
|
+ reportWindturbine.setCompared(false);
|
|
|
+ reportWindturbine.setAlarmInfoList(new ArrayList<>());
|
|
|
+ reportWindturbine.setReportId(reportId);;
|
|
|
+
|
|
|
+ for (Map.Entry<String, Long> sumCountEntry :
|
|
|
+ sumCountByAlertValue.entrySet()) {
|
|
|
+ Optional<ProEconAlarmRule> first = alertRule2List.stream().filter(s -> String.valueOf(s.getId()).equals(sumCountEntry.getKey())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ ProEconEarlyReportAlarm alarmInfo = new ProEconEarlyReportAlarm();
|
|
|
+ alarmInfo.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ alarmInfo.setRuleId(first.get().getId());
|
|
|
+ alarmInfo.setAlarmType("custom");
|
|
|
+ alarmInfo.setRuleName(first.get().getName());
|
|
|
+ alarmInfo.setRuleDescription(first.get().getDescription());
|
|
|
+ alarmInfo.setRank(String.valueOf(first.get().getRank()));
|
|
|
+ alarmInfo.setCount(sumCountEntry.getValue());
|
|
|
+ alarmInfo.setReportWindturbineId(reportWindturbine.getId());;
|
|
|
+ if (sumKeepTimeByAlertValue.containsKey(sumCountEntry.getKey())) {
|
|
|
+ alarmInfo.setKeepTime(sumKeepTimeByAlertValue.get(sumCountEntry.getKey()).doubleValue());
|
|
|
+ }
|
|
|
+ reportWindturbine.getAlarmInfoList().add(alarmInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultList.add(reportWindturbine);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ProEconEarlyReportWt> earlyReportWindturbineList = checkAndFixData(resultList, alertRule2List);
|
|
|
+
|
|
|
+ return getConclusion(alertRule2List, earlyReportWindturbineList);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * @param
|
|
|
+ * @param windturbineInfoList 需要对比的风机报告信息(上次报告)
|
|
|
+ * @param model 风机型号
|
|
|
+ * @param reportId 本次报告的id
|
|
|
+ * @param startTime 分析起始时间(本次分析)
|
|
|
+ * @param endTime 分析结束时间(本次分析)
|
|
|
+ * @return com.gyee.wisdom.alarm.schedule.entity.ProEconEarlyReportWt
|
|
|
+ * @author Wanghs
|
|
|
+ * @description 获取上次报告中的风机与本周报告对比信息
|
|
|
+ * @date 2022/8/29
|
|
|
+ **/
|
|
|
+
|
|
|
+ private List<ProEconEarlyReportWt> getCompareWindturbineInfo(ProBasicEquipment wt,List<ProEconEarlyReportWt> windturbineInfoList, String model, String reportId,String relatedParts, Date startTime, Date endTime) {
|
|
|
+
|
|
|
+ List<ProEconEarlyReportWt> resultList = new ArrayList<>();
|
|
|
+ List<String> windturbineIdList = windturbineInfoList.stream().map(s -> s.getWindturbineId()).collect(Collectors.toList());
|
|
|
+ List<ProEconEarlyReportAlarm> reportAlarmList = new ArrayList<>();
|
|
|
+ windturbineInfoList.forEach(s -> {
|
|
|
+ reportAlarmList.addAll(s.getAlarmInfoList());
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ List<ProEconAlarmRule> alertRule2List = new ArrayList<>();
|
|
|
+ List<String> components= new ArrayList<>();
|
|
|
+ components.add(relatedParts);
|
|
|
+ if(wt.getWindpowerstationId().contains("FDC"))
|
|
|
+ {
|
|
|
+ List<ProEconAlarmRule> rulels=CacheContext.alarmRulesMap.get(AlarmCustomType.WT.getCode());
|
|
|
+
|
|
|
+ if(!rulels.isEmpty())
|
|
|
+ {
|
|
|
+ for(ProEconAlarmRule rule:rulels)
|
|
|
+ {
|
|
|
+ if(rule.getRelatedParts().equals(relatedParts) && rule.getStationId().equals(wt.getWindpowerstationId()) && rule.getModelId().equals(model))
|
|
|
+ {
|
|
|
+ alertRule2List.add(rule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ List<ProEconAlarmRule> rulels=CacheContext.alarmRulesMap.get(AlarmCustomType.IN.getCode());
|
|
|
+
|
|
|
+ if(!rulels.isEmpty())
|
|
|
+ {
|
|
|
+ for(ProEconAlarmRule rule:rulels)
|
|
|
+ {
|
|
|
+ if(rule.getRelatedParts().equals(relatedParts) && rule.getStationId().equals(wt.getWindpowerstationId()) && rule.getModelId().equals(model))
|
|
|
+ {
|
|
|
+ alertRule2List.add(rule);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ List<ProEconAlarmInfo> customAlarmSnapList = proEconAlarmInfoService. queryAlarmInfo(wt.getId(), AlarmTypeValue.CT.getCode());
|
|
|
+ List<String> alarmidls=new ArrayList<>();
|
|
|
+ if(!customAlarmSnapList.isEmpty())
|
|
|
+ {
|
|
|
+ for(ProEconAlarmInfo alarmInfo:customAlarmSnapList)
|
|
|
+ {
|
|
|
+ alarmidls.add(alarmInfo.getAlarmId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<ProBasicFeatureStat> customAlarmCountList = alarmTsService.findCtFeatureStatCustom( startTime.getTime(), endTime.getTime(),wt.getWindpowerstationId(), wt.getModelId(), components,alarmidls);
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, List<ProBasicFeatureStat>> windturbineAlarmCountMap = customAlarmCountList.stream().filter(s -> windturbineIdList.contains(s.getWtId())).collect(Collectors.groupingBy(ProBasicFeatureStat::getWtId));
|
|
|
+
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<ProBasicFeatureStat>> entry :
|
|
|
+ windturbineAlarmCountMap.entrySet()) {
|
|
|
+ ProEconEarlyReportWt reportWindturbine = new ProEconEarlyReportWt();
|
|
|
+ reportWindturbine.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ reportWindturbine.setWindturbineId(entry.getKey());
|
|
|
+ reportWindturbine.setWindturbineCode(wt.getNemCode());
|
|
|
+ reportWindturbine.setModelId(model);
|
|
|
+ reportWindturbine.setCompared(true);
|
|
|
+ reportWindturbine.setAlarmInfoList(new ArrayList<>());
|
|
|
+ reportWindturbine.setReportId(reportId);
|
|
|
+
|
|
|
+ Optional<ProEconEarlyReportWt> oldReportWindturbine = windturbineInfoList.stream().filter(s -> s.getWindturbineId().equals(entry.getKey())).findFirst();
|
|
|
+ if (oldReportWindturbine.isPresent())
|
|
|
+ reportWindturbine.setCompareId(oldReportWindturbine.get().getId());
|
|
|
+
|
|
|
+ Map<String, Long> sumCountByAlertValue = entry.getValue().stream().collect(Collectors.groupingBy(ProBasicFeatureStat::getAlarmid, Collectors.summingLong(ProBasicFeatureStat::getTotal)));
|
|
|
+ Map<String, Double> sumKeepTimeByAlertValue = entry.getValue().stream().collect(Collectors.groupingBy(ProBasicFeatureStat::getAlarmid, Collectors.summingDouble(ProBasicFeatureStat::getTotalSeconds)));
|
|
|
+
|
|
|
+ for (Map.Entry<String, Long> sumCountEntry :
|
|
|
+ sumCountByAlertValue.entrySet()) {
|
|
|
+ Optional<ProEconAlarmRule> first = alertRule2List.stream().filter(s -> String.valueOf(s.getId()).equals(sumCountEntry.getKey())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ ProEconEarlyReportAlarm alarmInfo = new ProEconEarlyReportAlarm();
|
|
|
+ alarmInfo.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ alarmInfo.setRuleId(first.get().getId());
|
|
|
+ alarmInfo.setAlarmType("custom");
|
|
|
+ alarmInfo.setRuleName(first.get().getName());
|
|
|
+ alarmInfo.setRuleDescription(first.get().getDescription());
|
|
|
+ alarmInfo.setRank(String.valueOf(first.get().getRank()));
|
|
|
+ alarmInfo.setCount(sumCountEntry.getValue());
|
|
|
+ alarmInfo.setReportWindturbineId(reportWindturbine.getId());
|
|
|
+ if (sumKeepTimeByAlertValue.containsKey(sumCountEntry.getKey())) {
|
|
|
+ alarmInfo.setKeepTime(sumKeepTimeByAlertValue.get(sumCountEntry.getKey()).doubleValue());
|
|
|
+ }
|
|
|
+ reportWindturbine.getAlarmInfoList().add(alarmInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ resultList.add(reportWindturbine);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ProEconEarlyReportWt> earlyReportWindturbineList = checkAndFixData(resultList, alertRule2List);
|
|
|
+ return earlyReportWindturbineList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<ProEconEarlyReportWt> getConclusion(List<ProEconAlarmRule> alertRule2List, List<ProEconEarlyReportWt> reportWindturbineList) {
|
|
|
+
|
|
|
+ List<ProEconEarlyReportConclusio> listByPart = proEconEarlyReportConclusioService.getListByPart(alertRule2List.stream().map(s -> s.getRelatedParts()).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ for (ProEconEarlyReportWt windturbineData :
|
|
|
+ reportWindturbineList) {
|
|
|
+ if (!windturbineData.getWindturbineId().equals("全场平均")) {
|
|
|
+ StringBuilder firstStr = new StringBuilder("风机" + windturbineData.getWindturbineCode() + ":发生");
|
|
|
+ for (int i = 0; i < windturbineData.getAlarmInfoList().size(); i++) {
|
|
|
+ ProEconEarlyReportAlarm earlyReportAlarm = windturbineData.getAlarmInfoList().get(i);
|
|
|
+ firstStr.append(earlyReportAlarm.getRuleName());
|
|
|
+ firstStr.append(earlyReportAlarm.getCount());
|
|
|
+ firstStr.append("次,总持续时长为");
|
|
|
+ firstStr.append(earlyReportAlarm.getKeepTime() + "分钟;");
|
|
|
+ }
|
|
|
+ StringBuilder secondStr = new StringBuilder("可能存在的隐患:").append("\n");
|
|
|
+ StringBuilder thridStr = new StringBuilder("建议排查:").append("\n");
|
|
|
+
|
|
|
+ for (int i = 0; i < listByPart.size(); i++) {
|
|
|
+ secondStr.append("\b");
|
|
|
+ secondStr.append("\b");
|
|
|
+ secondStr.append("\b");
|
|
|
+ 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("\n");
|
|
|
+ }
|
|
|
+ StringBuilder resultStr = new StringBuilder();
|
|
|
+
|
|
|
+ resultStr.append(firstStr);
|
|
|
+ resultStr.append("\n");
|
|
|
+ resultStr.append(secondStr);
|
|
|
+ resultStr.append("\n");
|
|
|
+ resultStr.append(thridStr);
|
|
|
+ windturbineData.setConclusion(resultStr.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return reportWindturbineList;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public List<ProEconEarlyReportWt> checkAndFixData(List<ProEconEarlyReportWt> earlyReportWindturbineList,List<ProEconAlarmRule> rule2List){
|
|
|
+
|
|
|
+ List<String> ruleIdList = rule2List.stream().map(s -> s.getId()).collect(Collectors.toList());
|
|
|
+ earlyReportWindturbineList.forEach(s -> {
|
|
|
+
|
|
|
+ List<ProEconEarlyReportAlarm> alarmInfoList = s.getAlarmInfoList();
|
|
|
+ if (alarmInfoList.size() < rule2List.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<ProEconAlarmRule> first = rule2List.stream().filter(m -> m.getId().equals(l)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ ProEconEarlyReportAlarm alarmInfo = new ProEconEarlyReportAlarm();
|
|
|
+ alarmInfo.setId(String.valueOf(SnowflakeGenerator.generateId()));
|
|
|
+ alarmInfo.setRuleId(first.get().getId());
|
|
|
+ alarmInfo.setAlarmType("custom");
|
|
|
+ alarmInfo.setRuleName(first.get().getName());
|
|
|
+ alarmInfo.setRuleDescription(first.get().getDescription());
|
|
|
+ alarmInfo.setRank(String.valueOf(first.get().getRank()));
|
|
|
+ alarmInfo.setCount(0l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