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.generation.config.feign.RemoteServiceBuilder;
import com.gyee.generation.config.feign.TsDoubleData;
import com.gyee.generation.feign.AdapterApi;
import com.gyee.generation.init.CacheContext;
import com.gyee.generation.model.auto.*;
import com.gyee.generation.model.vo.StatusValue;
import com.gyee.generation.model.vo.WpType;
import com.gyee.generation.service.auto.IProEconInOrOutSpeedTotal2Service;
import com.gyee.generation.service.auto.IProEconInOrOutSpeedTotalService;
import com.gyee.generation.service.auto.IProEconInputOrOutputSpeedService;
import com.gyee.generation.util.DateUtils;
import com.gyee.generation.util.StringUtils;
import com.gyee.generation.util.dataadapter.IAdapterService;
import com.gyee.generation.util.dataadapter.PointInfo;
import com.gyee.generation.util.realtimesource.IEdosUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URI;
import java.util.*;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

@Service
public class InputOrOutPutService {

    @Resource
    private IEdosUtil edosUtil;
    @Resource
    private IProEconInOrOutSpeedTotal2Service proEconInOrOutSpeedTotal2Service;
    @Resource
    private IProEconInOrOutSpeedTotalService proEconInOrOutSpeedTotalService;
    @Resource
    private IProEconInputOrOutputSpeedService proEconInputOrOutputSpeedService;
    @Resource
    private RemoteServiceBuilder remoteService;

    @Value("${frequency.cutinandout}")
    private Integer frequency;

    private static Map<String, Double> statusRanngMap;

    @Resource
    private AdapterApi adapter;


    public URI goldenUri() {
        return URI.create("http://10.220.1.8:8011/ts");
    }
    public void initialInputOrOutputSpeed() {
        statusRanngMap = new HashMap<>();
        List<ProBasicEquipment> wtls = new ArrayList<>();
        for (ProBasicPowerstation wp : CacheContext.wpls) {
            if (wp.getId().contains("FDC")) {
                wtls.addAll(CacheContext.wpwtmap.get(wp.getId()));
            }
        }

        List<ProEconInputOrOutputSpeed> ls = new ArrayList<>();

        List<String> mxztls = new ArrayList<>();
        String mxzts = null;
        List<String> ssfsls = new ArrayList<>();
        for (ProBasicEquipment wt : wtls) {

            Map<String, ProBasicEquipmentPoint> pointmap = CacheContext.wtpAimap.get(wt.getId());

            ProBasicEquipmentPoint mxzt = pointmap.get(ContantXk.MXZT);
            mxztls.add(mxzt.getNemCode());
            mxzts = String.join(",", mxztls);
            ProBasicEquipmentPoint ssfs = pointmap.get(ContantXk.CJ_SSFS);
            ssfsls.add(ssfs.getNemCode());
        }

        try {
//                        List<PointData> mxztvaluels = edosUtil.getRealData(mxztls);
            String ztpoints = String.join(",", mxztls);
            Map<String, TsDoubleData> mxztvaluels = remoteService.adapterfd().getLatest(ztpoints);
            List<TsDoubleData> mxztValueList = new ArrayList<>(mxztvaluels.values());
            //Map<String, PointInfo> mxztvaluelsMap = iAdapterService.getLatestData(mxzts);
            //List<PointInfo> mxztvaluels = null;
            //if (null != mxztvaluelsMap && mxztvaluelsMap.size() != 0) {
            //    mxztvaluels = (List<PointInfo>) mxztvaluelsMap.values();
            //}
            if (null != mxztValueList && mxztValueList.size() == wtls.size()) {
                for (int i = 0; i < wtls.size(); i++) {

                    ProBasicEquipment wt = wtls.get(i);
                    //                    statusRanngMap.put(wt.getId(), mxztvaluels.get(i).getPointValueInDouble());
                    statusRanngMap.put(wt.getId(), (Double) mxztValueList.get(i).getDoubleValue());
                }
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void inputOrOutputSpeed(Date recordDate) throws Exception {

        //        Date begin = DateUtils.addSeconds(recordDate, -60);
        //
        //        Date begin = DateUtils.addHours(recordDate, -frequency);
        //        Date end = recordDate;
        //        Map<String, ProEconInputOrOutputSpeed> wtTimeStatusMap=new HashMap<>();
        //        Map<String,Double> wtLastStatusMap=new HashMap<>();
        //
        //        QueryWrapper<ProEconInputOrOutputSpeed> queryWrapper = new QueryWrapper<>();
        //        queryWrapper.ge("record_date",begin).le("record_date",end);
        //        queryWrapper.orderByAsc("record_date");
        //        List<ProEconInputOrOutputSpeed> recordList = proEconInputOrOutputSpeedService.list(queryWrapper);
        //
        //        Map<String, Map<String,ProEconInputOrOutputSpeed>> statusMap=new HashMap<>();
        //        if(!recordList.isEmpty())
        //        {
        //            for(ProEconInputOrOutputSpeed po:recordList)
        //            {
        //                if(statusMap.containsKey(po.getWindturbineId()))
        //                {
        //                    Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(po.getWindturbineId());
        //                    map.put(String.valueOf(po.getRecordDate().getTime()),po);
        //                }else
        //                {
        //                    Map<String, ProEconInputOrOutputSpeed> map= new HashMap<>();
        //                    map.put(String.valueOf(po.getRecordDate().getTime()),po);
        //                    statusMap.put(po.getWindturbineId(),map);
        //                }
        //
        //            }
        //        }
        List<ProBasicEquipment> wtls = new ArrayList<>();
        for (ProBasicPowerstation wp : CacheContext.wpls) {
            if (wp.getId().contains("FDC")) {
                wtls.addAll(CacheContext.wpwtmap.get(wp.getId()));
            }
        }

        List<ProEconInputOrOutputSpeed> ls = new ArrayList<>();


        List<String> mxztls = new ArrayList<>();
        List<String> ssfsls = new ArrayList<>();
        for (ProBasicEquipment wt : wtls) {

            Map<String, ProBasicEquipmentPoint> pointmap = CacheContext.wtpAimap.get(wt.getId());

            ProBasicEquipmentPoint mxzt = pointmap.get(ContantXk.MXZT);
            mxztls.add(mxzt.getNemCode());
            ProBasicEquipmentPoint ssfs = pointmap.get(ContantXk.CJ_SSFS);
            ssfsls.add(ssfs.getNemCode());
        }

        String ztpoints = String.join(",", mxztls);
        String fspoints = String.join(",", ssfsls);
        Map<String, TsDoubleData> mxztvaluels = remoteService.adapterfd().getLatest(ztpoints);
        Map<String, TsDoubleData> ssfsvaluels = remoteService.adapterfd().getLatest(fspoints);
        // 将 Map 的值转换为 List
        List<TsDoubleData> mxztValueList = new ArrayList<>(mxztvaluels.values());
        List<TsDoubleData> ssfsValueList = new ArrayList<>(ssfsvaluels.values());

//        List<PointData> mxztvaluels = edosUtil.getRealData(mxztls);
//        List<PointData> ssfsvaluels = edosUtil.getRealData(ssfsls);

        if (ssfsValueList.size() == mxztValueList.size() && ssfsValueList.size() == wtls.size()) {
            for (int i = 0; i < wtls.size(); i++) {


                ProBasicEquipment wt = wtls.get(i);
                double status = StringUtils.round(mxztValueList.get(i).getDoubleValue(), 0);
                if (null != statusRanngMap) {
                    double lastStatus = StringUtils.round(statusRanngMap.get(wt.getId()), 0);

                    TsDoubleData ssfspo = ssfsValueList.get(i);
                    //     切入切出风速
                    if (lastStatus == StatusValue.DJ.getCode() && status == StatusValue.YX.getCode()) {
                        ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();

                        input.setWindturbineId(wt.getId());
                        input.setWindpowerstationId(wt.getWindpowerstationId());
                        input.setProjectId(wt.getProjectId());
                        input.setLineId(wt.getLineId());
                        input.setRecordDate(DateUtils.truncate(new Date()));
                        input.setInputOrOutput(1);


                        input.setSpeed(StringUtils.round(ssfspo.getDoubleValue(), 2));


                        //                    if(statusMap.containsKey(wt.getId()))
                        //                    {
                        //                        Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(wt.getId());
                        //
                        //                        if(!map.containsKey(String.valueOf(ssfspo.getPointTime())) )
                        //                        {
                        //                            ls.add(input);
                        //                        }
                        //                    }else {
                        //                        ls.add(input);
                        //                    }

                        ls.add(input);

                    } else if (lastStatus == StatusValue.YX.getCode() && status == StatusValue.DJ.getCode()) {
                        ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
                        input.setWindturbineId(wt.getId());
                        input.setWindpowerstationId(wt.getWindpowerstationId());
                        input.setProjectId(wt.getProjectId());
                        input.setLineId(wt.getLineId());
                        input.setRecordDate(DateUtils.truncate(new Date()));
                        input.setInputOrOutput(0);

                        input.setSpeed(StringUtils.round(ssfspo.getDoubleValue(), 2));

                        //                    if(statusMap.containsKey(wt.getId()))
                        //                    {
                        //                        Map<String, ProEconInputOrOutputSpeed> map= statusMap.get(wt.getId());
                        //
                        //                        if(!map.containsKey(String.valueOf(ssfspo.getPointTime())) )
                        //                        {
                        //                            ls.add(input);
                        //                        }
                        //                    }else
                        //                    {
                        //                        ls.add(input);
                        //                    }

                        ls.add(input);
                    }
                }


                statusRanngMap.put(wt.getId(), status);
            }
        }
        //        for (ProBasicEquipment wt: wtls) {
        //            {
        //
        ////                if (wt.getWindpowerstationId().contains(WpType.GDC.id)) {
        ////                    continue;
        ////                }
        //                Map<String, ProBasicEquipmentPoint> pointmap= CacheContext.wtpAimap.get(wt.getId());
        //
        //
        //                if(statusMap.containsKey(wt.getId()))
        //                {
        //                    wtTimeStatusMap=statusMap.get(wt.getId());
        //                }
        //
        //                double lastStatus=-1;
        //
        //
        //                ProBasicEquipmentPoint mxzt= pointmap.get(ContantXk.SBZT);
        //                ProBasicEquipmentPoint ssfs= pointmap.get(ContantXk.CJ_SSFS);
        //
        //                //获取5分钟没个间隔1秒钟，保证状态与时序库保持一致
        //                List<PointData> statusls = edosUtil.getHistoryDatasSnap(mxzt.getNemCode(), begin.getTime() / 1000, end.getTime() / 1000,null,1L);
        //                List<PointData> ssfsls = edosUtil.getHistoryDatasSnap(ssfs.getNemCode(), begin.getTime() / 1000, end.getTime() / 1000,null,1L);
        //
        //
        //                if(!statusls.isEmpty() && !ssfsls.isEmpty() && ssfsls.size()==statusls.size())
        //                {
        //
        //                    for(int i=0;i<statusls.size();i++)
        //                    {
        //
        //
        //                        if(wtLastStatusMap.containsKey(wt.getId()))
        //                        {
        //                            lastStatus=wtLastStatusMap.get(wt.getId());
        //                        }
        //
        //                        PointData statuspo=statusls.get(i);
        //                        PointData ssfspo=ssfsls.get(i);
        //                        double status= StringUtils.round(statuspo.getPointValueInDouble(),0);
        //
        //                        if(i==0)
        //                        {
        //                            lastStatus=status;
        //                        }
        //                        if (!Objects.equals(lastStatus, status))
        //                        {
        //
        //                            //     切入切出风速
        //                            if (lastStatus == 0 && status == 1)
        //                            {
        //                                ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
        //
        //                                input.setWindturbineId(wt.getId());
        //                                input.setWindpowerstationId(wt.getWindpowerstationId());
        //                                input.setProjectId(wt.getProjectId());
        //                                input.setLineId(wt.getLineId());
        //                                input.setRecordDate(new Date());
        //                                input.setInputOrOutput(1);
        //
        //
        //                                input.setSpeed(StringUtils.round(ssfspo.getPointValueInDouble(),2));
        //
        //                                if(!wtTimeStatusMap.containsKey(String.valueOf(statuspo.getPointTime())) && !wtTimeStatusMap.get(String.valueOf(statuspo.getPointTime())).getWindturbineId().equals(wt.getId()))
        //                                {
        //                                    //roEconInputOrOutputSpeedService.save(input);
        //                                    ls.add(input);
        //                                }
        //                                lastStatus=status;
        //
        //                            }
        //                            else if (lastStatus == 1 && status== 0)
        //                            {
        //                                ProEconInputOrOutputSpeed input = new ProEconInputOrOutputSpeed();
        //                                input.setWindturbineId(wt.getId());
        //                                input.setWindpowerstationId(wt.getWindpowerstationId());
        //                                input.setProjectId(wt.getProjectId());
        //                                input.setLineId(wt.getLineId());
        //                                input.setRecordDate(new Date());
        //                                input.setInputOrOutput(0);
        //
        //                                input.setSpeed(StringUtils.round(ssfspo.getPointValueInDouble(),2));
        //
        //                                if(!wtTimeStatusMap.containsKey(String.valueOf(statuspo.getPointTime())) && !wtTimeStatusMap.get(String.valueOf(statuspo.getPointTime())).getWindturbineId().equals(wt.getId()))
        //                                {
        //                                    //proEconInputOrOutputSpeedService.save(input);
        //
        //                                    ls.add(input);
        //                                }
        //                                lastStatus=status;
        //                            }
        //
        //                            wtLastStatusMap.put(wt.getId(), status);
        //
        //                        }
        //                    }
        //
        //
        //
        //                }
        //
        //            }
        //
        //        System.out.println("切入切出数量"+ls.size());
        List<ProEconInputOrOutputSpeed> templs = new ArrayList<>();
        for (ProEconInputOrOutputSpeed vo : ls) {
            templs.add(vo);
            if (templs.size() == 100) {
                proEconInputOrOutputSpeedService.saveBatch(templs);
                templs = new ArrayList<>();
            }
        }

        if (!templs.isEmpty()) {
            proEconInputOrOutputSpeedService.saveBatch(templs);
        }

        //        }

    }

    public void inputOrOutput(Date currentDate) {
        currentDate = DateUtils.truncate(currentDate);
        //        Date end = DateUtils.addDays(currentDate, 1);
        //        Date daybegin =DateUtils.truncate(currentDate);
        Date end = currentDate;
        Date daybegin = DateUtils.addDays(currentDate, -1);

        Calendar c = Calendar.getInstance();
        c.setTime(daybegin);


        c.set(Calendar.DAY_OF_MONTH, 1);
        Date monthbegin = c.getTime();
        c.set(Calendar.MONTH, 0);
        Date yearbegin = c.getTime();

        for (ProBasicPowerstation wp : CacheContext.wpls) {

            if (wp.getId().contains(WpType.GDC.id)) {
                continue;
            }
            List<ProBasicEquipment> wtls = null;
            if (CacheContext.wpwtmap.containsKey(wp.getId())) {
                wtls = CacheContext.wpwtmap.get(wp.getId());
            }

            if (null != wtls && !wtls.isEmpty()) {
                for (ProBasicEquipment wt : wtls) {


                    ProEconInOrOutSpeedTotal total1 = null;
                    ProEconInOrOutSpeedTotal2 total2 = null;
                    QueryWrapper<ProEconInOrOutSpeedTotal> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("record_date", daybegin).eq("windturbine_id", wt.getId());
                    Optional<ProEconInOrOutSpeedTotal> total1o = proEconInOrOutSpeedTotalService.list(queryWrapper)
                            .stream()
                            //                            .filter(i -> i.getWindturbineId().equals(wt.getId())
                            //                                    && i.getRecordDate().compareTo(daybegin) == 0)
                            .findFirst();

                    if (total1o.isPresent()) {
                        total1 = total1o.get();
                    }
                    QueryWrapper<ProEconInOrOutSpeedTotal2> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("record_date", daybegin).eq("windturbine_id", wt.getId());
                    Optional<ProEconInOrOutSpeedTotal2> total2o = proEconInOrOutSpeedTotal2Service.list(queryWrapper2).stream()
                            //                            .filter(i -> i.getWindturbineId().equals(wt.getId())
                            //                            && i.getRecordDate().compareTo(daybegin) == 0)
                            .findFirst();

                    if (total2o.isPresent()) {
                        total2 = total2o.get();
                    }
                    if (total1 != null) {

                        QueryWrapper<ProEconInOrOutSpeedTotal> wrapper = new QueryWrapper<>();
                        wrapper.eq("id", total1.getId());
                        proEconInOrOutSpeedTotalService.remove(wrapper);

                    }
                    if (total2 != null) {
                        QueryWrapper<ProEconInOrOutSpeedTotal2> wrapper = new QueryWrapper<>();
                        wrapper.eq("id", total2.getId());
                        proEconInOrOutSpeedTotal2Service.remove(wrapper);

                    }

                    total1 = new ProEconInOrOutSpeedTotal();
                    total1.setWindturbineId(wt.getId());
                    total1.setWindpowerstationId(wt.getWindpowerstationId());
                    total1.setProjectId(wt.getProjectId());
                    total1.setLineId(wt.getLineId());
                    total1.setRecordDate(daybegin);
                    total1.setCompanyId(wt.getCompanyId());
                    total1.setRegionId(wt.getRegionId());
                    if (wt.getWindpowerstationId().contains(WpType.FDC.id)) {
                        total1.setTypes("-1");
                    } else {
                        total1.setTypes("-2");
                    }
                    total2 = new ProEconInOrOutSpeedTotal2();
                    total2.setWindturbineId(wt.getId());
                    total2.setWindpowerstationId(wt.getWindpowerstationId());
                    total2.setProjectId(wt.getProjectId());
                    total2.setLineId(wt.getLineId());
                    total2.setRecordDate(daybegin);
                    total2.setRegionId(wt.getRegionId());
                    total2.setCompanyId(wt.getCompanyId());
                    if (wt.getWindpowerstationId().contains(WpType.FDC.id)) {
                        total2.setTypes("-1");
                    } else {
                        total2.setTypes("-2");
                    }

                    newMethod(end, daybegin, monthbegin, yearbegin, wt.getId(), total1, total2);
                    verify(total1);

                    proEconInOrOutSpeedTotalService.save(total1);
                    proEconInOrOutSpeedTotal2Service.save(total2);
                }

            }


        }
    }

    private void verify(ProEconInOrOutSpeedTotal total1) {
        //日小风切入
        if (Double.isInfinite(total1.getDayInputSmall()) || Double.isNaN(total1.getDayInputSmall())) {
            total1.setDayInputSmall(0.0);
        } else {
            total1.setDayInputSmall(StringUtils.round(total1.getDayInputSmall(), 2));
        }
        //日小风切入最小值
        if (Double.isInfinite(total1.getDayInputSmallMin()) || Double.isNaN(total1.getDayInputSmallMin())) {
            total1.setDayInputSmallMin(0.0);
        } else {
            total1.setDayInputSmallMin(StringUtils.round(total1.getDayInputSmallMin(), 2));
        }
        //日小风切入最大值
        if (Double.isInfinite(total1.getDayInputSmallMax()) || Double.isNaN(total1.getDayInputSmallMax())) {
            total1.setDayInputSmallMax(0.0);
        } else {
            total1.setDayInputSmallMax(StringUtils.round(total1.getDayInputSmallMax(), 2));
        }

        //日大风切入
        if (Double.isInfinite(total1.getDayInputBig()) || Double.isNaN(total1.getDayInputBig())) {
            total1.setDayInputBig(0.0);
        } else {
            total1.setDayInputBig(StringUtils.round(total1.getDayInputBig(), 2));
        }
        //日大风切入最大值
        if (Double.isInfinite(total1.getDayInputBigMin()) || Double.isNaN(total1.getDayInputBigMin())) {
            total1.setDayInputBigMin(0.0);
        } else {
            total1.setDayInputBigMin(StringUtils.round(total1.getDayInputBigMin(), 2));
        }
        //日大风切入最大值
        if (Double.isInfinite(total1.getDayInputBigMax()) || Double.isNaN(total1.getDayInputBigMax())) {
            total1.setDayInputBigMax(0.0);
        } else {
            total1.setDayInputBigMax(StringUtils.round(total1.getDayInputBigMax(), 2));
        }

        //日小风切出
        if (Double.isInfinite(total1.getDayOutputSmall()) || Double.isNaN(total1.getDayOutputSmall())) {
            total1.setDayOutputSmall(0.0);
        } else {
            total1.setDayOutputSmall(StringUtils.round(total1.getDayOutputSmall(), 2));
        }
        //日小风切出最小值
        if (Double.isInfinite(total1.getDayOutputSmallMin()) || Double.isNaN(total1.getDayOutputSmallMin())) {
            total1.setDayOutputSmallMin(0.0);
        } else {
            total1.setDayOutputSmallMin(StringUtils.round(total1.getDayOutputSmallMin(), 2));
        }
        //日小风切出最大值
        if (Double.isInfinite(total1.getDayOutputSmallMax()) || Double.isNaN(total1.getDayOutputSmallMax())) {
            total1.setDayOutputSmallMax(0.0);
        } else {
            total1.setDayOutputSmallMax(StringUtils.round(total1.getDayOutputSmallMax(), 2));
        }

        //日大风切出
        if (Double.isInfinite(total1.getDayOutputBig()) || Double.isNaN(total1.getDayOutputBig())) {
            total1.setDayOutputBig(0.0);
        } else {
            total1.setDayOutputBig(StringUtils.round(total1.getDayOutputBig(), 2));
        }
        //日大风切出最大值
        if (Double.isInfinite(total1.getDayOutputBigMin()) || Double.isNaN(total1.getDayOutputBigMin())) {
            total1.setDayOutputBigMin(0.0);
        } else {
            total1.setDayOutputBigMin(StringUtils.round(total1.getDayOutputBigMin(), 2));
        }
        //日大风切出最大值
        if (Double.isInfinite(total1.getDayOutputBigMax()) || Double.isNaN(total1.getDayOutputBigMax())) {
            total1.setDayOutputBigMax(0.0);
        } else {
            total1.setDayOutputBigMax(StringUtils.round(total1.getDayOutputBigMax(), 2));
        }

        //月小风切入
        if (Double.isInfinite(total1.getMonthInputSmall()) || Double.isNaN(total1.getMonthInputSmall())) {
            total1.setMonthInputSmall(0.0);
        } else {
            total1.setMonthInputSmall(StringUtils.round(total1.getMonthInputSmall(), 2));
        }
        //月小风切入最小值
        if (Double.isInfinite(total1.getMonthInputSmallMin()) || Double.isNaN(total1.getMonthInputSmallMin())) {
            total1.setMonthInputSmallMin(0.0);
        } else {
            total1.setMonthInputSmallMin(StringUtils.round(total1.getMonthInputSmallMin(), 2));
        }
        //月小风切入最大值
        if (Double.isInfinite(total1.getMonthInputSmallMax()) || Double.isNaN(total1.getMonthInputSmallMax())) {
            total1.setMonthInputSmallMax(0.0);
        } else {
            total1.setMonthInputSmallMax(StringUtils.round(total1.getMonthInputSmallMax(), 2));
        }

        //月大风切入
        if (Double.isInfinite(total1.getMonthInputBig()) || Double.isNaN(total1.getMonthInputBig())) {
            total1.setMonthInputBig(0.0);
        } else {
            total1.setMonthInputBig(StringUtils.round(total1.getMonthInputBig(), 2));
        }
        //月大风切入最大值
        if (Double.isInfinite(total1.getMonthInputBigMin()) || Double.isNaN(total1.getMonthInputBigMin())) {
            total1.setMonthInputBigMin(0.0);
        } else {
            total1.setMonthInputBigMin(StringUtils.round(total1.getMonthInputBigMin(), 2));
        }
        //月大风切入最大值
        if (Double.isInfinite(total1.getMonthInputBigMax()) || Double.isNaN(total1.getMonthInputBigMax())) {
            total1.setMonthInputBigMax(0.0);
        } else {
            total1.setMonthInputBigMax(StringUtils.round(total1.getMonthInputBigMax(), 2));
        }

        //月小风切出
        if (Double.isInfinite(total1.getMonthOutputSmall()) || Double.isNaN(total1.getMonthOutputSmall())) {
            total1.setMonthOutputSmall(0.0);
        } else {
            total1.setMonthOutputSmall(StringUtils.round(total1.getMonthOutputSmall(), 2));
        }
        //月小风切出最小值
        if (Double.isInfinite(total1.getMonthOutputSmallMin()) || Double.isNaN(total1.getMonthOutputSmallMin())) {
            total1.setMonthOutputSmallMin(0.0);
        } else {
            total1.setMonthOutputSmallMin(StringUtils.round(total1.getMonthOutputSmallMin(), 2));
        }
        //月小风切出最大值
        if (Double.isInfinite(total1.getMonthOutputSmallMax()) || Double.isNaN(total1.getMonthOutputSmallMax())) {
            total1.setMonthOutputSmallMax(0.0);
        } else {
            total1.setMonthOutputSmallMax(StringUtils.round(total1.getMonthOutputSmallMax(), 2));
        }

        //月大风切出
        if (Double.isInfinite(total1.getMonthOutputBig()) || Double.isNaN(total1.getMonthOutputBig())) {
            total1.setMonthOutputBig(0.0);
        } else {
            total1.setMonthOutputBig(StringUtils.round(total1.getMonthOutputBig(), 2));
        }
        //月大风切出最大值
        if (Double.isInfinite(total1.getMonthOutputBigMin()) || Double.isNaN(total1.getMonthOutputBigMin())) {
            total1.setMonthOutputBigMin(0.0);
        } else {
            total1.setMonthOutputBigMin(StringUtils.round(total1.getMonthOutputBigMin(), 2));
        }
        //月大风切出最大值
        if (Double.isInfinite(total1.getMonthOutputBigMax()) || Double.isNaN(total1.getMonthOutputBigMax())) {
            total1.setMonthOutputBigMax(0.0);
        } else {
            total1.setMonthOutputBigMax(StringUtils.round(total1.getMonthOutputBigMax(), 2));
        }

        //年小风切入
        if (Double.isInfinite(total1.getYearInputSmall()) || Double.isNaN(total1.getYearInputSmall())) {
            total1.setYearInputSmall(0.0);
        } else {
            total1.setYearInputSmall(StringUtils.round(total1.getYearInputSmall(), 2));
        }
        //年小风切入最小值
        if (Double.isInfinite(total1.getYearInputSmallMin()) || Double.isNaN(total1.getYearInputSmallMin())) {
            total1.setYearInputSmallMin(0.0);
        } else {
            total1.setYearInputSmallMin(StringUtils.round(total1.getYearInputSmallMin(), 2));
        }
        //年小风切入最大值
        if (Double.isInfinite(total1.getYearInputSmallMax()) || Double.isNaN(total1.getYearInputSmallMax())) {
            total1.setYearInputSmallMax(0.0);
        } else {
            total1.setYearInputSmallMax(StringUtils.round(total1.getYearInputSmallMax(), 2));
        }

        //年大风切入
        if (Double.isInfinite(total1.getYearInputBig()) || Double.isNaN(total1.getYearInputBig())) {
            total1.setYearInputBig(0.0);
        } else {
            total1.setYearInputBig(StringUtils.round(total1.getYearInputBig(), 2));
        }
        //年大风切入最大值
        if (Double.isInfinite(total1.getYearInputBigMin()) || Double.isNaN(total1.getYearInputBigMin())) {
            total1.setYearInputBigMin(0.0);
        } else {
            total1.setYearInputBigMin(StringUtils.round(total1.getYearInputBigMin(), 2));
        }
        //年大风切入最大值
        if (Double.isInfinite(total1.getYearInputBigMax()) || Double.isNaN(total1.getYearInputBigMax())) {
            total1.setYearInputBigMax(0.0);
        } else {
            total1.setYearInputBigMax(StringUtils.round(total1.getYearInputBigMax(), 2));
        }

        //年小风切出
        if (Double.isInfinite(total1.getYearOutputSmall()) || Double.isNaN(total1.getYearOutputSmall())) {
            total1.setYearOutputSmall(0.0);
        } else {
            total1.setYearOutputSmall(StringUtils.round(total1.getYearOutputSmall(), 2));
        }
        //年小风切出最小值
        if (Double.isInfinite(total1.getYearOutputSmallMin()) || Double.isNaN(total1.getYearOutputSmallMin())) {
            total1.setYearOutputSmallMin(0.0);
        } else {
            total1.setYearOutputSmallMin(StringUtils.round(total1.getYearOutputSmallMin(), 2));
        }
        //年小风切出最大值
        if (Double.isInfinite(total1.getYearOutputSmallMax()) || Double.isNaN(total1.getYearOutputSmallMax())) {
            total1.setYearOutputSmallMax(0.0);
        } else {
            total1.setYearOutputSmallMax(StringUtils.round(total1.getYearOutputSmallMax(), 2));
        }

        //年大风切出
        if (Double.isInfinite(total1.getYearOutputBig()) || Double.isNaN(total1.getYearOutputBig())) {
            total1.setYearOutputBig(0.0);
        } else {
            total1.setYearOutputBig(StringUtils.round(total1.getYearOutputBig(), 2));
        }
        //年大风切出最大值
        if (Double.isInfinite(total1.getYearOutputBigMin()) || Double.isNaN(total1.getYearOutputBigMin())) {
            total1.setYearOutputBigMin(0.0);
        } else {
            total1.setYearOutputBigMin(StringUtils.round(total1.getYearOutputBigMin(), 2));
        }
        //年大风切出最大值
        if (Double.isInfinite(total1.getYearOutputBigMax()) || Double.isNaN(total1.getYearOutputBigMax())) {
            total1.setYearOutputBigMax(0.0);
        } else {
            total1.setYearOutputBigMax(StringUtils.round(total1.getYearOutputBigMax(), 2));
        }

        //小风切入
        if (Double.isInfinite(total1.getInputSmall()) || Double.isNaN(total1.getInputSmall())) {
            total1.setInputSmall(0.0);
        } else {
            total1.setInputSmall(StringUtils.round(total1.getInputSmall(), 2));
        }
        //小风切入最小值
        if (Double.isInfinite(total1.getInputSmallMin()) || Double.isNaN(total1.getInputSmallMin())) {
            total1.setInputSmallMin(0.0);
        } else {
            total1.setInputSmallMin(StringUtils.round(total1.getInputSmallMin(), 2));
        }
        //小风切入最大值
        if (Double.isInfinite(total1.getInputSmallMax()) || Double.isNaN(total1.getInputSmallMax())) {
            total1.setInputSmallMax(0.0);
        } else {
            total1.setInputSmallMax(StringUtils.round(total1.getInputSmallMax(), 2));
        }

        //大风切入
        if (Double.isInfinite(total1.getInputBig()) || Double.isNaN(total1.getInputBig())) {
            total1.setInputBig(0.0);
        } else {
            total1.setInputBig(StringUtils.round(total1.getInputBig(), 2));
        }
        //大风切入最大值
        if (Double.isInfinite(total1.getInputBigMin()) || Double.isNaN(total1.getInputBigMin())) {
            total1.setInputBigMin(0.0);
        } else {
            total1.setInputBigMin(StringUtils.round(total1.getInputBigMin(), 2));
        }
        //大风切入最大值
        if (Double.isInfinite(total1.getInputBigMax()) || Double.isNaN(total1.getInputBigMax())) {
            total1.setInputBigMax(0.0);
        } else {
            total1.setInputBigMax(StringUtils.round(total1.getInputBigMax(), 2));
        }

        //小风切出
        if (Double.isInfinite(total1.getOutputSmall()) || Double.isNaN(total1.getOutputSmall())) {
            total1.setOutputSmall(0.0);
        } else {
            total1.setOutputSmall(StringUtils.round(total1.getOutputSmall(), 2));
        }
        //小风切出最小值
        if (Double.isInfinite(total1.getOutputSmallMin()) || Double.isNaN(total1.getOutputSmallMin())) {
            total1.setOutputSmallMin(0.0);
        } else {
            total1.setOutputSmallMin(StringUtils.round(total1.getOutputSmallMin(), 2));
        }
        //小风切出最大值
        if (Double.isInfinite(total1.getOutputSmallMax()) || Double.isNaN(total1.getOutputSmallMax())) {
            total1.setOutputSmallMax(0.0);
        } else {
            total1.setOutputSmallMax(StringUtils.round(total1.getOutputSmallMax(), 2));
        }

        //大风切出
        if (Double.isInfinite(total1.getOutputBig()) || Double.isNaN(total1.getOutputBig())) {
            total1.setOutputBig(0.0);
        } else {
            total1.setOutputBig(StringUtils.round(total1.getOutputBig(), 2));
        }
        //大风切出最大值
        if (Double.isInfinite(total1.getOutputBigMin()) || Double.isNaN(total1.getOutputBigMin())) {
            total1.setOutputBigMin(0.0);
        } else {
            total1.setOutputBigMin(StringUtils.round(total1.getOutputBigMin(), 2));
        }
        //大风切出最大值
        if (Double.isInfinite(total1.getOutputBigMax()) || Double.isNaN(total1.getOutputBigMax())) {
            total1.setOutputBigMax(0.0);
        } else {
            total1.setOutputBigMax(StringUtils.round(total1.getOutputBigMax(), 2));
        }


        //日小风切入合格率
        if (Double.isInfinite(total1.getDayInputSmallRatio()) || Double.isNaN(total1.getDayInputSmallRatio())) {
            total1.setDayInputSmallRatio(0.0);
        } else {
            total1.setDayInputSmallRatio(StringUtils.round(total1.getDayInputSmallRatio(), 2));
        }
        //日小风切出合格率
        if (Double.isInfinite(total1.getDayOutputSmallRatio()) || Double.isNaN(total1.getDayOutputSmallRatio())) {
            total1.setDayOutputSmallRatio(0.0);
        } else {
            total1.setDayOutputSmallRatio(StringUtils.round(total1.getDayOutputSmallRatio(), 2));
        }

        //日大风切入合格率
        if (Double.isInfinite(total1.getDayInputBigRatio()) || Double.isNaN(total1.getDayInputBigRatio())) {
            total1.setDayInputBigRatio(0.0);
        } else {
            total1.setDayInputBigRatio(StringUtils.round(total1.getDayInputBigRatio(), 2));
        }

        //日大风切出合格率
        if (Double.isInfinite(total1.getDayOutputBigRatio()) || Double.isNaN(total1.getDayOutputBigRatio())) {
            total1.setDayOutputBigRatio(0.0);
        } else {
            total1.setDayOutputBigRatio(StringUtils.round(total1.getDayOutputBigRatio(), 2));
        }
        //月小风切入合格率
        if (Double.isInfinite(total1.getMonthInputSmallRatio()) || Double.isNaN(total1.getMonthInputSmallRatio())) {
            total1.setMonthInputSmallRatio(0.0);
        } else {
            total1.setMonthInputSmallRatio(StringUtils.round(total1.getMonthInputSmallRatio(), 2));
        }
        //月小风切出合格率
        if (Double.isInfinite(total1.getMonthOutputSmallRatio()) || Double.isNaN(total1.getMonthOutputSmallRatio())) {
            total1.setMonthOutputSmallRatio(0.0);
        } else {
            total1.setMonthOutputSmallRatio(StringUtils.round(total1.getMonthOutputSmallRatio(), 2));
        }

        //月大风切入合格率
        if (Double.isInfinite(total1.getMonthInputBigRatio()) || Double.isNaN(total1.getMonthInputBigRatio())) {
            total1.setMonthInputBigRatio(0.0);
        } else {
            total1.setMonthInputBigRatio(StringUtils.round(total1.getMonthInputBigRatio(), 2));
        }

        //月大风切出合格率
        if (Double.isInfinite(total1.getMonthOutputBigRatio()) || Double.isNaN(total1.getMonthOutputBigRatio())) {
            total1.setMonthOutputBigRatio(0.0);
        } else {
            total1.setMonthOutputBigRatio(StringUtils.round(total1.getMonthOutputBigRatio(), 2));
        }

        //年小风切入合格率
        if (Double.isInfinite(total1.getYearInputSmallRatio()) || Double.isNaN(total1.getYearInputSmallRatio())) {
            total1.setYearInputSmallRatio(0.0);
        } else {
            total1.setYearInputSmallRatio(StringUtils.round(total1.getYearInputSmallRatio(), 2));
        }
        //年小风切出合格率
        if (Double.isInfinite(total1.getYearOutputSmallRatio()) || Double.isNaN(total1.getYearOutputSmallRatio())) {
            total1.setYearOutputSmallRatio(0.0);
        } else {
            total1.setYearOutputSmallRatio(StringUtils.round(total1.getYearOutputSmallRatio(), 2));
        }

        //年大风切入合格率
        if (Double.isInfinite(total1.getYearInputBigRatio()) || Double.isNaN(total1.getYearInputBigRatio())) {
            total1.setYearInputBigRatio(0.0);
        } else {
            total1.setYearInputBigRatio(StringUtils.round(total1.getYearInputBigRatio(), 2));
        }

        //年大风切出合格率
        if (Double.isInfinite(total1.getYearOutputBigRatio()) || Double.isNaN(total1.getYearOutputBigRatio())) {
            total1.setYearOutputBigRatio(0.0);
        } else {
            total1.setYearOutputBigRatio(StringUtils.round(total1.getYearOutputBigRatio(), 2));
        }

        //总小风切入合格率
        if (Double.isInfinite(total1.getInputSmallRatio()) || Double.isNaN(total1.getInputSmallRatio())) {
            total1.setInputSmallRatio(0.0);
        } else {
            total1.setInputSmallRatio(StringUtils.round(total1.getInputSmallRatio(), 2));
        }
        //总小风切出合格率
        if (Double.isInfinite(total1.getOutputSmallRatio()) || Double.isNaN(total1.getOutputSmallRatio())) {
            total1.setOutputSmallRatio(0.0);
        } else {
            total1.setOutputSmallRatio(StringUtils.round(total1.getOutputSmallRatio(), 2));
        }

        //总大风切入合格率
        if (Double.isInfinite(total1.getInputBigRatio()) || Double.isNaN(total1.getInputBigRatio())) {
            total1.setInputBigRatio(0.0);
        } else {
            total1.setInputBigRatio(StringUtils.round(total1.getInputBigRatio(), 2));
        }

        //总大风切出合格率
        if (Double.isInfinite(total1.getOutputBigMaxRatio()) || Double.isNaN(total1.getOutputBigMaxRatio())) {
            total1.setOutputBigMaxRatio(0.0);
        } else {
            total1.setOutputBigMaxRatio(StringUtils.round(total1.getOutputBigMaxRatio(), 2));
        }
    }

    private void newMethod(Date end, Date daybegin, Date monthbegin, Date yearbegin, String windturbineId, ProEconInOrOutSpeedTotal total1, ProEconInOrOutSpeedTotal2 total2) {
        buildDay(end, daybegin, windturbineId, total1, total2);
        buildMonth(end, monthbegin, windturbineId, total1, total2);
        buildyear(end, yearbegin, windturbineId, total1, total2);

        QueryWrapper<ProEconInOrOutSpeedTotal> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("windturbine_id", windturbineId);
        List<ProEconInOrOutSpeedTotal> items = proEconInOrOutSpeedTotalService.list(queryWrapper);
        //                .stream()
        //                .filter(i -> i.getWindturbineId().equals(windturbineId)).collect(Collectors.toList());

        items.add(total1);

        //总小风切入
        DoubleSummaryStatistics summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayInputSmall()) && i.getDayInputSmall() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayInputSmall).summaryStatistics();
        total1.setInputSmall(summaryStatistics.getAverage());
        //总小风切入最大值
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayInputSmallMax()) && i.getDayInputSmallMax() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayInputSmallMax).summaryStatistics();
        total1.setInputSmallMax(summaryStatistics.getMax());
        //总小风切入最小值
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayInputSmallMin()) && i.getDayInputSmallMin() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayInputSmallMin).summaryStatistics();
        total1.setInputSmallMin(summaryStatistics.getMin());
        //总大风切入
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayInputBig()) && i.getDayInputBig() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayInputBig).summaryStatistics();
        total1.setInputBig(summaryStatistics.getAverage());
        //总大风切入最大值
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayInputBigMax()) && i.getDayInputBigMax() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayInputBigMax).summaryStatistics();
        total1.setInputBigMax(summaryStatistics.getMax());
        //总大风切入最小值
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayInputBigMin()) && i.getDayInputBigMin() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayInputBigMin).summaryStatistics();
        total1.setInputBigMin(summaryStatistics.getMin());

        //总小风切出
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayOutputSmall()) && i.getDayOutputSmall() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayOutputSmall).summaryStatistics();
        total1.setOutputSmall(summaryStatistics.getAverage());
        //总小风切出最大值
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayOutputSmallMax()) && i.getDayOutputSmallMax() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayOutputSmallMax).summaryStatistics();
        total1.setOutputSmallMax(summaryStatistics.getMax());
        //总小风切出最小值
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayOutputSmallMin()) && i.getDayOutputSmallMin() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayOutputSmallMin).summaryStatistics();
        total1.setOutputSmallMin(summaryStatistics.getMin());

        //总大风切出
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayOutputBig()) && i.getDayOutputBig() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayOutputBig).summaryStatistics();
        total1.setOutputBig(summaryStatistics.getAverage());
        //总大风切出最大值
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayOutputBigMax()) && i.getDayOutputBigMax() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayOutputBigMax).summaryStatistics();
        total1.setOutputBigMax(summaryStatistics.getMax());
        //总大风切出最小值
        summaryStatistics = items.stream()
                .filter(i -> StringUtils.notEmp(i.getDayOutputBigMin()) && i.getDayOutputBigMin() > 0)
                .mapToDouble(ProEconInOrOutSpeedTotal::getDayOutputBigMin).summaryStatistics();
        total1.setOutputBigMin(summaryStatistics.getMin());


        QueryWrapper<ProEconInputOrOutputSpeed> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("windturbine_id", windturbineId).isNotNull("speed").ne("speed", 0);
        List<ProEconInputOrOutputSpeed> recordList = proEconInputOrOutputSpeedService.list(queryWrapper2);
        //                .stream()
        //                .filter(i -> i.getWindturbineId().equals(windturbineId) && StringUtils.notEmp(i.getSpeed())
        //                        && i.getSpeed() != 0).collect(Collectors.toList());


        List<ProEconInputOrOutputSpeed> inputrecordList = recordList.stream()
                .filter(i -> i.getInputOrOutput() == 1).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> outputrecordList = recordList.stream()
                .filter(i -> i.getInputOrOutput() == 0).collect(Collectors.toList());


        List<ProEconInputOrOutputSpeed> AList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 3).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> ACountList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> BList = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 3).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> BCountList = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> CList = inputrecordList.stream().filter(i -> i.getSpeed() >= 25).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> CCountList = inputrecordList.stream().filter(i -> i.getSpeed() > 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> DList = outputrecordList.stream().filter(i -> i.getSpeed() >= 25).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> DCountList = outputrecordList
                .stream().filter(i -> i.getSpeed() > 11).collect(Collectors.toList());

        //总小风切入合格率
        if (ACountList.size() != 0) {
            total1.setInputSmallRatio(new BigDecimal(AList.size()).divide(new BigDecimal(ACountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setInputSmallRatio(0.0);
        }
        //总小风切出合格率
        if (BCountList.size() != 0) {
            total1.setOutputSmallRatio(new BigDecimal(BList.size()).divide(new BigDecimal(BCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setOutputSmallRatio(0.0);
        }
        //总大风切入合格率
        if (CCountList.size() != 0) {
            total1.setInputBigRatio(new BigDecimal(CList.size()).divide(new BigDecimal(CCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setInputBigRatio(0.0);
        }
        //总大风切出合格率
        if (DCountList.size() != 0) {
            total1.setOutputBigMaxRatio(new BigDecimal(DList.size()).divide(new BigDecimal(DCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setOutputBigMaxRatio(0.0);
        }

    }

    private void buildDay(Date end, Date daybegin, String windturbineId, ProEconInOrOutSpeedTotal total1, ProEconInOrOutSpeedTotal2 total2) {
        int count;

        QueryWrapper<ProEconInputOrOutputSpeed> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("record_date", daybegin).le("record_date", end).eq("windturbine_id", windturbineId).isNotNull("speed");
        List<ProEconInputOrOutputSpeed> recordList = proEconInputOrOutputSpeedService.list(queryWrapper);
        //                .stream()
        //                .filter(i -> i.getWindturbineId().equals(windturbineId) && StringUtils.notEmp(i.getSpeed())
        //                        && (i.getRecordDate().compareTo(daybegin) == 0 || i.getRecordDate().after(daybegin))
        //                        && (i.getRecordDate().compareTo(end) == 0 || i.getRecordDate().before(end))
        //                        && i.getSpeed() != 0).collect(Collectors.toList());


        List<ProEconInputOrOutputSpeed> inputrecordList = recordList.stream()
                .filter(i -> i.getInputOrOutput() == 1).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> outputrecordList = recordList.stream()
                .filter(i -> i.getInputOrOutput() == 0).collect(Collectors.toList());


        List<ProEconInputOrOutputSpeed> AList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 3).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> ACountList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> BList = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 3).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> BCountList = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> CList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() >= 25).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> CCountList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() > 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> DList = outputrecordList.stream().filter(i -> i.getSpeed() >= 25).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> DCountList = outputrecordList
                .stream().filter(i -> i.getSpeed() > 11).collect(Collectors.toList());


        if (ACountList.size() != 0) {
            total1.setDayInputSmallRatio(new BigDecimal(AList.size()).divide(new BigDecimal(ACountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setDayInputSmallRatio(0.0);
        }

        if (BCountList.size() != 0) {
            total1.setDayOutputSmallRatio(new BigDecimal(BList.size()).divide(new BigDecimal(BCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setDayOutputSmallRatio(0.0);
        }

        if (CCountList.size() != 0) {
            total1.setDayInputBigRatio(new BigDecimal(CList.size()).divide(new BigDecimal(CCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setDayInputBigRatio(0.0);
        }

        if (DCountList.size() != 0) {
            total1.setDayOutputBigRatio(new BigDecimal(DList.size()).divide(new BigDecimal(DCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setDayOutputBigRatio(0.0);
        }


        List<ProEconInputOrOutputSpeed> A1List = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() < 2).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A2List = inputrecordList.stream().filter(i -> i.getSpeed() >= 2
                && i.getSpeed() < 2.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A3List = inputrecordList.stream().filter(i -> i.getSpeed() >= 2.5
                && i.getSpeed() < 3).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A4List = inputrecordList.stream().filter(i -> i.getSpeed() >= 3
                && i.getSpeed() < 3.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A5List = inputrecordList.stream().filter(i -> i.getSpeed() >= 3.5
                && i.getSpeed() < 4).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A6List = inputrecordList.stream().filter(i -> i.getSpeed() >= 4
                && i.getSpeed() < 5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A7List = inputrecordList.stream().filter(i -> i.getSpeed() >= 5
                && i.getSpeed() <= 11).collect(Collectors.toList());

        DoubleSummaryStatistics summaryStatistics = inputrecordList.stream().filter(i ->
                        i.getSpeed() > 0 && i.getSpeed() < 5)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setDayInputSmall(summaryStatistics.getAverage());
        total1.setDayInputSmallMax(summaryStatistics.getMax());
        total1.setDayInputSmallMin(summaryStatistics.getMin());

        summaryStatistics = inputrecordList.stream().filter(i ->
                        i.getSpeed() > 18 && i.getSpeed() < 30)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setDayInputBig(summaryStatistics.getAverage());
        total1.setDayInputBigMax(summaryStatistics.getMax());
        total1.setDayInputBigMin(summaryStatistics.getMin());


        total2.setDaya1((double) A1List.size());
        total2.setDaya2((double) A2List.size());
        total2.setDaya3((double) A3List.size());
        total2.setDaya4((double) A4List.size());
        total2.setDaya5((double) A5List.size());
        total2.setDaya6((double) A6List.size());
        total2.setDaya7((double) A7List.size());


        count = A1List.size() + A2List.size() + A3List.size() + A4List.size() + A5List.size() + A6List.size() + A7List.size();

        if (count > 0) {
            total2.setDaya8(new BigDecimal(A1List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDaya9(new BigDecimal(A2List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDaya10(new BigDecimal(A3List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDaya11(new BigDecimal(A4List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDaya12(new BigDecimal(A5List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDaya13(new BigDecimal(A6List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDaya14(new BigDecimal(A7List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());


        } else {
            total2.setDaya8(0.0);
            total2.setDaya9(0.0);
            total2.setDaya10(0.0);
            total2.setDaya11(0.0);
            total2.setDaya12(0.0);
            total2.setDaya13(0.0);
            total2.setDaya14(0.0);
        }


        List<ProEconInputOrOutputSpeed> B1List = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() < 2).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B2List = outputrecordList.stream().filter(i -> i.getSpeed() >= 2
                && i.getSpeed() < 2.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B3List = outputrecordList.stream().filter(i -> i.getSpeed() >= 2.5
                && i.getSpeed() < 3).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B4List = outputrecordList.stream().filter(i -> i.getSpeed() >= 3
                && i.getSpeed() < 3.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B5List = outputrecordList.stream().filter(i -> i.getSpeed() >= 3.5
                && i.getSpeed() < 4).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B6List = outputrecordList.stream().filter(i -> i.getSpeed() >= 4
                && i.getSpeed() < 5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B7List = outputrecordList.stream().filter(i -> i.getSpeed() >= 5
                && i.getSpeed() <= 11).collect(Collectors.toList());


        summaryStatistics = outputrecordList.stream().filter(i ->
                        i.getSpeed() > 0 && i.getSpeed() < 5)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setDayOutputSmall(summaryStatistics.getAverage());
        total1.setDayOutputSmallMax(summaryStatistics.getMax());
        total1.setDayOutputSmallMin(summaryStatistics.getMin());

        summaryStatistics = outputrecordList.stream().filter(i ->
                        i.getSpeed() > 18 && i.getSpeed() < 30)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setDayOutputBig(summaryStatistics.getAverage());
        total1.setDayOutputBigMax(summaryStatistics.getMax());
        total1.setDayOutputBigMin(summaryStatistics.getMin());


        total2.setDayb1((double) B1List.size());
        total2.setDayb2((double) B2List.size());
        total2.setDayb3((double) B3List.size());
        total2.setDayb4((double) B4List.size());
        total2.setDayb5((double) B5List.size());
        total2.setDayb6((double) B6List.size());
        total2.setDayb7((double) B7List.size());

        count = B1List.size() + B2List.size() + B3List.size() + B4List.size() + B5List.size() + B6List.size() + B7List.size();

        if (count > 0) {
            total2.setDayb8(new BigDecimal(B1List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDayb9(new BigDecimal(B2List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDayb10(new BigDecimal(B3List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDayb11(new BigDecimal(B4List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDayb12(new BigDecimal(B5List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDayb13(new BigDecimal(B6List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setDayb14(new BigDecimal(B7List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());


        } else {
            total2.setDayb8(0.0);
            total2.setDayb9(0.0);
            total2.setDayb10(0.0);
            total2.setDayb11(0.0);
            total2.setDayb12(0.0);
            total2.setDayb13(0.0);
            total2.setDayb14(0.0);
        }
    }

    private void buildMonth(Date end, Date monthbegin, String windturbineId, ProEconInOrOutSpeedTotal total1, ProEconInOrOutSpeedTotal2 total2) {
        int count;
        QueryWrapper<ProEconInputOrOutputSpeed> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("record_date", monthbegin).le("record_date", end).eq("windturbine_id", windturbineId).isNotNull("speed");
        List<ProEconInputOrOutputSpeed> recordList = proEconInputOrOutputSpeedService.list(queryWrapper);
        //        .stream()
        //                .filter(i -> i.getWindturbineId().equals(windturbineId) && StringUtils.notEmp(i.getSpeed())
        //                        && (i.getRecordDate().compareTo(monthbegin) == 0 || i.getRecordDate().after(monthbegin))
        //                        && (i.getRecordDate().compareTo(end) == 0 || i.getRecordDate().before(end))
        //                        && i.getSpeed() != 0).collect(Collectors.toList());


        List<ProEconInputOrOutputSpeed> inputrecordList = recordList.stream()
                .filter(i -> i.getInputOrOutput() == 1).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> outputrecordList = recordList.stream()
                .filter(i -> i.getInputOrOutput() == 0).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> AList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 3).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> ACountList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> BList = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 3).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> BCountList = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> CList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() >= 25).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> CCountList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() > 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> DList = outputrecordList.stream().filter(i -> i.getSpeed() >= 25).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> DCountList = outputrecordList
                .stream().filter(i -> i.getSpeed() > 11).collect(Collectors.toList());

        if (ACountList.size() != 0) {
            total1.setMonthInputSmallRatio(new BigDecimal(AList.size()).divide(new BigDecimal(ACountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setMonthInputSmallRatio(0.0);
        }

        if (BCountList.size() != 0) {
            total1.setMonthOutputSmallRatio(new BigDecimal(BList.size()).divide(new BigDecimal(BCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setMonthOutputSmallRatio(0.0);
        }

        if (CCountList.size() != 0) {
            total1.setMonthInputBigRatio(new BigDecimal(CList.size()).divide(new BigDecimal(CCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setMonthInputBigRatio(0.0);
        }

        if (DCountList.size() != 0) {
            total1.setMonthOutputBigRatio(new BigDecimal(DList.size()).divide(new BigDecimal(DCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setMonthOutputBigRatio(0.0);
        }

        List<ProEconInputOrOutputSpeed> A1List = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() < 2).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A2List = inputrecordList.stream().filter(i -> i.getSpeed() >= 2
                && i.getSpeed() < 2.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A3List = inputrecordList.stream().filter(i -> i.getSpeed() >= 2.5
                && i.getSpeed() < 3).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A4List = inputrecordList.stream().filter(i -> i.getSpeed() >= 3
                && i.getSpeed() < 3.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A5List = inputrecordList.stream().filter(i -> i.getSpeed() >= 3.5
                && i.getSpeed() < 4).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A6List = inputrecordList.stream().filter(i -> i.getSpeed() >= 4
                && i.getSpeed() < 5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A7List = inputrecordList.stream().filter(i -> i.getSpeed() >= 5
                && i.getSpeed() <= 11).collect(Collectors.toList());

        DoubleSummaryStatistics summaryStatistics = inputrecordList.stream().filter(i ->
                        i.getSpeed() > 0 && i.getSpeed() < 5)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setMonthInputSmall(summaryStatistics.getAverage());
        total1.setMonthInputSmallMax(summaryStatistics.getMax());
        total1.setMonthInputSmallMin(summaryStatistics.getMin());

        summaryStatistics = inputrecordList.stream().filter(i ->
                        i.getSpeed() > 18 && i.getSpeed() < 30)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setMonthInputBig(summaryStatistics.getAverage());
        total1.setMonthInputBigMax(summaryStatistics.getMax());
        total1.setMonthInputBigMin(summaryStatistics.getMin());


        total2.setMontha1((double) A1List.size());
        total2.setMontha2((double) A2List.size());
        total2.setMontha3((double) A3List.size());
        total2.setMontha4((double) A4List.size());
        total2.setMontha5((double) A5List.size());
        total2.setMontha6((double) A6List.size());
        total2.setMontha7((double) A7List.size());


        count = A1List.size() + A2List.size() + A3List.size() + A4List.size() + A5List.size() + A6List.size() + A7List.size();

        if (count > 0) {
            total2.setMontha8(new BigDecimal(A1List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMontha9(new BigDecimal(A2List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMontha10(new BigDecimal(A3List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMontha11(new BigDecimal(A4List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMontha12(new BigDecimal(A5List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMontha13(new BigDecimal(A6List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMontha14(new BigDecimal(A7List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());


        } else {
            total2.setMontha8(0.0);
            total2.setMontha9(0.0);
            total2.setMontha10(0.0);
            total2.setMontha11(0.0);
            total2.setMontha12(0.0);
            total2.setMontha13(0.0);
            total2.setMontha14(0.0);
        }


        List<ProEconInputOrOutputSpeed> B1List = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() < 2).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B2List = outputrecordList.stream().filter(i -> i.getSpeed() >= 2
                && i.getSpeed() < 2.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B3List = outputrecordList.stream().filter(i -> i.getSpeed() >= 2.5
                && i.getSpeed() < 3).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B4List = outputrecordList.stream().filter(i -> i.getSpeed() >= 3
                && i.getSpeed() < 3.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B5List = outputrecordList.stream().filter(i -> i.getSpeed() >= 3.5
                && i.getSpeed() < 4).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B6List = outputrecordList.stream().filter(i -> i.getSpeed() >= 4
                && i.getSpeed() < 5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B7List = outputrecordList.stream().filter(i -> i.getSpeed() >= 5
                && i.getSpeed() <= 11).collect(Collectors.toList());


        summaryStatistics = outputrecordList.stream().filter(i ->
                        i.getSpeed() > 0 && i.getSpeed() < 5)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setMonthOutputSmall(summaryStatistics.getAverage());
        total1.setMonthOutputSmallMax(summaryStatistics.getMax());
        total1.setMonthOutputSmallMin(summaryStatistics.getMin());

        summaryStatistics = outputrecordList.stream().filter(i ->
                        i.getSpeed() > 18 && i.getSpeed() < 30)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setMonthOutputBig(summaryStatistics.getAverage());
        total1.setMonthOutputBigMax(summaryStatistics.getMax());
        total1.setMonthOutputBigMin(summaryStatistics.getMin());


        total2.setMonthb1((double) B1List.size());
        total2.setMonthb2((double) B2List.size());
        total2.setMonthb3((double) B3List.size());
        total2.setMonthb4((double) B4List.size());
        total2.setMonthb5((double) B5List.size());
        total2.setMonthb6((double) B6List.size());
        total2.setMonthb7((double) B7List.size());

        count = B1List.size() + B2List.size() + B3List.size() + B4List.size() + B5List.size() + B6List.size() + B7List.size();

        if (count > 0) {
            total2.setMonthb8(new BigDecimal(B1List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMonthb9(new BigDecimal(B2List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMonthb10(new BigDecimal(B3List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMonthb11(new BigDecimal(B4List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMonthb12(new BigDecimal(B5List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMonthb13(new BigDecimal(B6List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setMonthb14(new BigDecimal(B7List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());


        } else {
            total2.setMonthb8(0.0);
            total2.setMonthb9(0.0);
            total2.setMonthb10(0.0);
            total2.setMonthb11(0.0);
            total2.setMonthb12(0.0);
            total2.setMonthb13(0.0);
            total2.setMonthb14(0.0);
        }
    }

    private void buildyear(Date end, Date yearbegin, String windturbineId, ProEconInOrOutSpeedTotal total1, ProEconInOrOutSpeedTotal2 total2) {
        int count;
        QueryWrapper<ProEconInputOrOutputSpeed> queryWrapper = new QueryWrapper<>();
        queryWrapper.ge("record_date", yearbegin).le("record_date", end).eq("windturbine_id", windturbineId).isNotNull("speed");
        List<ProEconInputOrOutputSpeed> recordList = proEconInputOrOutputSpeedService.list(queryWrapper);
        //        .stream()
        //                .filter(i -> i.getWindturbineId().equals(windturbineId) && StringUtils.notEmp(i.getSpeed())
        //                        && (i.getRecordDate().compareTo(yearbegin) == 0 || i.getRecordDate().after(yearbegin))
        //                        && (i.getRecordDate().compareTo(end) == 0 || i.getRecordDate().before(end))
        //                        && i.getSpeed() != 0).collect(Collectors.toList());


        List<ProEconInputOrOutputSpeed> inputrecordList = recordList.stream()
                .filter(i -> i.getInputOrOutput() == 1).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> outputrecordList = recordList.stream()
                .filter(i -> i.getInputOrOutput() == 0).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> AList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 3).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> ACountList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> BList = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 3).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> BCountList = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() <= 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> CList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() >= 25).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> CCountList = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() > 11).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> DList = outputrecordList.stream().filter(i -> i.getSpeed() >= 25).collect(Collectors.toList());

        List<ProEconInputOrOutputSpeed> DCountList = outputrecordList
                .stream().filter(i -> i.getSpeed() > 11).collect(Collectors.toList());

        if (ACountList.size() != 0) {
            total1.setYearInputSmallRatio(new BigDecimal(AList.size()).divide(new BigDecimal(ACountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setYearInputSmallRatio(0.0);
        }

        if (BCountList.size() != 0) {
            total1.setYearOutputSmallRatio(new BigDecimal(BList.size()).divide(new BigDecimal(BCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setYearOutputSmallRatio(0.0);
        }

        if (CCountList.size() != 0) {
            total1.setYearInputBigRatio(new BigDecimal(CList.size()).divide(new BigDecimal(CCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setYearInputBigRatio(0.0);
        }

        if (DCountList.size() != 0) {
            total1.setYearOutputBigRatio(new BigDecimal(DList.size()).divide(new BigDecimal(DCountList.size()),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
        } else {
            total1.setYearOutputBigRatio(0.0);
        }

        List<ProEconInputOrOutputSpeed> A1List = inputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() < 2).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A2List = inputrecordList.stream().filter(i -> i.getSpeed() >= 2
                && i.getSpeed() < 2.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A3List = inputrecordList.stream().filter(i -> i.getSpeed() >= 2.5
                && i.getSpeed() < 3).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A4List = inputrecordList.stream().filter(i -> i.getSpeed() >= 3
                && i.getSpeed() < 3.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A5List = inputrecordList.stream().filter(i -> i.getSpeed() >= 3.5
                && i.getSpeed() < 4).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A6List = inputrecordList.stream().filter(i -> i.getSpeed() >= 4
                && i.getSpeed() < 5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> A7List = inputrecordList.stream().filter(i -> i.getSpeed() >= 5
                && i.getSpeed() <= 11).collect(Collectors.toList());

        DoubleSummaryStatistics summaryStatistics = inputrecordList.stream().filter(i ->
                        i.getSpeed() > 0 && i.getSpeed() < 5)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setYearInputSmall(summaryStatistics.getAverage());
        total1.setYearInputSmallMax(summaryStatistics.getMax());
        total1.setYearInputSmallMin(summaryStatistics.getMin());

        summaryStatistics = inputrecordList.stream().filter(i ->
                        i.getSpeed() > 18 && i.getSpeed() < 30)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setYearInputBig(summaryStatistics.getAverage());
        total1.setYearInputBigMax(summaryStatistics.getMax());
        total1.setYearInputBigMin(summaryStatistics.getMin());


        total2.setYeara1((double) A1List.size());
        total2.setYeara2((double) A2List.size());
        total2.setYeara3((double) A3List.size());
        total2.setYeara4((double) A4List.size());
        total2.setYeara5((double) A5List.size());
        total2.setYeara6((double) A6List.size());
        total2.setYeara7((double) A7List.size());


        count = A1List.size() + A2List.size() + A3List.size() + A4List.size() + A5List.size() + A6List.size() + A7List.size();

        if (count > 0) {
            total2.setYeara8(new BigDecimal(A1List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYeara9(new BigDecimal(A2List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYeara10(new BigDecimal(A3List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYeara11(new BigDecimal(A4List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYeara12(new BigDecimal(A5List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYeara13(new BigDecimal(A6List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYeara14(new BigDecimal(A7List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());


        } else {
            total2.setYeara8(0.0);
            total2.setYeara9(0.0);
            total2.setYeara10(0.0);
            total2.setYeara11(0.0);
            total2.setYeara12(0.0);
            total2.setYeara13(0.0);
            total2.setYeara14(0.0);
        }


        List<ProEconInputOrOutputSpeed> B1List = outputrecordList.stream().filter(i -> i.getSpeed() > 0
                && i.getSpeed() < 2).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B2List = outputrecordList.stream().filter(i -> i.getSpeed() >= 2
                && i.getSpeed() < 2.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B3List = outputrecordList.stream().filter(i -> i.getSpeed() >= 2.5
                && i.getSpeed() < 3).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B4List = outputrecordList.stream().filter(i -> i.getSpeed() >= 3
                && i.getSpeed() < 3.5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B5List = outputrecordList.stream().filter(i -> i.getSpeed() >= 3.5
                && i.getSpeed() < 4).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B6List = outputrecordList.stream().filter(i -> i.getSpeed() >= 4
                && i.getSpeed() < 5).collect(Collectors.toList());
        List<ProEconInputOrOutputSpeed> B7List = outputrecordList.stream().filter(i -> i.getSpeed() >= 5
                && i.getSpeed() <= 11).collect(Collectors.toList());


        summaryStatistics = outputrecordList.stream().filter(i ->
                        i.getSpeed() > 0 && i.getSpeed() < 5)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setYearOutputSmall(summaryStatistics.getAverage());
        total1.setYearOutputSmallMax(summaryStatistics.getMax());
        total1.setYearOutputSmallMin(summaryStatistics.getMin());

        summaryStatistics = outputrecordList.stream().filter(i ->
                        i.getSpeed() > 18 && i.getSpeed() < 30)
                .mapToDouble(ProEconInputOrOutputSpeed::getSpeed).summaryStatistics();

        total1.setYearOutputBig(summaryStatistics.getAverage());
        total1.setYearOutputBigMax(summaryStatistics.getMax());
        total1.setYearOutputBigMin(summaryStatistics.getMin());


        total2.setYearb1((double) B1List.size());
        total2.setYearb2((double) B2List.size());
        total2.setYearb3((double) B3List.size());
        total2.setYearb4((double) B4List.size());
        total2.setYearb5((double) B5List.size());
        total2.setYearb6((double) B6List.size());
        total2.setYearb7((double) B7List.size());

        count = B1List.size() + B2List.size() + B3List.size() + B4List.size() + B5List.size() + B6List.size() + B7List.size();

        if (count > 0) {
            total2.setYearb8(new BigDecimal(B1List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYearb9(new BigDecimal(B2List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYearb10(new BigDecimal(B3List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYearb11(new BigDecimal(B4List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYearb12(new BigDecimal(B5List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYearb13(new BigDecimal(B6List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());
            total2.setYearb14(new BigDecimal(B7List.size()).divide(new BigDecimal(count),
                    4, RoundingMode.HALF_EVEN).multiply(new BigDecimal(100)).doubleValue());


        } else {
            total2.setYearb8(0.0);
            total2.setYearb9(0.0);
            total2.setYearb10(0.0);
            total2.setYearb11(0.0);
            total2.setYearb12(0.0);
            total2.setYearb13(0.0);
            total2.setYearb14(0.0);
        }
    }

}

