|
@@ -0,0 +1,641 @@
|
|
|
+package com.gyee.healthmanagementhistroy.service.mttrmtbf;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+
|
|
|
+import com.gyee.common.model.StringUtils;
|
|
|
+import com.gyee.common.util.BigDecimalUtils;
|
|
|
+import com.gyee.common.util.DateUtils;
|
|
|
+import com.gyee.healthmanagementhistroy.init.CacheContext;
|
|
|
+import com.gyee.healthmanagementhistroy.model.auto.*;
|
|
|
+import com.gyee.healthmanagementhistroy.service.auto.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName : MTTRMTBFTaskService
|
|
|
+ * @Author : xieshengjie
|
|
|
+ * @Date: 2021/6/21 19:27
|
|
|
+ * @Description : 生成mttrmtbf Service
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class MTTRMTBFTaskService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IFaultsnapService faultsnapService;
|
|
|
+ @Autowired
|
|
|
+ private IFaulthistoryService faulthistoryService;
|
|
|
+ @Autowired
|
|
|
+ private IWindpowerinfodayService windpowerinfodayService;
|
|
|
+ @Autowired
|
|
|
+ private IWpmttrandmtbfdayService wpmttrandmtbfdayService;
|
|
|
+ @Autowired
|
|
|
+ private IWpmttrandmtbmonthService wpmttrandmtbmonthService;
|
|
|
+ @Autowired
|
|
|
+ private IWpmttrandmtbfyearService wpmttrandmtbfyearService;
|
|
|
+ @Autowired
|
|
|
+ private IWindturbineinfodayService windturbineinfodayService;
|
|
|
+ @Autowired
|
|
|
+ private IWtmttrandmtbfdayService wtmttrandmtbfdayService;
|
|
|
+ @Autowired
|
|
|
+ private IWtmttrandmtbfmonthService wtmttrandmtbfmonthService;
|
|
|
+ @Autowired
|
|
|
+ private IWtmttrandmtbfyearService wtmttrandmtbfyearService;
|
|
|
+ @Autowired
|
|
|
+ private IShutdowneventService shutdowneventService;
|
|
|
+ /**
|
|
|
+ * 保存日
|
|
|
+ */
|
|
|
+ public void saveWpMttrAndMtbfDay(String beginDate,String endDate){
|
|
|
+ List<String> days = DateUtils.getDays(beginDate, endDate);
|
|
|
+ for (String day : days) {
|
|
|
+ Date date = DateUtils.parseDate(day);
|
|
|
+
|
|
|
+ Map<String,Object> delMap = new HashMap<>();
|
|
|
+ delMap.put("recorddate",date);
|
|
|
+ wpmttrandmtbfdayService.removeByMap(delMap);
|
|
|
+ wtmttrandmtbfdayService.removeByMap(delMap);
|
|
|
+ // 取一天windpowerinfoday 的数据
|
|
|
+ QueryWrapper<Windpowerinfoday> infodayQw = new QueryWrapper<>();
|
|
|
+ infodayQw.eq("recorddate",date);
|
|
|
+ List<Windpowerinfoday> indodayList = windpowerinfodayService.list(infodayQw);
|
|
|
+ // 取一天windtrubineinfoday 的数据
|
|
|
+ QueryWrapper<Windturbineinfoday> infodaywtQw = new QueryWrapper<>();
|
|
|
+ infodaywtQw.eq("recorddate",date);
|
|
|
+ List<Windturbineinfoday> infodaywtList = windturbineinfodayService.list(infodaywtQw);
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<Shutdownevent> shutdowneventQueryWrapper = new QueryWrapper<>();
|
|
|
+ Date addDay = DateUtils.addDays(date, 1);
|
|
|
+ shutdowneventQueryWrapper.ge("stoptime",date).lt("stoptime",addDay);
|
|
|
+ List<Shutdownevent> historyList = shutdowneventService.list(shutdowneventQueryWrapper);
|
|
|
+
|
|
|
+
|
|
|
+// // 取出所有故障的snapid
|
|
|
+// QueryWrapper<Faultsnap> snapQw = new QueryWrapper<>();
|
|
|
+// snapQw.eq("category1","FJ").eq("category2","GZ");
|
|
|
+// List<Faultsnap> snapList = faultsnapService.list(snapQw);
|
|
|
+// Map<BigDecimal,Faultsnap> snapMap = new HashMap<>();
|
|
|
+// snapList.stream().forEach(i->{
|
|
|
+// snapMap.put(i.getId(),i);
|
|
|
+// });
|
|
|
+//
|
|
|
+// List<BigDecimal> snapids = faultsnapService.list(snapQw).stream().map(i -> i.getId()).collect(Collectors.toList());
|
|
|
+//
|
|
|
+// //取出一天故障流水记录
|
|
|
+// QueryWrapper<Faulthistory> historyQw = new QueryWrapper<>();
|
|
|
+//// historyQw.like("faulttime",date);
|
|
|
+// Date addDay = DateUtils.addDays(date, 1);
|
|
|
+// historyQw.ge("faulttime",date).lt("faulttime",addDay);
|
|
|
+// historyQw.in("snapid",snapids);
|
|
|
+// List<Faulthistory> historyList = faulthistoryService.list(historyQw);
|
|
|
+ double fdFaulttime = 0;
|
|
|
+ long fdFaultcount = 0;
|
|
|
+ double fdWthours = 0;
|
|
|
+ double gfFaulttime = 0;
|
|
|
+ long gfFaultcount = 0;
|
|
|
+ double gfWthours = 0;
|
|
|
+ double zFaulttime = 0;
|
|
|
+ long zFaultcount = 0;
|
|
|
+ double zWthours = 0;
|
|
|
+ //保存日场站级别MTTR MTBF
|
|
|
+ for (Windpowerstation windpowerstation : CacheContext.wplist) {
|
|
|
+ Windpowerinfoday windpowerinfoday = indodayList.stream().filter(i -> i.getForeignkeyid().equals(windpowerstation.getId())).findFirst().isPresent()?indodayList.stream().filter(i -> i.getForeignkeyid().equals(windpowerstation.getId())).findFirst().get():null;
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfoday)){
|
|
|
+ faulttime = windpowerinfoday.getFaulttime();
|
|
|
+ }
|
|
|
+// long faultcount = historyList.stream().filter(i -> snapMap.get(i.getSnapid()).getStationid().equals(windpowerstation.getId())).count();
|
|
|
+ long faultcount = historyList.stream().filter(i -> i.getWindpowerstationid().equals(windpowerstation.getId())).count();
|
|
|
+ zFaulttime += faulttime;
|
|
|
+ zFaultcount += faultcount;
|
|
|
+ zWthours += BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2).doubleValue();
|
|
|
+ if (windpowerstation.getId().endsWith("FDC")){
|
|
|
+ fdFaulttime += faulttime;
|
|
|
+ fdFaultcount += faultcount;
|
|
|
+ fdWthours += BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2).doubleValue();
|
|
|
+ }else {
|
|
|
+ gfFaulttime += faulttime;
|
|
|
+ gfFaultcount += faultcount;
|
|
|
+ gfWthours += BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2).doubleValue();
|
|
|
+ }
|
|
|
+ Wpmttrandmtbfday w = new Wpmttrandmtbfday();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(windpowerstation.getId());
|
|
|
+ w.setWpname(windpowerstation.getName());
|
|
|
+ w.setLocation("windpower");
|
|
|
+ w.setRecorddate(date);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2).doubleValue());
|
|
|
+ wpmttrandmtbfdayService.save(w);
|
|
|
+ }
|
|
|
+ for (Project project : CacheContext.projectList) {
|
|
|
+ Windpowerinfoday windpowerinfoday = indodayList.stream().filter(i -> i.getForeignkeyid().equals(project.getId())).findFirst().isPresent()?indodayList.stream().filter(i -> i.getForeignkeyid().equals(project.getId())).findFirst().get():null;
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfoday)){
|
|
|
+ faulttime = windpowerinfoday.getFaulttime();
|
|
|
+ }
|
|
|
+// long faultcount = historyList.stream().filter(i -> snapMap.get(i.getSnapid()).getProjectid().equals(project.getId())).count();
|
|
|
+ long faultcount = historyList.stream().filter(i -> i.getProjectid().equals(project.getId())).count();
|
|
|
+
|
|
|
+ Wpmttrandmtbfday w = new Wpmttrandmtbfday();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(project.getId());
|
|
|
+ w.setWpname(project.getName());
|
|
|
+ w.setLocation("project");
|
|
|
+ w.setRecorddate(date);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(new BigDecimal(project.getQuantity()),new BigDecimal(24),2).doubleValue());
|
|
|
+ wpmttrandmtbfdayService.save(w);
|
|
|
+ }
|
|
|
+ for (Line line : CacheContext.lineList) {
|
|
|
+ Windpowerinfoday windpowerinfoday = indodayList.stream().filter(i -> i.getForeignkeyid().equals(line.getId())).findFirst().isPresent()?indodayList.stream().filter(i -> i.getForeignkeyid().equals(line.getId())).findFirst().get():null;
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfoday)){
|
|
|
+ faulttime = windpowerinfoday.getFaulttime();
|
|
|
+ }
|
|
|
+ long faultcount = historyList.stream().filter(i -> CacheContext.wmap.get(i.getWindturbineid()).getLineid().equals(line.getId())).count();
|
|
|
+
|
|
|
+ Wpmttrandmtbfday w = new Wpmttrandmtbfday();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(line.getId());
|
|
|
+ w.setWpname(line.getName());
|
|
|
+ w.setLocation("line");
|
|
|
+ w.setRecorddate(date);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(new BigDecimal(line.getQuantity()),new BigDecimal(24),2).doubleValue());
|
|
|
+ wpmttrandmtbfdayService.save(w);
|
|
|
+ }
|
|
|
+ // 保存日风机级别MTTR MTBF
|
|
|
+ for (Windturbine windturbine : CacheContext.wtls) {
|
|
|
+ Windturbineinfoday windturbineinfoday = infodaywtList.stream().filter(i -> i.getWindturbineid().equals(windturbine.getId())).findFirst().isPresent()?infodaywtList.stream().filter(i -> i.getWindturbineid().equals(windturbine.getId())).findFirst().get():null;
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windturbineinfoday)){
|
|
|
+ faulttime = windturbineinfoday.getFaulttime();
|
|
|
+ }
|
|
|
+ double faultcount = historyList.stream().filter(i -> i.getWindturbineid().equals(windturbine.getId())).count();
|
|
|
+ Wtmttrandmtbfday w = new Wtmttrandmtbfday();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWtid(windturbine.getId());
|
|
|
+ w.setWpname(windturbine.getName());
|
|
|
+ w.setRecorddate(date);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ wtmttrandmtbfdayService.save(w);
|
|
|
+ }
|
|
|
+
|
|
|
+ Wpmttrandmtbfday fd = new Wpmttrandmtbfday();
|
|
|
+ fd.setId(StringUtils.getUUID());
|
|
|
+ fd.setWpid("-1");
|
|
|
+ fd.setWpname("风电");
|
|
|
+ fd.setLocation("wind");
|
|
|
+ fd.setRecorddate(date);
|
|
|
+ fd.setStophours(fdFaulttime);
|
|
|
+ fd.setStoprtimes(fdFaultcount);
|
|
|
+ fd.setWthours(fdWthours);
|
|
|
+ wpmttrandmtbfdayService.save(fd);
|
|
|
+
|
|
|
+ Wpmttrandmtbfday gf = new Wpmttrandmtbfday();
|
|
|
+ gf.setId(StringUtils.getUUID());
|
|
|
+ gf.setWpid("-2");
|
|
|
+ gf.setWpname("光伏");
|
|
|
+ gf.setLocation("light");
|
|
|
+ gf.setRecorddate(date);
|
|
|
+ gf.setStophours(gfFaulttime);
|
|
|
+ gf.setStoprtimes(gfFaultcount);
|
|
|
+ gf.setWthours(gfWthours);
|
|
|
+ wpmttrandmtbfdayService.save(gf);
|
|
|
+
|
|
|
+ Wpmttrandmtbfday z = new Wpmttrandmtbfday();
|
|
|
+ z.setId(StringUtils.getUUID());
|
|
|
+ z.setWpid("0");
|
|
|
+ z.setWpname("全省");
|
|
|
+ z.setLocation("entire");
|
|
|
+ z.setRecorddate(date);
|
|
|
+ z.setStophours(zFaulttime);
|
|
|
+ z.setStoprtimes(zFaultcount);
|
|
|
+ z.setWthours(zWthours);
|
|
|
+ wpmttrandmtbfdayService.save(z);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存月
|
|
|
+ */
|
|
|
+ public void saveWpMttrAndMtbMonth(String beginDate,String endDate){
|
|
|
+ List<String> days = DateUtils.getDays(beginDate, endDate);
|
|
|
+ for (String day : days) {
|
|
|
+ Date date = DateUtils.parseDate(day);
|
|
|
+// Date monthLast = DateUtils.getMonthLast(date);
|
|
|
+ Date monthLast = date;
|
|
|
+ Date monthFirst = DateUtils.getMonthFirst(date);
|
|
|
+ int year = DateUtils.getYear(date);
|
|
|
+ int month = DateUtils.getMonth(date);
|
|
|
+ Map<String,Object> delMap = new HashMap<>();
|
|
|
+ delMap.put("year",year);
|
|
|
+ delMap.put("month",month);
|
|
|
+ wpmttrandmtbmonthService.removeByMap(delMap);
|
|
|
+ wtmttrandmtbfmonthService.removeByMap(delMap);
|
|
|
+ // 取一月windpowerinfoday 的数据
|
|
|
+ QueryWrapper<Windpowerinfoday> infodayQw = new QueryWrapper<>();
|
|
|
+ infodayQw.ge("recorddate",monthFirst);
|
|
|
+ infodayQw.le("recorddate",monthLast);
|
|
|
+ List<Windpowerinfoday> indodayList = windpowerinfodayService.list(infodayQw);
|
|
|
+
|
|
|
+ QueryWrapper<Shutdownevent> shutdowneventQueryWrapper = new QueryWrapper<>();
|
|
|
+ Date addDay = DateUtils.addDays(date, 1);
|
|
|
+ shutdowneventQueryWrapper.ge("stoptime",monthFirst).lt("stoptime",addDay);
|
|
|
+ List<Shutdownevent> historyList = shutdowneventService.list(shutdowneventQueryWrapper);
|
|
|
+
|
|
|
+// //取出所有故障的snapid
|
|
|
+// QueryWrapper<Faultsnap> snapQw = new QueryWrapper<>();
|
|
|
+// snapQw.eq("category1","FJ").eq("category2","GZ");
|
|
|
+// List<Faultsnap> snapList = faultsnapService.list(snapQw);
|
|
|
+// Map<BigDecimal,Faultsnap> snapMap = new HashMap<>();
|
|
|
+// snapList.stream().forEach(i->{
|
|
|
+// snapMap.put(i.getId(),i);
|
|
|
+// });
|
|
|
+//
|
|
|
+// List<BigDecimal> snapids = faultsnapService.list(snapQw).stream().map(i -> i.getId()).collect(Collectors.toList());
|
|
|
+//
|
|
|
+// //取出一月故障流水记录
|
|
|
+// QueryWrapper<Faulthistory> historyQw = new QueryWrapper<>();
|
|
|
+//// historyQw.like("faulttime",date);
|
|
|
+//// Date addDay = DateUtils.addDays(date, 1);
|
|
|
+// historyQw.ge("faulttime",monthFirst).le("faulttime",monthLast);
|
|
|
+// historyQw.in("snapid",snapids);
|
|
|
+// List<Faulthistory> historyList = faulthistoryService.list(historyQw);
|
|
|
+ double fdFaulttime = 0;
|
|
|
+ long fdFaultcount = 0;
|
|
|
+ double fdWthours = 0;
|
|
|
+ double gfFaulttime = 0;
|
|
|
+ long gfFaultcount = 0;
|
|
|
+ double gfWthours = 0;
|
|
|
+ double zFaulttime = 0;
|
|
|
+ long zFaultcount = 0;
|
|
|
+ double zWthours = 0;
|
|
|
+ //保存月场站级别MTTR MTBF
|
|
|
+ for (Windpowerstation windpowerstation : CacheContext.wplist) {
|
|
|
+ List<Windpowerinfoday> windpowerinfodayList = indodayList.stream().filter(i -> i.getForeignkeyid().equals(windpowerstation.getId())).collect(Collectors.toList());
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfodayList)){
|
|
|
+ faulttime = windpowerinfodayList.stream().mapToDouble(Windpowerinfoday::getFaulttime).sum();
|
|
|
+ }
|
|
|
+ long faultcount = historyList.stream().filter(i -> i.getWindpowerstationid().equals(windpowerstation.getId())).count();
|
|
|
+ zFaulttime += faulttime;
|
|
|
+ zFaultcount += faultcount;
|
|
|
+ zWthours += BigDecimalUtils.multiply(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2),new BigDecimal(getDays(DateUtils.toDate1(monthFirst),DateUtils.toDate1(monthLast)).size()),2).doubleValue();
|
|
|
+ if (windpowerstation.getId().endsWith("FDC")){
|
|
|
+ fdFaulttime += faulttime;
|
|
|
+ fdFaultcount += faultcount;
|
|
|
+ fdWthours += BigDecimalUtils.multiply(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2),new BigDecimal(getDays(DateUtils.toDate1(monthFirst),DateUtils.toDate1(monthLast)).size()),2).doubleValue();
|
|
|
+ }else {
|
|
|
+ gfFaulttime += faulttime;
|
|
|
+ gfFaultcount += faultcount;
|
|
|
+ gfWthours += BigDecimalUtils.multiply(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2),new BigDecimal(getDays(DateUtils.toDate1(monthFirst),DateUtils.toDate1(monthLast)).size()),2).doubleValue();
|
|
|
+ }
|
|
|
+ Wpmttrandmtbmonth w = new Wpmttrandmtbmonth();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(windpowerstation.getId());
|
|
|
+ w.setWpname(windpowerstation.getName());
|
|
|
+ w.setLocation("windpower");
|
|
|
+ w.setYear(year);
|
|
|
+ w.setMonth(month);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2),new BigDecimal(getDays(DateUtils.toDate1(monthFirst),DateUtils.toDate1(monthLast)).size()),2).doubleValue());
|
|
|
+ wpmttrandmtbmonthService.save(w);
|
|
|
+ }
|
|
|
+ for (Project project : CacheContext.projectList) {
|
|
|
+ List<Windpowerinfoday> windpowerinfodayList = indodayList.stream().filter(i -> i.getForeignkeyid().equals(project.getId())).collect(Collectors.toList());
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfodayList)){
|
|
|
+ faulttime = windpowerinfodayList.stream().mapToDouble(Windpowerinfoday::getFaulttime).sum();
|
|
|
+ }
|
|
|
+ long faultcount = historyList.stream().filter(i -> i.getProjectid().equals(project.getId())).count();
|
|
|
+
|
|
|
+ Wpmttrandmtbmonth w = new Wpmttrandmtbmonth();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(project.getId());
|
|
|
+ w.setWpname(project.getName());
|
|
|
+ w.setLocation("project");
|
|
|
+ w.setYear(year);
|
|
|
+ w.setMonth(month);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(BigDecimalUtils.multiply(new BigDecimal(project.getQuantity()),new BigDecimal(24),2),new BigDecimal(getDays(DateUtils.toDate1(monthFirst),DateUtils.toDate1(monthLast)).size()),2).doubleValue());
|
|
|
+
|
|
|
+ wpmttrandmtbmonthService.save(w);
|
|
|
+ }
|
|
|
+ for (Line line : CacheContext.lineList) {
|
|
|
+ List<Windpowerinfoday> windpowerinfodayList = indodayList.stream().filter(i -> i.getForeignkeyid().equals(line.getId())).collect(Collectors.toList());
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfodayList)){
|
|
|
+ faulttime = windpowerinfodayList.stream().mapToDouble(Windpowerinfoday::getFaulttime).sum();
|
|
|
+ }
|
|
|
+// long faultcount = historyList.stream().filter(i -> i.().equals(line.getId())).count();
|
|
|
+ long faultcount = historyList.stream().filter(i -> CacheContext.wmap.get(i.getWindturbineid()).getLineid().equals(line.getId())).count();
|
|
|
+
|
|
|
+
|
|
|
+ Wpmttrandmtbmonth w = new Wpmttrandmtbmonth();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(line.getId());
|
|
|
+ w.setWpname(line.getName());
|
|
|
+ w.setLocation("line");
|
|
|
+ w.setYear(year);
|
|
|
+ w.setMonth(month);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(BigDecimalUtils.multiply(new BigDecimal(line.getQuantity()),new BigDecimal(24),2),new BigDecimal(getDays(DateUtils.toDate1(monthFirst),DateUtils.toDate1(monthLast)).size()),2).doubleValue());
|
|
|
+
|
|
|
+ wpmttrandmtbmonthService.save(w);
|
|
|
+ }
|
|
|
+ // 保存月风机级别MTTR MTBF
|
|
|
+ for (Windturbine windturbine : CacheContext.wtls) {
|
|
|
+ // 取一月windtrubineinfoday 的数据
|
|
|
+ QueryWrapper<Windturbineinfoday> infodaywtQw = new QueryWrapper<>();
|
|
|
+ infodaywtQw.select("windturbineid,sum(faulttime) faulttime");
|
|
|
+ infodaywtQw.ge("recorddate",monthFirst);
|
|
|
+ infodaywtQw.le("recorddate",monthLast);
|
|
|
+ infodaywtQw.eq("windturbineid",windturbine.getId());
|
|
|
+ infodaywtQw.groupBy("windturbineid");
|
|
|
+ List<Windturbineinfoday> infodaywtList = windturbineinfodayService.list(infodaywtQw);
|
|
|
+ Optional<Windturbineinfoday> first = infodaywtList.stream().findFirst();
|
|
|
+ double faulttime = 0;
|
|
|
+ if (first.isPresent()){
|
|
|
+ faulttime = first.get().getFaulttime();
|
|
|
+ }
|
|
|
+// double faultcount = historyList.stream().filter(i -> snapMap.get(i.getSnapid()).getWindturbineid().equals(windturbine.getId())).count();
|
|
|
+ double faultcount = historyList.stream().filter(i -> i.getWindturbineid().equals(windturbine.getId())).count();
|
|
|
+ Wtmttrandmtbfmonth w = new Wtmttrandmtbfmonth();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWtid(windturbine.getId());
|
|
|
+ w.setWpname(windturbine.getName());
|
|
|
+ w.setYear(year);
|
|
|
+ w.setMonth(month);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ wtmttrandmtbfmonthService.save(w);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Wpmttrandmtbmonth fd = new Wpmttrandmtbmonth();
|
|
|
+ fd.setId(StringUtils.getUUID());
|
|
|
+ fd.setWpid("-1");
|
|
|
+ fd.setWpname("风电");
|
|
|
+ fd.setLocation("wind");
|
|
|
+ fd.setYear(year);
|
|
|
+ fd.setMonth(month);
|
|
|
+ fd.setStophours(fdFaulttime);
|
|
|
+ fd.setStoprtimes(fdFaultcount);
|
|
|
+ fd.setWthours(fdWthours);
|
|
|
+ wpmttrandmtbmonthService.save(fd);
|
|
|
+
|
|
|
+ Wpmttrandmtbmonth gf = new Wpmttrandmtbmonth();
|
|
|
+ gf.setId(StringUtils.getUUID());
|
|
|
+ gf.setWpid("-2");
|
|
|
+ gf.setWpname("光伏");
|
|
|
+ gf.setLocation("light");
|
|
|
+ gf.setYear(year);
|
|
|
+ gf.setMonth(month);
|
|
|
+ gf.setStophours(gfFaulttime);
|
|
|
+ gf.setStoprtimes(gfFaultcount);
|
|
|
+ gf.setWthours(gfWthours);
|
|
|
+ wpmttrandmtbmonthService.save(gf);
|
|
|
+
|
|
|
+ Wpmttrandmtbmonth z = new Wpmttrandmtbmonth();
|
|
|
+ z.setId(StringUtils.getUUID());
|
|
|
+ z.setWpid("0");
|
|
|
+ z.setWpname("全省");
|
|
|
+ z.setLocation("entire");
|
|
|
+ z.setYear(year);
|
|
|
+ z.setMonth(month);
|
|
|
+ z.setStophours(zFaulttime);
|
|
|
+ z.setStoprtimes(zFaultcount);
|
|
|
+ z.setWthours(zWthours);
|
|
|
+ wpmttrandmtbmonthService.save(z);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 保存年
|
|
|
+ */
|
|
|
+ public void saveWpMttrAndMtbfYear(String beginDate,String endDate){
|
|
|
+ List<String> days = DateUtils.getDays(beginDate, endDate);
|
|
|
+ for (String day : days) {
|
|
|
+ Date date = DateUtils.parseDate(day);
|
|
|
+ int year = DateUtils.getYear(date);
|
|
|
+// Date monthLast = DateUtils.getMonthLast(date);
|
|
|
+ Date yearLast = date;
|
|
|
+ Date yearFirst = DateUtils.getYearFirst(year);
|
|
|
+
|
|
|
+ Map<String,Object> delMap = new HashMap<>();
|
|
|
+ delMap.put("year",year);
|
|
|
+ wpmttrandmtbfyearService.removeByMap(delMap);
|
|
|
+ wtmttrandmtbfyearService.removeByMap(delMap);
|
|
|
+ // 取一年windpowerinfoday 的数据
|
|
|
+ QueryWrapper<Windpowerinfoday> infodayQw = new QueryWrapper<>();
|
|
|
+ infodayQw.ge("recorddate",yearFirst);
|
|
|
+ infodayQw.le("recorddate",yearLast);
|
|
|
+ List<Windpowerinfoday> indodayList = windpowerinfodayService.list(infodayQw);
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<Shutdownevent> shutdowneventQueryWrapper = new QueryWrapper<>();
|
|
|
+ Date addDay = DateUtils.addDays(date, 1);
|
|
|
+ shutdowneventQueryWrapper.ge("stoptime",yearFirst).lt("stoptime",addDay);
|
|
|
+ List<Shutdownevent> historyList = shutdowneventService.list(shutdowneventQueryWrapper);
|
|
|
+
|
|
|
+// //取出所有故障的snapid
|
|
|
+// QueryWrapper<Faultsnap> snapQw = new QueryWrapper<>();
|
|
|
+// snapQw.eq("category1","FJ").eq("category2","GZ");
|
|
|
+// List<Faultsnap> snapList = faultsnapService.list(snapQw);
|
|
|
+// Map<BigDecimal,Faultsnap> snapMap = new HashMap<>();
|
|
|
+// snapList.stream().forEach(i->{
|
|
|
+// snapMap.put(i.getId(),i);
|
|
|
+// });
|
|
|
+//
|
|
|
+// List<BigDecimal> snapids = faultsnapService.list(snapQw).stream().map(i -> i.getId()).collect(Collectors.toList());
|
|
|
+//
|
|
|
+// //取出一年故障流水记录
|
|
|
+// QueryWrapper<Faulthistory> historyQw = new QueryWrapper<>();
|
|
|
+//// historyQw.like("faulttime",date);
|
|
|
+//// Date addDay = DateUtils.addDays(date, 1);
|
|
|
+// historyQw.ge("faulttime",yearFirst).le("faulttime",yearLast);
|
|
|
+// historyQw.in("snapid",snapids);
|
|
|
+// List<Faulthistory> historyList = faulthistoryService.list(historyQw);
|
|
|
+ double fdFaulttime = 0;
|
|
|
+ long fdFaultcount = 0;
|
|
|
+ double fdWthours = 0;
|
|
|
+ double gfFaulttime = 0;
|
|
|
+ long gfFaultcount = 0;
|
|
|
+ double gfWthours = 0;
|
|
|
+ double zFaulttime = 0;
|
|
|
+ long zFaultcount = 0;
|
|
|
+ double zWthours = 0;
|
|
|
+ int size = getDays(DateUtils.toDate1(yearFirst), DateUtils.toDate1(yearLast)).size();
|
|
|
+
|
|
|
+ //保存年场站级别MTTR MTBF
|
|
|
+ for (Windpowerstation windpowerstation : CacheContext.wplist) {
|
|
|
+ List<Windpowerinfoday> windpowerinfodayList = indodayList.stream().filter(i -> i.getForeignkeyid().equals(windpowerstation.getId())).collect(Collectors.toList());
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfodayList)){
|
|
|
+ faulttime = windpowerinfodayList.stream().mapToDouble(Windpowerinfoday::getFaulttime).sum();
|
|
|
+ }
|
|
|
+ long faultcount = historyList.stream().filter(i -> i.getWindpowerstationid().equals(windpowerstation.getId())).count();
|
|
|
+ zFaulttime += faulttime;
|
|
|
+ zFaultcount += faultcount;
|
|
|
+ zWthours += BigDecimalUtils.multiply(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2),new BigDecimal(size),2).doubleValue();
|
|
|
+ if (windpowerstation.getId().endsWith("FDC")){
|
|
|
+ fdFaulttime += faulttime;
|
|
|
+ fdFaultcount += faultcount;
|
|
|
+ fdWthours += BigDecimalUtils.multiply(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2),new BigDecimal(size),2).doubleValue();
|
|
|
+ }else {
|
|
|
+ gfFaulttime += faulttime;
|
|
|
+ gfFaultcount += faultcount;
|
|
|
+ gfWthours += BigDecimalUtils.multiply(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2),new BigDecimal(size),2).doubleValue();
|
|
|
+ }
|
|
|
+ Wpmttrandmtbfyear w = new Wpmttrandmtbfyear();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(windpowerstation.getId());
|
|
|
+ w.setWpname(windpowerstation.getName());
|
|
|
+ w.setLocation("windpower");
|
|
|
+ w.setYear(year);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(BigDecimalUtils.multiply(windpowerstation.getQuantity(),new BigDecimal(24),2),new BigDecimal(size),2).doubleValue());
|
|
|
+ wpmttrandmtbfyearService.save(w);
|
|
|
+ }
|
|
|
+ for (Project project : CacheContext.projectList) {
|
|
|
+ List<Windpowerinfoday> windpowerinfodayList = indodayList.stream().filter(i -> i.getForeignkeyid().equals(project.getId())).collect(Collectors.toList());
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfodayList)){
|
|
|
+ faulttime = windpowerinfodayList.stream().mapToDouble(Windpowerinfoday::getFaulttime).sum();
|
|
|
+ }
|
|
|
+ long faultcount = historyList.stream().filter(i -> i.getProjectid().equals(project.getId())).count();
|
|
|
+
|
|
|
+ Wpmttrandmtbfyear w = new Wpmttrandmtbfyear();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(project.getId());
|
|
|
+ w.setWpname(project.getName());
|
|
|
+ w.setLocation("project");
|
|
|
+ w.setYear(year);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(BigDecimalUtils.multiply(new BigDecimal(project.getQuantity()),new BigDecimal(24),2),new BigDecimal(size),2).doubleValue());
|
|
|
+
|
|
|
+ wpmttrandmtbfyearService.save(w);
|
|
|
+ }
|
|
|
+ for (Line line : CacheContext.lineList) {
|
|
|
+ List<Windpowerinfoday> windpowerinfodayList = indodayList.stream().filter(i -> i.getForeignkeyid().equals(line.getId())).collect(Collectors.toList());
|
|
|
+ double faulttime = 0;
|
|
|
+ if (StringUtils.isNotNull(windpowerinfodayList)){
|
|
|
+ faulttime = windpowerinfodayList.stream().mapToDouble(Windpowerinfoday::getFaulttime).sum();
|
|
|
+ }
|
|
|
+// long faultcount = historyList.stream().filter(i -> snapMap.get(i.getSnapid()).getLineid().equals(line.getId())).count();
|
|
|
+ long faultcount = historyList.stream().filter(i -> CacheContext.wmap.get(i.getWindturbineid()).getLineid().equals(line.getId())).count();
|
|
|
+
|
|
|
+ Wpmttrandmtbfyear w = new Wpmttrandmtbfyear();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWpid(line.getId());
|
|
|
+ w.setWpname(line.getName());
|
|
|
+ w.setLocation("line");
|
|
|
+ w.setYear(year);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ w.setWthours(BigDecimalUtils.multiply(BigDecimalUtils.multiply(new BigDecimal(line.getQuantity()),new BigDecimal(24),2),new BigDecimal(size),2).doubleValue());
|
|
|
+
|
|
|
+ wpmttrandmtbfyearService.save(w);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存年风机级别MTTR MTBF
|
|
|
+ for (Windturbine windturbine : CacheContext.wtls) {
|
|
|
+ // 取一年windtrubineinfoday 的数据
|
|
|
+ QueryWrapper<Windturbineinfoday> infoyearwtQw = new QueryWrapper<>();
|
|
|
+ infoyearwtQw.select("windturbineid,sum(faulttime) faulttime");
|
|
|
+ infoyearwtQw.ge("recorddate",yearFirst);
|
|
|
+ infoyearwtQw.le("recorddate",yearLast);
|
|
|
+ infoyearwtQw.eq("windturbineid",windturbine.getId());
|
|
|
+ infoyearwtQw.groupBy("windturbineid");
|
|
|
+ List<Windturbineinfoday> infoyearwtList = windturbineinfodayService.list(infoyearwtQw);
|
|
|
+
|
|
|
+ Optional<Windturbineinfoday> first = infoyearwtList.stream().findFirst();
|
|
|
+ double faulttime = 0;
|
|
|
+ if (first.isPresent()){
|
|
|
+ faulttime = first.get().getFaulttime();
|
|
|
+ }
|
|
|
+// double faultcount = historyList.stream().filter(i -> snapMap.get(i.getSnapid()).getWindturbineid().equals(windturbine.getId())).count();
|
|
|
+ double faultcount = historyList.stream().filter(i -> i.getWindturbineid().equals(windturbine.getId())).count();
|
|
|
+ Wtmttrandmtbfyear w = new Wtmttrandmtbfyear();
|
|
|
+ w.setId(StringUtils.getUUID());
|
|
|
+ w.setWtid(windturbine.getId());
|
|
|
+ w.setWpname(windturbine.getName());
|
|
|
+ w.setYear(year);
|
|
|
+ w.setStophours(faulttime);
|
|
|
+ w.setStoprtimes(faultcount);
|
|
|
+ wtmttrandmtbfyearService.save(w);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Wpmttrandmtbfyear fd = new Wpmttrandmtbfyear();
|
|
|
+ fd.setId(StringUtils.getUUID());
|
|
|
+ fd.setWpid("-1");
|
|
|
+ fd.setWpname("风电");
|
|
|
+ fd.setLocation("wind");
|
|
|
+ fd.setYear(year);
|
|
|
+ fd.setStophours(fdFaulttime);
|
|
|
+ fd.setStoprtimes(fdFaultcount);
|
|
|
+ fd.setWthours(fdWthours);
|
|
|
+ wpmttrandmtbfyearService.save(fd);
|
|
|
+
|
|
|
+ Wpmttrandmtbfyear gf = new Wpmttrandmtbfyear();
|
|
|
+ gf.setId(StringUtils.getUUID());
|
|
|
+ gf.setWpid("-2");
|
|
|
+ gf.setWpname("光伏");
|
|
|
+ gf.setLocation("light");
|
|
|
+ gf.setYear(year);
|
|
|
+ gf.setStophours(gfFaulttime);
|
|
|
+ gf.setStoprtimes(gfFaultcount);
|
|
|
+ gf.setWthours(gfWthours);
|
|
|
+ wpmttrandmtbfyearService.save(gf);
|
|
|
+
|
|
|
+ Wpmttrandmtbfyear z = new Wpmttrandmtbfyear();
|
|
|
+ z.setId(StringUtils.getUUID());
|
|
|
+ z.setWpid("0");
|
|
|
+ z.setWpname("全省");
|
|
|
+ z.setLocation("entire");
|
|
|
+ z.setYear(year);
|
|
|
+ z.setStophours(zFaulttime);
|
|
|
+ z.setStoprtimes(zFaultcount);
|
|
|
+ z.setWthours(zWthours);
|
|
|
+ wpmttrandmtbfyearService.save(z);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取两日期间日期list
|
|
|
+ *
|
|
|
+ * @param beginDate
|
|
|
+ * @param endDate
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static List<String> getDays(String beginDate, String endDate) {
|
|
|
+ List<String> days = null;
|
|
|
+ if (StringUtils.isNotEmpty(beginDate) && StringUtils.isNotEmpty(endDate)) {
|
|
|
+ days = DateUtils.getDays(beginDate, endDate);
|
|
|
+ } else {
|
|
|
+ days = new ArrayList<>();
|
|
|
+ days.add(DateUtils.getYesterdayStr("yyyy-MM-dd"));
|
|
|
+ }
|
|
|
+ return days;
|
|
|
+ }
|
|
|
+}
|