package com.gyee.generation.service; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.gyee.generation.init.CacheContext; import com.gyee.generation.model.auto.ProEconEquipmentInfoDay1; import com.gyee.generation.model.auto.ProEconWindturbineGoodness; import com.gyee.generation.service.auto.IProEconEquipmentInfoDay1Service; import com.gyee.generation.service.auto.IProEconWindturbineGoodnessService; import com.gyee.generation.task.thread.GoodnessOfFitThread; import com.gyee.generation.util.DateUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; import java.util.concurrent.CountDownLatch; import java.util.concurrent.Executor; import java.util.stream.Collectors; @Service public class WindturbineGoodnessService { @Resource private CoefficientService coefficientService; @Resource private GoodnessOfFitService goodnessOfFitService; @Resource private IProEconWindturbineGoodnessService proEconWindturbineGoodnessService; @Resource private IProEconEquipmentInfoDay1Service proEconEquipmentInfoDay1Service; @Resource private Executor executor; public void calWindturbineGoodness(Date recordDate) throws Exception { // //判断是否有重复记录,先删除重复记录 // QueryWrapper queryWrapper = new QueryWrapper<>(); // queryWrapper.eq("record_date",DateUtils.truncate(recordDate)); // List idls = proEconWindturbineGoodnessService.list(queryWrapper).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 tempids=new ArrayList<>(); // // for(int i=0;i(); // } // } // // if(!tempids.isEmpty()) // { // proEconWindturbineGoodnessService.removeByIds(tempids); // } QueryWrapper queryWrapper2 = new QueryWrapper<>(); queryWrapper2.eq("record_date",DateUtils.truncate(recordDate)); List ed1ls= proEconEquipmentInfoDay1Service.list(queryWrapper2); Map equipmentInfoDay1Map=new HashMap<>(); if(!ed1ls.isEmpty()) { for(ProEconEquipmentInfoDay1 ed1:ed1ls) { equipmentInfoDay1Map.put(ed1.getWindturbineId(),ed1); } } List vos=new ArrayList<>(); System.out.println("拟合优度风机数量"+CacheContext.wtfdls.size()); final CountDownLatch latch = new CountDownLatch(+CacheContext.wtfdls.size()); for(int i=0;i() { @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 queryWrapper = new QueryWrapper<>(); queryWrapper.eq("record_date",DateUtils.truncate(recordDate)); List idls = proEconWindturbineGoodnessService.list(queryWrapper).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 tempids=new ArrayList<>(); for(int i=0;i(); } } if(!tempids.isEmpty()) { proEconWindturbineGoodnessService.removeByIds(tempids); } List templs=new ArrayList<>(); for(ProEconWindturbineGoodness vo:vos) { templs.add(vo); if(templs.size()==1000) { proEconWindturbineGoodnessService.saveBatch(templs); templs=new ArrayList<>(); } } if(!templs.isEmpty()) { proEconWindturbineGoodnessService.saveBatch(templs); } System.out.println("拟合优度风机存储结束"); } }