|
@@ -1,6 +1,7 @@
|
|
|
package com.gyee.alarm.service;
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.gyee.alarm.init.CacheContext;
|
|
|
import com.gyee.alarm.model.auto.*;
|
|
|
import com.gyee.alarm.model.vo.AlarmCustomType;
|
|
@@ -32,6 +33,10 @@ public class EarlyReportService {
|
|
|
@Resource
|
|
|
private IAlarmTsService alarmTsService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private IProEconEarlyReportWtService proEconEarlyReportWtService;
|
|
|
+ @Resource
|
|
|
+ private IProEconEarlyReportAlarmService proEconEarlyReportAlarmService;
|
|
|
|
|
|
|
|
|
//时间间隔(天),即从当日0点,向前间隔天数,为计算区间
|
|
@@ -40,50 +45,116 @@ public class EarlyReportService {
|
|
|
@Value("${limit}")
|
|
|
private int limit;
|
|
|
|
|
|
- public boolean createEarlyReport() {
|
|
|
+ public boolean createEarlyReport(Date recordDate) {
|
|
|
|
|
|
boolean result=false;
|
|
|
//报告时间
|
|
|
- Date reportDate = DateUtils.truncate(new Date());
|
|
|
+ Date reportDate = DateUtils.truncate(recordDate);
|
|
|
//获取计算开始时间
|
|
|
Date statStartTime = DateUtils.addDays(DateUtils.today(), - interval_day);
|
|
|
//获取计算结束时间
|
|
|
- Date statEndTime = DateUtils.today();
|
|
|
+ Date statEndTime = DateUtils.truncate(recordDate);
|
|
|
|
|
|
|
|
|
List<ProEconAlarmType> fjtypels=CacheContext.alarmTypeMap.get(AlarmType.FJBJ.getCode());
|
|
|
|
|
|
List<ProEconAlarmType> gftypels=CacheContext.alarmTypeMap.get(AlarmType.GFBJ.getCode());
|
|
|
|
|
|
+ QueryWrapper<ProEconEarlyReport> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("report_date",recordDate);
|
|
|
+ //判断是否有重复记录,先删除重复记录
|
|
|
+ List<String> idls = proEconEarlyReportService.list(queryWrapper).stream()
|
|
|
+ .map(ProEconEarlyReport::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for(int i=0;i<idls.size();i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ List<ProEconEarlyReportWt> wtls= proEconEarlyReportWtService.findByReportId(idls.get(i));
|
|
|
+ if(!wtls.isEmpty())
|
|
|
+ {
|
|
|
+ List<String> wtidls = wtls.stream().map(ProEconEarlyReportWt::getId).collect(Collectors.toList());
|
|
|
+ proEconEarlyReportService.removeByIds(wtidls);
|
|
|
+
|
|
|
+ for(int j=0;j<wtidls.size();j++)
|
|
|
+ {
|
|
|
+ List<ProEconEarlyReportAlarm> alarmls= proEconEarlyReportAlarmService.findByWindturbineReportId(wtidls.get(j));
|
|
|
+
|
|
|
+ if(!alarmls.isEmpty())
|
|
|
+ {
|
|
|
+ List<String> alarmidls = alarmls.stream().map(ProEconEarlyReportAlarm::getId).collect(Collectors.toList());
|
|
|
+ proEconEarlyReportAlarmService.removeByIds(alarmidls);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> tempids=new ArrayList<>();
|
|
|
+
|
|
|
+ for(int i=0;i<idls.size();i++)
|
|
|
+ {
|
|
|
+ tempids.add(idls.get(i));
|
|
|
+ if(tempids.size()==100)
|
|
|
+ {
|
|
|
+ proEconEarlyReportService.removeByIds(tempids);
|
|
|
+ tempids=new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!tempids.isEmpty())
|
|
|
+ {
|
|
|
+ proEconEarlyReportService.removeByIds(tempids);
|
|
|
+ }
|
|
|
+
|
|
|
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());
|
|
|
+ if(!fjtype.getNemCode().equals("BJXT") && !fjtype.getNemCode().equals("FDJ"))
|
|
|
+ {
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ 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());
|
|
|
+
|
|
|
+ result = isResult(statStartTime, statEndTime, wt, report);
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}else
|
|
|
{
|
|
|
for(ProEconAlarmType gftype:gftypels)
|
|
|
{
|
|
|
+ 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());
|
|
|
+ }
|
|
|
report.setRelatedParts(gftype.getNemCode());
|
|
|
StringBuilder sb=new StringBuilder();
|
|
|
sb.append(wt.getNemCode()).append(wt.getName()).append(gftype.getName()).append("诊断报告");
|
|
@@ -93,36 +164,52 @@ public class EarlyReportService {
|
|
|
report.setProEconEarlyReportWtList(new ArrayList<>());
|
|
|
report.setReportDate(reportDate);
|
|
|
report.setStatStartDate(new Date());
|
|
|
+
|
|
|
+ result = isResult(statStartTime, statEndTime, wt, report);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- try {
|
|
|
- //获取本次报告最差的风机信息集合
|
|
|
- List<ProEconEarlyReportWt> nowWindturbineInfoList = getNowWindturbineInfo(wt,wt.getModelId(), report.getId(),report.getRelatedParts(), statStartTime, statEndTime, limit);
|
|
|
+ private boolean isResult(Date statStartTime, Date statEndTime, ProBasicEquipment wt, ProEconEarlyReport report) {
|
|
|
|
|
|
- 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());
|
|
|
+ boolean result;
|
|
|
|
|
|
- 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);
|
|
|
- }
|
|
|
+ //获取本次报告最差的风机信息集合
|
|
|
+ List<ProEconEarlyReportWt> nowWindturbineInfoList = getNowWindturbineInfo(wt, wt.getModelId(), report.getId(), report.getRelatedParts(), statStartTime, statEndTime, limit);
|
|
|
|
|
|
- //执行写入操作
|
|
|
- result = proEconEarlyReportService.save(report);
|
|
|
+ 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());
|
|
|
|
|
|
- } catch (RuntimeException ex) {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
- } finally {
|
|
|
+ if(!report.getProEconEarlyReportWtList().isEmpty())
|
|
|
+ {
|
|
|
+ for(ProEconEarlyReportWt earlyReportWt:report.getProEconEarlyReportWtList())
|
|
|
+ {
|
|
|
+ if(!earlyReportWt.getAlarmInfoList().isEmpty())
|
|
|
+ {
|
|
|
+ for(ProEconEarlyReportAlarm earlyReportAlarm: earlyReportWt.getAlarmInfoList())
|
|
|
+ {
|
|
|
+ proEconEarlyReportAlarmService.save(earlyReportAlarm);
|
|
|
+ }
|
|
|
+ proEconEarlyReportWtService.save(earlyReportWt);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ //执行写入操作
|
|
|
+ result = proEconEarlyReportService.save(report);
|
|
|
return result;
|
|
|
}
|
|
|
|