package com.gyee.generation.service; import com.gyee.generation.init.CacheContext; import com.gyee.generation.model.auto.ProBasicEquipment; import com.gyee.generation.model.auto.ProEconWindturbineGoodness; import com.gyee.generation.service.auto.IProEconWindturbineGoodnessService; import com.gyee.generation.util.DateUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @Service public class WindturbineGoodnessService { @Resource private CoefficientService coefficientService; @Resource private GoodnessOfFitService goodnessOfFitService; @Resource private IProEconWindturbineGoodnessService proEconWindturbineGoodnessService; public void calWindturbineGoodness(Date recordDate) throws Exception { //判断是否有重复记录,先删除重复记录 List idls = proEconWindturbineGoodnessService.list().stream() .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate))==0 && CacheContext.wtmap.containsKey(i.getWindturbineId())).map(ProEconWindturbineGoodness::getId) .collect(Collectors.toList()); if (idls.size() > 0) { proEconWindturbineGoodnessService.removeByIds(idls); } List vos=new ArrayList<>(); for(ProBasicEquipment wt: CacheContext.wtls) { Map> coefficientMap=coefficientService.coefficient(wt.getId(),recordDate); Map> fitMap=goodnessOfFitService.goodnessOfFit(wt.getId(),recordDate); ProEconWindturbineGoodness po=new ProEconWindturbineGoodness(); po.setModelId(wt.getModelId()); po.setWindturbineId(wt.getId()); po.setRecordDate(DateUtils.truncate(recordDate)); po.setWindtpowerstationId(wt.getWindpowerstationId()); po.setCompanyId(wt.getCompanyId()); if(wt.getWindpowerstationId().contains("FDC")) { po.setTypes("-1"); }else { po.setTypes("-2"); } po.setDayGoodness(0.0); po.setYearGoodness(0.0); po.setMonthGoodness(0.0); po.setDayCoefficient(0.0); po.setMonthCoefficient(0.0); po.setYearCoefficient(0.0); if(fitMap.containsKey(wt.getId())) { Map map=fitMap.get(wt.getId()); po.setDayGoodness(map.get("day")); po.setYearGoodness(map.get("month")); po.setMonthGoodness(map.get("year")); } if(coefficientMap.containsKey(wt.getId())) { Map map=coefficientMap.get(wt.getId()); po.setDayCoefficient(map.get("day")); po.setMonthCoefficient(map.get("month")); po.setMonthCoefficient(map.get("year")); } vos.add(po); // proEconWindturbineGoodnessService.save(po); } vos.sort(new Comparator() { @Override public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) { double d1=o1.getDayGoodness()+o1.getDayCoefficient(); double d2=o2.getDayGoodness()+o2.getDayCoefficient(); if (d1 < d2) { return 1; }else if (d1 > d2){ return 1; }else { return 0; } } }); for(int i=0;i() { @Override public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) { double d1=o1.getMonthGoodness()+o1.getMonthCoefficient(); double d2=o2.getMonthGoodness()+o2.getMonthCoefficient(); if (d1 < d2) { return 1; }else if (d1 > d2){ return 1; }else { return 0; } } }); for(int i=0;i() { @Override public int compare(ProEconWindturbineGoodness o1, ProEconWindturbineGoodness o2) { double d1=o1.getYearGoodness()+o1.getYearCoefficient(); double d2=o2.getYearGoodness()+o2.getYearCoefficient(); if (d1 < d2) { return 1; }else if (d1 > d2){ return 1; }else { return 0; } } }); for(int i=0;i