123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- 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<ProEconWindturbineGoodness> queryWrapper = new QueryWrapper<>();
- // queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
- // List<Long> 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<Long> tempids=new ArrayList<>();
- //
- // for(int i=0;i<idls.size();i++)
- // {
- // tempids.add(idls.get(i));
- // if(tempids.size()==1000)
- // {
- // proEconWindturbineGoodnessService.removeByIds(tempids);
- // tempids=new ArrayList<>();
- // }
- // }
- //
- // if(!tempids.isEmpty())
- // {
- // proEconWindturbineGoodnessService.removeByIds(tempids);
- // }
- QueryWrapper<ProEconEquipmentInfoDay1> queryWrapper2 = new QueryWrapper<>();
- queryWrapper2.eq("record_date",DateUtils.truncate(recordDate));
- List<ProEconEquipmentInfoDay1> ed1ls= proEconEquipmentInfoDay1Service.list(queryWrapper2);
- Map<String,ProEconEquipmentInfoDay1> equipmentInfoDay1Map=new HashMap<>();
- if(!ed1ls.isEmpty())
- {
- for(ProEconEquipmentInfoDay1 ed1:ed1ls)
- {
- equipmentInfoDay1Map.put(ed1.getWindturbineId(),ed1);
- }
- }
- List<ProEconWindturbineGoodness> vos=new ArrayList<>();
- System.out.println("拟合优度风机数量"+CacheContext.wtfdls.size());
- final CountDownLatch latch = new CountDownLatch(+CacheContext.wtfdls.size());
- for(int i=0;i<CacheContext.wtfdls.size();i++)
- {
- new Thread(new GoodnessOfFitThread(executor, i, recordDate, coefficientService,
- goodnessOfFitService,
- equipmentInfoDay1Map, vos,latch)).start();
- // proEconWindturbineGoodnessService.save(po);
- }
- latch.await();
- 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);
- }
- System.out.println("拟合优度风机存储数量"+vos.size());
- //判断是否有重复记录,先删除重复记录
- QueryWrapper<ProEconWindturbineGoodness> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("record_date",DateUtils.truncate(recordDate));
- List<Long> 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<Long> tempids=new ArrayList<>();
- for(int i=0;i<idls.size();i++)
- {
- tempids.add(idls.get(i));
- if(tempids.size()==1000)
- {
- proEconWindturbineGoodnessService.removeByIds(tempids);
- tempids=new ArrayList<>();
- }
- }
- if(!tempids.isEmpty())
- {
- proEconWindturbineGoodnessService.removeByIds(tempids);
- }
- List<ProEconWindturbineGoodness> 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("拟合优度风机存储结束");
- }
- }
|