123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- 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<String, ProEconEquipmentInfoDay1> queryEquipmentInfoDay1(Date recordDate) {
- QueryWrapper<ProEconEquipmentInfoDay1> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
- List<ProEconEquipmentInfoDay1> iostls= proEconEquipmentInfoDay1Service.list(queryWrapper);
- // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
- // )
- // .collect(Collectors.toList());
- //List转map
- Map<String, ProEconEquipmentInfoDay1> iostmap=iostls.stream().
- collect(Collectors.toMap(ProEconEquipmentInfoDay1::getWindturbineId, Function.identity(), (key1, key2) -> key2));
- return iostmap;
- }
- private Map<String, ProEconEquipmentInfoDay2> queryEquipmentInfoDay2(Date recordDate) {
- QueryWrapper<ProEconEquipmentInfoDay2> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
- List<ProEconEquipmentInfoDay2> iostls= proEconEquipmentInfoDay2Service.list(queryWrapper);
- // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
- // )
- // .collect(Collectors.toList());
- //List转map
- Map<String, ProEconEquipmentInfoDay2> iostmap=iostls.stream().
- collect(Collectors.toMap(ProEconEquipmentInfoDay2::getWindturbineId, Function.identity(), (key1, key2) -> key2));
- return iostmap;
- }
- private Map<String, ProEconEquipmentInfoDay3> queryEquipmentInfoDay3(Date recordDate) {
- QueryWrapper<ProEconEquipmentInfoDay3> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
- List<ProEconEquipmentInfoDay3> iostls= proEconEquipmentInfoDay3Service.list(queryWrapper);
- // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
- // )
- // .collect(Collectors.toList());
- //List转map
- Map<String, ProEconEquipmentInfoDay3> iostmap=iostls.stream().
- collect(Collectors.toMap(ProEconEquipmentInfoDay3::getWindturbineId, Function.identity(), (key1, key2) -> key2));
- return iostmap;
- }
- private Map<String, ProEconEquipmentInfoDay4> queryEquipmentInfoDay4(Date recordDate) {
- QueryWrapper<ProEconEquipmentInfoDay4> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
- List<ProEconEquipmentInfoDay4> iostls= proEconEquipmentInfoDay4Service.list(queryWrapper);
- // .stream().filter(i-> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
- // )
- // .collect(Collectors.toList());
- //List转map
- Map<String, ProEconEquipmentInfoDay4> 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<ProEconWtAlysisDay> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
- List<Long> 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<String, ProEconEquipmentInfoDay1> eqday1map = queryEquipmentInfoDay1(recordDate);
- Map<String, ProEconEquipmentInfoDay2> eqday2map = queryEquipmentInfoDay2(recordDate);
- Map<String, ProEconEquipmentInfoDay3> eqday3map = queryEquipmentInfoDay3(recordDate);
- Map<String, ProEconEquipmentInfoDay4> eqday4map = queryEquipmentInfoDay4(recordDate);
- List<ProEconWtAlysisDay> 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<ProEconWtAlysisDay> 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<ProEconWtAlysisDay> 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<ProEconWtAlysisDay> pepidls) throws Exception {
- //*******************************************日信息统计*********************************************************/
- double lastState=-1;//上一分钟状态
- double bbhcs=0;//不饱和次数
- Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
- Map<String, ProBasicEquipmentPoint> aimap=wtpAimap.get(wt.getId());
- if(aimap.containsKey(ContantXk.SSQFZT))
- {
- ProBasicEquipmentPoint point=aimap.get(ContantXk.SSQFZT);
- //按照分钟时间进行统计状态快照值
- List<PointData> 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));
- }
- //*******************************************年信息统计*********************************************************/
- }
- }
|