package com.gyee.generation.service;//package com.gyee.generation.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.gyee.common.contant.ContantXk; import com.gyee.common.model.PointData; import com.gyee.common.model.StringUtils; import com.gyee.generation.init.CacheContext; import com.gyee.generation.model.auto.*; import com.gyee.generation.service.auto.*; import com.gyee.generation.util.DateUtils; import com.gyee.generation.util.realtimesource.IEdosUtil; import com.gyee.generation.util.statisticcs.Initial; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @Service public class WtAlysisDayService { // private static final Logger logger = LoggerFactory.getLogger(EquipmentInfo1Service.class); @Resource private IEdosUtil edosUtil; @Resource private IProEconWtAlysisDayService proEconWtAlysisDayService; @Resource private IProEconEquipmentInfoDay1Service proEconEquipmentInfoDay1Service; @Resource private IProEconEquipmentInfoDay2Service proEconEquipmentInfoDay2Service; @Resource private IProEconEquipmentInfoDay3Service proEconEquipmentInfoDay3Service; @Resource private IProEconEquipmentInfoDay4Service proEconEquipmentInfoDay4Service; private Map queryEquipmentInfoDay1(Date recordDate) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("record_date",DateUtils.truncate(recordDate)); List iostls= proEconEquipmentInfoDay1Service.list(queryWrapper); // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0 // ) // .collect(Collectors.toList()); //List转map Map iostmap=iostls.stream(). collect(Collectors.toMap(ProEconEquipmentInfoDay1::getWindturbineId, Function.identity(), (key1, key2) -> key2)); return iostmap; } private Map queryEquipmentInfoDay2(Date recordDate) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("record_date",DateUtils.truncate(recordDate)); List iostls= proEconEquipmentInfoDay2Service.list(queryWrapper); // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0 // ) // .collect(Collectors.toList()); //List转map Map iostmap=iostls.stream(). collect(Collectors.toMap(ProEconEquipmentInfoDay2::getWindturbineId, Function.identity(), (key1, key2) -> key2)); return iostmap; } private Map queryEquipmentInfoDay3(Date recordDate) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("record_date",DateUtils.truncate(recordDate)); List iostls= proEconEquipmentInfoDay3Service.list(queryWrapper); // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0 // ) // .collect(Collectors.toList()); //List转map Map iostmap=iostls.stream(). collect(Collectors.toMap(ProEconEquipmentInfoDay3::getWindturbineId, Function.identity(), (key1, key2) -> key2)); return iostmap; } private Map queryEquipmentInfoDay4(Date recordDate) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("record_date",DateUtils.truncate(recordDate)); List iostls= proEconEquipmentInfoDay4Service.list(queryWrapper); // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0 // ) // .collect(Collectors.toList()); //List转map Map iostmap=iostls.stream(). collect(Collectors.toMap(ProEconEquipmentInfoDay4::getWindturbineId, Function.identity(), (key1, key2) -> key2)); return iostmap; } /** * 计算设备日信息 */ public void calEquipmentInfoDay(Date recordDate) throws Exception { Calendar c=Calendar.getInstance(); c.setTime(recordDate); Date end=c.getTime(); Date begin= DateUtils.truncate(c.getTime()); //判断是否有重复记录, QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("record_date",DateUtils.truncate(recordDate)); List idls = proEconWtAlysisDayService.list(queryWrapper).stream() // .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate))==0 // && CacheContext.wtmap.containsKey(i.getWindturbineId())) .map(ProEconWtAlysisDay::getId) .collect(Collectors.toList()); if (idls.size() > 0) { proEconWtAlysisDayService.removeByIds(idls); } Map eqday1map = queryEquipmentInfoDay1(recordDate); Map eqday2map = queryEquipmentInfoDay2(recordDate); Map eqday3map = queryEquipmentInfoDay3(recordDate); Map eqday4map = queryEquipmentInfoDay4(recordDate); List dayls=new ArrayList<>(); for(ProBasicEquipment wt:CacheContext.wtls) { ProEconWtAlysisDay pewp=new ProEconWtAlysisDay(); Initial.initial(pewp); pewp.setRecordDate(DateUtils.truncate(recordDate)); pewp.setWindturbineId(wt.getId()); if(eqday1map.containsKey(wt.getId())) { ProEconEquipmentInfoDay1 dayinfo= eqday1map.get(wt.getId()); pewp.setRfdl(dayinfo.getRfdl()); pewp.setRpjfs(dayinfo.getRpjfs()); pewp.setRpjgl(dayinfo.getRpjgl()); pewp.setRyfdl(dayinfo.getRllfdl()); double gzss=dayinfo.getRgzssdl(); double jxss=dayinfo.getRjxssdl(); double xnss=dayinfo.getRxnssdl(); double xdss=dayinfo.getRxdtjssdl()+dayinfo.getRxdjclssdl(); double slss=dayinfo.getRcwsltqssdl()+dayinfo.getRcwsldwssdl(); double ssdl=gzss+jxss+xnss+xdss+slss; pewp.setRssdl(StringUtils.round(ssdl,2)); pewp.setYfdl(dayinfo.getYfdl()); pewp.setYpjfs(dayinfo.getYpjfs()); pewp.setYpjgl(dayinfo.getYpjgl()); pewp.setYyfdl(dayinfo.getYllfdl()); gzss=dayinfo.getYgzssdl(); jxss=dayinfo.getYjxssdl(); xnss=dayinfo.getYxnssdl(); xdss=dayinfo.getYxdtjssdl()+dayinfo.getYxdjclssdl(); slss=dayinfo.getYcwsltqssdl()+dayinfo.getYcwsldwssdl(); ssdl=gzss+jxss+xnss+xdss+slss; pewp.setYssdl(StringUtils.round(ssdl,2)); pewp.setNfdl(dayinfo.getNfdl()); pewp.setNpjfs(dayinfo.getNpjfs()); pewp.setNpjgl(dayinfo.getNpjgl()); pewp.setNyfdl(dayinfo.getNllfdl()); gzss=dayinfo.getNgzssdl(); jxss=dayinfo.getNjxssdl(); xnss=dayinfo.getNxnssdl(); xdss=dayinfo.getNxdtjssdl()+dayinfo.getNxdjclssdl(); slss=dayinfo.getNcwsltqssdl()+dayinfo.getNcwsldwssdl(); ssdl=gzss+jxss+xnss+xdss+slss; pewp.setNssdl(StringUtils.round(ssdl,2)); } if(eqday2map.containsKey(wt.getId())) { ProEconEquipmentInfoDay2 dayinfo= eqday2map.get(wt.getId()); pewp.setRyxxs(dayinfo.getRyxxs()); pewp.setRgzxs(dayinfo.getRgztjxs()); pewp.setRjxxs(dayinfo.getRjxtjxs()); pewp.setRzdxs(dayinfo.getRxdxs()); pewp.setRzdxs(dayinfo.getRtxzdxs()); int dayTimes=24; double sbklyl = new BigDecimal(dayTimes-dayinfo.getRgztjxs()).divide(new BigDecimal(dayTimes), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();//风机平均设备可利用率 pewp.setRsbklyl(StringUtils.round(sbklyl, 2)); pewp.setYyxxs(dayinfo.getYyxxs()); pewp.setYgzxs(dayinfo.getYgztjxs()); pewp.setYjxxs(dayinfo.getYjxtjxs()); pewp.setYzdxs(dayinfo.getYxdxs()); pewp.setYzdxs(dayinfo.getYtxzdxs()); c.setTime(recordDate); int days=c.get(Calendar.DAY_OF_MONTH); dayTimes=24*days; sbklyl = new BigDecimal(dayTimes-dayinfo.getYgztjxs()).divide(new BigDecimal(dayTimes), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();//风机平均设备可利用率 pewp.setYsbklyl(StringUtils.round(sbklyl, 2)); pewp.setNyxxs(dayinfo.getNyxxs()); pewp.setNgzxs(dayinfo.getNgztjxs()); pewp.setNjxxs(dayinfo.getNjxtjxs()); pewp.setNzdxs(dayinfo.getNxdxs()); pewp.setNzdxs(dayinfo.getNtxzdxs()); days=c.get(Calendar.DAY_OF_YEAR); dayTimes=24*days; sbklyl = new BigDecimal(dayTimes-dayinfo.getNgztjxs()).divide(new BigDecimal(dayTimes), 2, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue();//风机平均设备可利用率 pewp.setNsbklyl(StringUtils.round(sbklyl, 2)); } if(eqday3map.containsKey(wt.getId())) { ProEconEquipmentInfoDay3 dayinfo= eqday3map.get(wt.getId()); pewp.setRtjcs(dayinfo.getRgztjcs()+dayinfo.getRjxtjcs()); pewp.setYtjcs(dayinfo.getYgztjcs()+dayinfo.getYjxtjcs()); pewp.setNtjcs(dayinfo.getNgztjcs()+dayinfo.getNjxtjcs()); } if(eqday4map.containsKey(wt.getId())) { ProEconEquipmentInfoDay4 dayinfo= eqday4map.get(wt.getId()); pewp.setRnhyd(dayinfo.getRnhyd()); pewp.setRsjbz(dayinfo.getRqxpcbbzsj()); pewp.setRyxfs(dayinfo.getRyxfss()); pewp.setYnhyd(dayinfo.getYnhyd()); pewp.setYsjbz(dayinfo.getYqxpcbbzsj()); pewp.setYyxfs(dayinfo.getYyxfss()); pewp.setNnhyd(dayinfo.getNnhyd()); pewp.setNsjbz(dayinfo.getNqxpcbbzsj()); pewp.setNyxfs(dayinfo.getNyxfss()); } //昨日的统计结果 List pepidls =new ArrayList<>(); Calendar cl=Calendar.getInstance(); cl.setTime(recordDate); cl.add(Calendar.DAY_OF_MONTH,-1); if(cl.get(Calendar.DAY_OF_MONTH)!=1) { QueryWrapper queryWrapper2 = new QueryWrapper<>(); queryWrapper2.eq("record_date",DateUtils.truncate(cl.getTime())).eq("windTurbine_Id",wt.getId()); pepidls = proEconWtAlysisDayService.list(queryWrapper2); // .stream() // .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(cl.getTime())) == 0 // && i.getWindturbineId().equals(wt.getId()) // ) // .collect(Collectors.toList()); } calSimple(pewp, end, begin, wt, pepidls); dayls.add(pewp); } proEconWtAlysisDayService.saveBatch(dayls); } private void calSimple(ProEconWtAlysisDay pewp, Date end, Date begin, ProBasicEquipment wt, List pepidls) throws Exception { //*******************************************日信息统计*********************************************************/ double lastState=-1;//上一分钟状态 double bbhcs=0;//不饱和次数 Map> wtpAimap = CacheContext.wtpAimap; Map aimap=wtpAimap.get(wt.getId()); if(aimap.containsKey(ContantXk.SSQFZT)) { ProBasicEquipmentPoint point=aimap.get(ContantXk.SSQFZT); //按照分钟时间进行统计状态快照值 List pointls=edosUtil.getHistoryDatasSnap(point.getNemCode(), begin.getTime()/1000, end.getTime()/1000); if(!pointls.isEmpty()) { for (PointData po : pointls) { if (po.getPointValueInDouble() >=3) { if (lastState != po.getPointValueInDouble()) { //将当前状态保存到上一分钟状态 lastState = po.getPointValueInDouble(); //实时欠发大于等于3的次数加1 bbhcs++; } } } } } //日不饱和次数 pewp.setRbbhcs(bbhcs); //*******************************************日信息统计*********************************************************/ //*******************************************月信息统计*********************************************************/ if(pepidls.isEmpty()) { pewp.setYbbhcs(pewp.getRbbhcs()); }else { ProEconWtAlysisDay pepid=pepidls.get(0); pewp.setYbbhcs(StringUtils.round(pepid.getYbbhcs()+pewp.getRbbhcs(),2)); } //*******************************************月信息统计*********************************************************/ //*******************************************年信息统计*********************************************************/ if(pepidls.isEmpty()) { pewp.setNbbhcs(pewp.getRbbhcs()); }else { ProEconWtAlysisDay pepid=pepidls.get(0); pewp.setNbbhcs(StringUtils.round(pepid.getNbbhcs()+pewp.getRbbhcs(),2)); } //*******************************************年信息统计*********************************************************/ } }