123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- 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<Long> 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<ProEconWindturbineGoodness> vos=new ArrayList<>();
- for(ProBasicEquipment wt: CacheContext.wtls)
- {
- Map<String, Map<String, Double>> coefficientMap=coefficientService.coefficient(wt.getId(),recordDate);
- Map<String, Map<String,Double>> 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<String, Double> 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<String, Double> 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<ProEconWindturbineGoodness>() {
- @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<vos.size();i++)
- {
- ProEconWindturbineGoodness vo=vos.get(i);
- vo.setDayTop(i+1);
- }
- vos.sort(new Comparator<ProEconWindturbineGoodness>() {
- @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<vos.size();i++)
- {
- ProEconWindturbineGoodness vo=vos.get(i);
- vo.setMonthTop(i+1);
- }
- vos.sort(new Comparator<ProEconWindturbineGoodness>() {
- @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<vos.size();i++)
- {
- ProEconWindturbineGoodness vo=vos.get(i);
- vo.setYearTop(i+1);
- }
- proEconWindturbineGoodnessService.saveBatch(vos);
- }
- }
|