package com.gyee.generation.service;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.common.model.PointData;
import com.gyee.common.model.StringUtils;
import com.gyee.generation.feign.AdapterApi;
import com.gyee.generation.init.CacheContext;
import com.gyee.generation.model.PointData2;
import com.gyee.generation.model.auto.*;
import com.gyee.generation.model.vo.CompanyType;
import com.gyee.generation.model.vo.Location;
import com.gyee.generation.model.vo.WpType;
import com.gyee.generation.service.auto.*;
import com.gyee.generation.util.DateUtils;
import com.gyee.generation.util.realtimesource.IEdosUtil;
import com.gyee.generation.util.statisticcs.Initial;
import com.xxl.job.core.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class WindPowerInfo1Service {
//    @Override
//    public void run(ApplicationArguments args) throws Exception {
//        Date date = new Date();
////        writeGf(date);
//        writeReport1(date);
//        writeReport2(date);
//        writeReport3(date);
//    }

    private static final Logger logger = LoggerFactory.getLogger(WindPowerInfo1Service.class);
    @Resource
    private IEdosUtil edosUtil;

    @Resource
    private IProEconPowerstationInfoDay1Service proEconPowerstationInfoDay1Service;

    @Resource
    private IProEconEquipmentInfoDay1Service proEconEquipmentInfoDay1Service;


    @Resource
    private IProEconAnalysisSubtableBottomService iProEconAnalysisSubtableBottomService;

    @Resource
    private IStationInfoHourService stationInfoHourService;


    @Resource
    private IProBaseBackfillService iProBaseBackfillService;


    @Resource
    private IProEconEquipmentInfoJsService iProEconEquipmentInfoJsService;

    @Resource
    private AdapterApi adapter;


    public URI goldenUri() {
        return URI.create("http://10.220.1.8:8011/ts");
    }


    /**
     * 计算区域日信息
     */
    public void calRegionInfoDay(Date recordDate) throws Exception {

        Calendar c = Calendar.getInstance();
        c.setTime(recordDate);
        if (c.get(Calendar.HOUR_OF_DAY) == 0 && c.get(Calendar.MINUTE) == 0) {
            c.add(Calendar.DAY_OF_MONTH, -1);
        }


        recordDate = DateUtils.truncate(c.getTime());
        QueryWrapper<ProEconPowerstationInfoDay1> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.cp.getValue());
        List<ProEconPowerstationInfoDay1> wpinfodayls = proEconPowerstationInfoDay1Service.list(queryWrapper);
        //                .stream()
        //                .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
        ////                        && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
        //                        && i.getLocation().equals(Location.cp.getValue()))
        //                .collect(Collectors.toList());
        if (!wpinfodayls.isEmpty()) {

            Map<String, Map<String, List<ProEconPowerstationInfoDay1>>> rgmap = new HashMap<>();


            for (ProEconPowerstationInfoDay1 wpinfo : wpinfodayls) {

                if (rgmap.containsKey(wpinfo.getRegionId())) {
                    Map<String, List<ProEconPowerstationInfoDay1>> map = rgmap.get(wpinfo.getRegionId());
                    List<ProEconPowerstationInfoDay1> qbls = map.get(CompanyType.qb.id);
                    List<ProEconPowerstationInfoDay1> fdls = map.get(CompanyType.fd.id);
                    List<ProEconPowerstationInfoDay1> gfls = map.get(CompanyType.gf.id);

                    if (wpinfo.getForeignKeyId().contains("-1")) {
                        fdls.add(wpinfo);
                    } else if (wpinfo.getForeignKeyId().contains("-2")) {
                        gfls.add(wpinfo);
                    } else if (wpinfo.getForeignKeyId().contains("0")) {
                        qbls.add(wpinfo);
                    }

                } else {
                    Map<String, List<ProEconPowerstationInfoDay1>> map = new HashMap<>();

                    List<ProEconPowerstationInfoDay1> qbls = new ArrayList<>();
                    List<ProEconPowerstationInfoDay1> gfls = new ArrayList<>();
                    List<ProEconPowerstationInfoDay1> fdls = new ArrayList<>();

                    if (wpinfo.getForeignKeyId().contains("-1")) {
                        fdls.add(wpinfo);
                    } else if (wpinfo.getForeignKeyId().contains("-2")) {
                        gfls.add(wpinfo);
                    } else if (wpinfo.getForeignKeyId().contains("0")) {
                        qbls.add(wpinfo);
                    }

                    map.put(CompanyType.qb.id, qbls);
                    map.put(CompanyType.fd.id, fdls);
                    map.put(CompanyType.gf.id, gfls);
                    rgmap.put(wpinfo.getRegionId(), map);
                }
            }


            //判断是否有重复记录，先删除重复记录
            QueryWrapper<ProEconPowerstationInfoDay1> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.rg.getValue());
            List<String> idls = proEconPowerstationInfoDay1Service.list(queryWrapper2)
                    .stream()
                    //                    .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
                    ////                            && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
                    //                            && i.getLocation().equals(Location.rg.getValue()))
                    .map(ProEconPowerstationInfoDay1::getId)
                    .collect(Collectors.toList());

            if (idls.size() > 0) {

                proEconPowerstationInfoDay1Service.removeByIds(idls);

            }
            for (Map.Entry<String, Map<String, List<ProEconPowerstationInfoDay1>>> entry : rgmap.entrySet()) {
                Map<String, List<ProEconPowerstationInfoDay1>> map = entry.getValue();
                List<ProEconPowerstationInfoDay1> qbls = map.get(CompanyType.qb.id);
                List<ProEconPowerstationInfoDay1> fdls = map.get(CompanyType.fd.id);
                List<ProEconPowerstationInfoDay1> gfls = map.get(CompanyType.gf.id);
                //                if(CacheContext.cpwpmap.size()==qbls.size())
                //                {

                ProEconPowerstationInfoDay1 qb = new ProEconPowerstationInfoDay1();
                ProEconPowerstationInfoDay1 fd = new ProEconPowerstationInfoDay1();
                ProEconPowerstationInfoDay1 gf = new ProEconPowerstationInfoDay1();

                if (CacheContext.rgmap.containsKey(entry.getKey())) {
                    ProBasicRegion cp = CacheContext.rgmap.get(entry.getKey());
                    gf.setRegionId(cp.getId());

                    gf.setRecordDate(DateUtils.truncate(recordDate));
                    gf.setForeignKeyId(cp.getId() + "-2");
                    gf.setLocation(Location.rg.getValue());

                    fd.setRegionId(cp.getId());

                    fd.setRecordDate(DateUtils.truncate(recordDate));
                    fd.setForeignKeyId(cp.getId() + "-1");
                    fd.setLocation(Location.rg.getValue());

                    qb.setRegionId(cp.getId());

                    qb.setRecordDate(DateUtils.truncate(recordDate));
                    qb.setForeignKeyId(cp.getId() + "0");
                    qb.setLocation(Location.rg.getValue());


                    Initial.initial(qb);
                    Initial.initial(fd);
                    Initial.initial(gf);
                    //计算区域级全部
                    calCp(qb, qbls);
                    //计算公司级风电场站
                    calCp(fd, fdls);
                    //计算公司级光电场站
                    calCp(gf, gfls);

                    proEconPowerstationInfoDay1Service.save(qb);
                    proEconPowerstationInfoDay1Service.save(fd);
                    proEconPowerstationInfoDay1Service.save(gf);
                }


                //                }else
                //                {
                //                    logger.debug("公司所属场站数量与保存的场站日信息数量不一致，未进行{0}统计-------结束", entry.getKey());
                //
                //                }


            }
        }

    }

    /**
     * 计算公司日信息
     */
    public void calCompanyInfoDay(Date recordDate) {

        Calendar c = Calendar.getInstance();
        c.setTime(recordDate);
        if (c.get(Calendar.HOUR_OF_DAY) == 0 && c.get(Calendar.MINUTE) == 0) {
            c.add(Calendar.DAY_OF_MONTH, -1);
        }


        recordDate = DateUtils.truncate(c.getTime());
        QueryWrapper<ProEconPowerstationInfoDay1> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.wp.getValue());
        List<ProEconPowerstationInfoDay1> wpinfodayls = proEconPowerstationInfoDay1Service.list(queryWrapper);
        //                .stream()
        //                .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
        //                        && i.getLocation().equals(Location.wp.getValue()))
        //                .collect(Collectors.toList());
        if (!wpinfodayls.isEmpty()) {

            Map<String, Map<String, List<ProEconPowerstationInfoDay1>>> cpmap = new HashMap<>();


            for (ProEconPowerstationInfoDay1 wpinfo : wpinfodayls) {

                if (cpmap.containsKey(wpinfo.getCompanyId())) {
                    Map<String, List<ProEconPowerstationInfoDay1>> map = cpmap.get(wpinfo.getCompanyId());
                    List<ProEconPowerstationInfoDay1> qbls = map.get(CompanyType.qb.id);
                    List<ProEconPowerstationInfoDay1> fdls = map.get(CompanyType.fd.id);
                    List<ProEconPowerstationInfoDay1> gfls = map.get(CompanyType.gf.id);

                    if (wpinfo.getWindpowerstationId().contains(WpType.FDC.id)) {
                        fdls.add(wpinfo);
                    } else {
                        gfls.add(wpinfo);
                    }
                    qbls.add(wpinfo);
                } else {
                    Map<String, List<ProEconPowerstationInfoDay1>> map = new HashMap<>();

                    List<ProEconPowerstationInfoDay1> qbls = new ArrayList<>();
                    List<ProEconPowerstationInfoDay1> gfls = new ArrayList<>();
                    List<ProEconPowerstationInfoDay1> fdls = new ArrayList<>();

                    if (wpinfo.getWindpowerstationId().contains(WpType.FDC.id)) {
                        fdls.add(wpinfo);
                    } else {
                        gfls.add(wpinfo);
                    }
                    qbls.add(wpinfo);
                    map.put(CompanyType.qb.id, qbls);
                    map.put(CompanyType.fd.id, fdls);
                    map.put(CompanyType.gf.id, gfls);
                    cpmap.put(wpinfo.getCompanyId(), map);
                }
            }


            //判断是否有重复记录，先删除重复记录
            QueryWrapper<ProEconPowerstationInfoDay1> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.cp.getValue());
            List<String> idls = proEconPowerstationInfoDay1Service.list(queryWrapper2).stream()
                    //                    .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
                    //                            && i.getLocation().equals(Location.cp.getValue()))
                    .map(ProEconPowerstationInfoDay1::getId)
                    .collect(Collectors.toList());

            if (idls.size() > 0) {

                proEconPowerstationInfoDay1Service.removeByIds(idls);

            }
            for (Map.Entry<String, Map<String, List<ProEconPowerstationInfoDay1>>> entry : cpmap.entrySet()) {
                Map<String, List<ProEconPowerstationInfoDay1>> map = entry.getValue();
                List<ProEconPowerstationInfoDay1> qbls = map.get(CompanyType.qb.id);
                List<ProEconPowerstationInfoDay1> fdls = map.get(CompanyType.fd.id);
                List<ProEconPowerstationInfoDay1> gfls = map.get(CompanyType.gf.id);
                //                if(CacheContext.cpwpmap.size()==qbls.size())
                //                {

                ProEconPowerstationInfoDay1 qb = new ProEconPowerstationInfoDay1();
                ProEconPowerstationInfoDay1 fd = new ProEconPowerstationInfoDay1();
                ProEconPowerstationInfoDay1 gf = new ProEconPowerstationInfoDay1();

                if (CacheContext.cpmap.containsKey(entry.getKey())) {
                    ProBasicCompany cp = CacheContext.cpmap.get(entry.getKey());
                    gf.setRegionId(cp.getRegionId());
                    gf.setCompanyId(cp.getId());
                    gf.setRecordDate(DateUtils.truncate(recordDate));
                    gf.setForeignKeyId(cp.getId() + "-2");
                    gf.setLocation(Location.cp.getValue());


                    fd.setRegionId(cp.getRegionId());
                    fd.setCompanyId(cp.getId());
                    fd.setRecordDate(DateUtils.truncate(recordDate));
                    fd.setForeignKeyId(cp.getId() + "-1");
                    fd.setLocation(Location.cp.getValue());

                    qb.setRegionId(cp.getRegionId());
                    qb.setCompanyId(cp.getId());
                    qb.setRecordDate(DateUtils.truncate(recordDate));
                    qb.setForeignKeyId(cp.getId() + "0");
                    qb.setLocation(Location.cp.getValue());

                    Initial.initial(qb);
                    Initial.initial(fd);
                    Initial.initial(gf);

                    //计算公司级全部场站
                    calCp(qb, qbls);
                    //计算公司级风电场站
                    calCp(fd, fdls);
                    //计算公司级光电场站
                    calCp(gf, gfls);

                    proEconPowerstationInfoDay1Service.save(qb);
                    proEconPowerstationInfoDay1Service.save(fd);
                    proEconPowerstationInfoDay1Service.save(gf);
                }


                //                }else
                //                {
                //                    logger.debug("公司所属场站数量与保存的场站日信息数量不一致，未进行{0}统计-------结束", entry.getKey());
                //
                //                }


            }
        }

    }

    private void calCp(ProEconPowerstationInfoDay1 pewp, List<ProEconPowerstationInfoDay1> ls) {

        if (!ls.isEmpty()) {
            //            DoubleSummaryStatistics summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRzdfs).summaryStatistics();
            //            //日最大风速
            //            pewp.setRzdfs(summaryStatistics.getMax());
            //            //日最小风速
            //            summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRzxfs).summaryStatistics();
            //            pewp.setRzxfs(summaryStatistics.getMin());
            //            //日平均风速
            //            summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRpjfs).summaryStatistics();
            //            pewp.setRpjfs(summaryStatistics.getAverage());
            //
            //            summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRzdgl).summaryStatistics();
            //            //日最大功率
            //            pewp.setRzdgl(summaryStatistics.getMax());
            //            //日最小功率
            //            summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRzxgl).summaryStatistics();
            //            pewp.setRzxgl(summaryStatistics.getMin());
            //            //日平均功率
            //            summaryStatistics=ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRpjgl).summaryStatistics();
            //            pewp.setRpjgl(summaryStatistics.getAverage());


            //日发电量
            DoubleSummaryStatistics summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRfdl).summaryStatistics();
            pewp.setRfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日可用电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRkydl).summaryStatistics();
            pewp.setRkydl(StringUtils.round(summaryStatistics.getSum(), 2));


            //日理论发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRllfdl).summaryStatistics();
            pewp.setRllfdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //日故障损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRgzssdl).summaryStatistics();
            pewp.setRgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //日场内受累故障损失电量
            pewp.setRcnslgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日检修损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRjxssdl).summaryStatistics();
            pewp.setRjxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日场内受累检修损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRcnsljxssdl).summaryStatistics();
            pewp.setRcnsljxssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //日待机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRdjssdl).summaryStatistics();
            pewp.setRdjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日缺陷降出力损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRqxjclssdl).summaryStatistics();
            pewp.setRqxjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日手动停机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRsdtjssdl).summaryStatistics();
            pewp.setRsdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日性能损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRxnssdl).summaryStatistics();
            pewp.setRxnssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日限电停机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRxdtjssdl).summaryStatistics();
            pewp.setRxdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日限电降出力损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRxdjclssdl).summaryStatistics();
            pewp.setRxdjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //日场外受累电网损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRcwsldwssdl).summaryStatistics();
            pewp.setRcwsldwssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //日场外受累天气损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRcwsltqssdl).summaryStatistics();
            pewp.setRcwsltqssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日增发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRzfdl).summaryStatistics();
            pewp.setRzfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日欠发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRqfdl).summaryStatistics();
            pewp.setRqfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //日自耗电
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getRzhd).summaryStatistics();
            pewp.setRzhd(StringUtils.round(summaryStatistics.getSum(), 2));

            //月发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYfdl).summaryStatistics();
            pewp.setYfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月可用电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYkydl).summaryStatistics();
            pewp.setYkydl(StringUtils.round(summaryStatistics.getSum(), 2));


            //月理论发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYllfdl).summaryStatistics();
            pewp.setYllfdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //月故障损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYgzssdl).summaryStatistics();
            pewp.setYgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //月场内受累故障损失电量
            pewp.setYcnslgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月检修损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYjxssdl).summaryStatistics();
            pewp.setYjxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月场内受累检修损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYcnsljxssdl).summaryStatistics();
            pewp.setYcnsljxssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //月待机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYdjssdl).summaryStatistics();
            pewp.setYdjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月缺陷降出力损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYqxjclssdl).summaryStatistics();
            pewp.setYqxjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月手动停机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYsdtjssdl).summaryStatistics();
            pewp.setYsdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月性能损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYxnssdl).summaryStatistics();
            pewp.setYxnssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月限电停机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYxdtjssdl).summaryStatistics();
            pewp.setYxdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月限电降出力损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYxdjclssdl).summaryStatistics();
            pewp.setYxdjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //月场外受累电网损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYcwsldwssdl).summaryStatistics();
            pewp.setYcwsldwssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //月场外受累天气损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYcwsltqssdl).summaryStatistics();
            pewp.setYcwsltqssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月增发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYzfdl).summaryStatistics();
            pewp.setYzfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月欠发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYqfdl).summaryStatistics();
            pewp.setYqfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //月自耗电
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getYzhd).summaryStatistics();
            pewp.setYzhd(StringUtils.round(summaryStatistics.getSum(), 2));

            //年发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNfdl).summaryStatistics();
            pewp.setNfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年可用电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNkydl).summaryStatistics();
            pewp.setNkydl(StringUtils.round(summaryStatistics.getSum(), 2));


            //年理论发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNllfdl).summaryStatistics();
            pewp.setNllfdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //年故障损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNgzssdl).summaryStatistics();
            pewp.setNgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //年场内受累故障损失电量
            pewp.setNcnslgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年检修损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNjxssdl).summaryStatistics();
            pewp.setNjxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年场内受累检修损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNcnsljxssdl).summaryStatistics();
            pewp.setNcnsljxssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //年待机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNdjssdl).summaryStatistics();
            pewp.setNdjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年缺陷降出力损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNqxjclssdl).summaryStatistics();
            pewp.setNqxjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年手动停机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNsdtjssdl).summaryStatistics();
            pewp.setNsdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年性能损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNxnssdl).summaryStatistics();
            pewp.setNxnssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年限电停机损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNxdtjssdl).summaryStatistics();
            pewp.setNxdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年限电降出力损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNxdjclssdl).summaryStatistics();
            pewp.setNxdjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //年场外受累电网损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNcwsldwssdl).summaryStatistics();
            pewp.setNcwsldwssdl(StringUtils.round(summaryStatistics.getSum(), 2));


            //年场外受累天气损失电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNcwsltqssdl).summaryStatistics();
            pewp.setNcwsltqssdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年增发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNzfdl).summaryStatistics();
            pewp.setNzfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年欠发电量
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNqfdl).summaryStatistics();
            pewp.setNqfdl(StringUtils.round(summaryStatistics.getSum(), 2));

            //年自耗电
            summaryStatistics = ls.stream().mapToDouble(ProEconPowerstationInfoDay1::getNzhd).summaryStatistics();
            pewp.setNzhd(StringUtils.round(summaryStatistics.getSum(), 2));

        }
    }

    /**
     * 计算场站日信息
     */
    public void calWindpowerInfoDay(Date recordDate) throws Exception {
        Calendar c = Calendar.getInstance();
        c.setTime(recordDate);
        if (c.get(Calendar.HOUR_OF_DAY) == 0 && c.get(Calendar.MINUTE) == 0) {
            c.add(Calendar.DAY_OF_MONTH, -1);
        }


        recordDate = DateUtils.truncate(c.getTime());


        Map<String, List<ProEconEquipmentInfoDay1>> pep1map = new HashMap<>();
        QueryWrapper<ProEconEquipmentInfoDay1> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("record_date", DateUtils.truncate(recordDate));
        List<ProEconEquipmentInfoDay1> pep1ls = proEconEquipmentInfoDay1Service.list(queryWrapper2);
        if (!pep1ls.isEmpty()) {
            for (ProEconEquipmentInfoDay1 pep : pep1ls) {
                if (pep1map.containsKey(pep.getWindpowerstationId())) {
                    List<ProEconEquipmentInfoDay1> pepls = pep1map.get(pep.getWindpowerstationId());
                    pepls.add(pep);
                } else {
                    List<ProEconEquipmentInfoDay1> pepls = new ArrayList<>();
                    pepls.add(pep);
                    pep1map.put(pep.getWindpowerstationId(), pepls);
                }

            }
        }
        List<String> wpls = new ArrayList<>();
        List<ProEconPowerstationInfoDay1> dayls = new ArrayList<>();
        for (ProBasicPowerstation wp : CacheContext.wpls) {
            if (CacheContext.wppointmap.containsKey(wp.getId())) {
                Map<String, ProBasicPowerstationPoint> pointmap = CacheContext.wppointmap.get(wp.getId());

                ProEconPowerstationInfoDay1 pewp = new ProEconPowerstationInfoDay1();
                Initial.initial(pewp);
                pewp.setRegionId(wp.getRegionId());
                pewp.setCompanyId(wp.getCompanyId());
                pewp.setRecordDate(DateUtils.truncate(recordDate));
                pewp.setForeignKeyId(wp.getId());
                pewp.setWindpowerstationId(wp.getId());
                pewp.setLocation(Location.wp.getValue());

                String type = null;
                if (wp.getId().contains("FDC")) {
                    type = "FDC";
                } else {
                    type = "GDC";
                }
                extracted(wp.getId(), type, pewp, pep1map);
                //*******************************************年信息统计*********************************************************/

                dayls.add(pewp);
                // proEconPowerstationInfoDay1Service.save(pewp);

                wpls.add(wp.getId());
            }


        }


        //判断是否有重复记录，先删除重复记录
        QueryWrapper<ProEconPowerstationInfoDay1> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate))
                .in("windpowerstation_id", wpls)
                .eq("location", Location.wp.getValue());
        List<String> idls = proEconPowerstationInfoDay1Service.list(queryWrapper).stream()
                //                .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
                //                        && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
                //                        && i.getLocation().equals(Location.wp.getValue()))
                .map(ProEconPowerstationInfoDay1::getId)
                .collect(Collectors.toList());

        if (idls.size() > 0) {

            proEconPowerstationInfoDay1Service.removeByIds(idls);

        }
        List<ProEconPowerstationInfoDay1> templs = new ArrayList<>();
        for (ProEconPowerstationInfoDay1 vo : dayls) {
            templs.add(vo);
            if (templs.size() == 1000) {
                proEconPowerstationInfoDay1Service.saveBatch(templs);
                templs = new ArrayList<>();
            }
        }

        if (!templs.isEmpty()) {
            proEconPowerstationInfoDay1Service.saveBatch(templs);
        }
        //        proEconPowerstationInfoDay1Service.saveBatch(dayls);
    }

    /**
     * 计算项目日信息
     */
    public void calProjectInfoDay(Date recordDate) throws Exception {
        Calendar c = Calendar.getInstance();
        c.setTime(recordDate);
        if (c.get(Calendar.HOUR_OF_DAY) == 0 && c.get(Calendar.MINUTE) == 0) {
            c.add(Calendar.DAY_OF_MONTH, -1);
        }


        recordDate = DateUtils.truncate(c.getTime());


        Map<String, List<ProEconEquipmentInfoDay1>> pep1map = new HashMap<>();
        QueryWrapper<ProEconEquipmentInfoDay1> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("record_date", DateUtils.truncate(recordDate));
        List<ProEconEquipmentInfoDay1> pep1ls = proEconEquipmentInfoDay1Service.list(queryWrapper2);
        if (!pep1ls.isEmpty()) {
            for (ProEconEquipmentInfoDay1 pep : pep1ls) {
                if (pep1map.containsKey(pep.getProjectId())) {
                    List<ProEconEquipmentInfoDay1> pepls = pep1map.get(pep.getProjectId());
                    pepls.add(pep);
                } else {
                    List<ProEconEquipmentInfoDay1> pepls = new ArrayList<>();
                    pepls.add(pep);
                    pep1map.put(pep.getProjectId(), pepls);
                }

            }
        }

        List<String> pjls = new ArrayList<>();
        List<ProEconPowerstationInfoDay1> dayls = new ArrayList<>();
        for (ProBasicProject pj : CacheContext.pjls) {
            if (CacheContext.propointmap.containsKey(pj.getId())) {
                Map<String, ProBasicPowerstationPoint> pointmap = CacheContext.propointmap.get(pj.getId());

                String type = null;
                ProEconPowerstationInfoDay1 pewp = new ProEconPowerstationInfoDay1();
                Initial.initial(pewp);
                if (CacheContext.wpmap.containsKey(pj.getWindpowerstationId())) {
                    ProBasicPowerstation wp = CacheContext.wpmap.get(pj.getWindpowerstationId());
                    pewp.setRegionId(wp.getRegionId());
                    pewp.setCompanyId(wp.getCompanyId());
                    if (wp.getId().contains("FDC")) {
                        type = "FDC";
                    } else {
                        type = "GDC";
                    }
                }
                pewp.setForeignKeyId(pj.getId());

                pewp.setWindpowerstationId(pj.getWindpowerstationId());
                pewp.setProjectId(pj.getId());
                pewp.setLocation(Location.pj.getValue());
                pewp.setRecordDate(DateUtils.truncate(recordDate));


                extracted(pj.getId(), type, pewp, pep1map);

                dayls.add(pewp);
                // proEconPowerstationInfoDay1Service.save(pewp);
                pjls.add(pj.getWindpowerstationId());
            }


        }


        //判断是否有重复记录，先删除重复记录
        QueryWrapper<ProEconPowerstationInfoDay1> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate))
                .in("windpowerstation_id", pjls)
                .eq("location", Location.pj.getValue());
        List<String> idls = proEconPowerstationInfoDay1Service.list(queryWrapper).stream()
                //                .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
                //                        && CacheContext.pjmap.containsKey(i.getProjectId())
                //                        && i.getLocation().equals(Location.pj.getValue()))
                .map(ProEconPowerstationInfoDay1::getId)
                .collect(Collectors.toList());

        if (idls.size() > 0) {

            proEconPowerstationInfoDay1Service.removeByIds(idls);

        }
        List<ProEconPowerstationInfoDay1> templs = new ArrayList<>();
        for (ProEconPowerstationInfoDay1 vo : dayls) {
            templs.add(vo);
            if (templs.size() == 1000) {
                proEconPowerstationInfoDay1Service.saveBatch(templs);
                templs = new ArrayList<>();
            }
        }

        if (!templs.isEmpty()) {
            proEconPowerstationInfoDay1Service.saveBatch(templs);
        }
        //        proEconPowerstationInfoDay1Service.saveBatch(dayls);
    }

    /**
     * 计算线路日信息
     */
    public void calLineInfoDay(Date recordDate) throws Exception {
        Calendar c = Calendar.getInstance();
        c.setTime(recordDate);
        if (c.get(Calendar.HOUR_OF_DAY) == 0 && c.get(Calendar.MINUTE) == 0) {
            c.add(Calendar.DAY_OF_MONTH, -1);
        }


        recordDate = DateUtils.truncate(c.getTime());


        Map<String, List<ProEconEquipmentInfoDay1>> pep1map = new HashMap<>();
        QueryWrapper<ProEconEquipmentInfoDay1> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("record_date", DateUtils.truncate(recordDate));
        List<ProEconEquipmentInfoDay1> pep1ls = proEconEquipmentInfoDay1Service.list(queryWrapper2);
        if (!pep1ls.isEmpty()) {
            for (ProEconEquipmentInfoDay1 pep : pep1ls) {
                if (pep1map.containsKey(pep.getLineId())) {
                    List<ProEconEquipmentInfoDay1> pepls = pep1map.get(pep.getLineId());
                    pepls.add(pep);
                } else {
                    List<ProEconEquipmentInfoDay1> pepls = new ArrayList<>();
                    pepls.add(pep);
                    pep1map.put(pep.getLineId(), pepls);
                }

            }
        }

        List<String> lnls = new ArrayList<>();
        List<ProEconPowerstationInfoDay1> dayls = new ArrayList<>();
        for (ProBasicLine ln : CacheContext.lnls) {
            if (CacheContext.linepointmap.containsKey(ln.getId())) {
                Map<String, ProBasicPowerstationPoint> pointmap = CacheContext.linepointmap.get(ln.getId());

                String type = null;
                ProEconPowerstationInfoDay1 pewp = new ProEconPowerstationInfoDay1();
                if (CacheContext.pjmap.containsKey(ln.getProjectId())) {
                    ProBasicProject pj = CacheContext.pjmap.get(ln.getProjectId());
                    if (CacheContext.wpmap.containsKey(pj.getWindpowerstationId())) {
                        ProBasicPowerstation wp = CacheContext.wpmap.get(pj.getWindpowerstationId());
                        pewp.setRegionId(wp.getRegionId());
                        pewp.setCompanyId(wp.getCompanyId());
                        pewp.setWindpowerstationId(wp.getId());
                        if (wp.getId().contains("FDC")) {
                            type = "FDC";
                        } else {
                            type = "GDC";
                        }
                    }

                }
                Initial.initial(pewp);
                pewp.setForeignKeyId(ln.getId());
                pewp.setLineId(ln.getId());
                pewp.setLocation(Location.ln.getValue());
                pewp.setProjectId(ln.getProjectId());
                pewp.setRecordDate(DateUtils.truncate(recordDate));


                extracted(ln.getId(), type, pewp, pep1map);

                dayls.add(pewp);
                //                proEconPowerstationInfoDay1Service.save(pewp);
                if (CacheContext.pjmap.containsKey(ln.getProjectId())) {
                    lnls.add(CacheContext.pjmap.get(ln.getProjectId()).getWindpowerstationId());
                }

            }


        }


        //判断是否有重复记录，先删除重复记录
        QueryWrapper<ProEconPowerstationInfoDay1> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate))
                .in("windpowerstation_id", lnls)
                .eq("location", Location.ln.getValue());
        List<String> idls = proEconPowerstationInfoDay1Service.list(queryWrapper).stream()
                //                .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
                //                        && CacheContext.lnmap.containsKey(i.getLineId())
                //                        && i.getLocation().equals(Location.ln.getValue()))
                .map(ProEconPowerstationInfoDay1::getId)
                .collect(Collectors.toList());

        if (idls.size() > 0) {

            proEconPowerstationInfoDay1Service.removeByIds(idls);

        }

        List<ProEconPowerstationInfoDay1> templs = new ArrayList<>();
        for (ProEconPowerstationInfoDay1 vo : dayls) {
            templs.add(vo);
            if (templs.size() == 1000) {
                proEconPowerstationInfoDay1Service.saveBatch(templs);
                templs = new ArrayList<>();
            }
        }

        if (!templs.isEmpty()) {
            proEconPowerstationInfoDay1Service.saveBatch(templs);
        }
        //        proEconPowerstationInfoDay1Service.saveBatch(dayls);
    }

    private void extracted(String id, String type, ProEconPowerstationInfoDay1 pewp, Map<String, List<ProEconEquipmentInfoDay1>> pep1map) throws Exception {


        //*******************************************日信息统计*********************************************************/

        if (pep1map.containsKey(id) && type != null) {
            List<ProEconEquipmentInfoDay1> pep1ls = pep1map.get(id);

            if (!pep1ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRzdfs).summaryStatistics();
                //日最大风速
                pewp.setRzdfs(summaryStatistics.getMax());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRzxfs).summaryStatistics();
                //日最小风速
                pewp.setRzxfs(summaryStatistics.getMin());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRpjfs).summaryStatistics();
                //日平均风速
                if (type.equals("FDC")) {
                    pewp.setRpjfs(summaryStatistics.getAverage());
                } else {
                    pewp.setRpjfs(pep1ls.get(0).getRpjfs());
                }


                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRzdgl).summaryStatistics();
                //日最大功率
                pewp.setRzdgl(summaryStatistics.getMax());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRzxgl).summaryStatistics();
                //日最小功率
                pewp.setRzxgl(summaryStatistics.getMin());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRpjgl).summaryStatistics();
                //日平均功率
                pewp.setRpjgl(summaryStatistics.getAverage());

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRfdl).summaryStatistics();
                //日发电量
                pewp.setRfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRkydl).summaryStatistics();
                //日可用电量
                pewp.setRkydl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRllfdl).summaryStatistics();
                //日理论发电量
                pewp.setRllfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRgzssdl).summaryStatistics();
                //日故障损失电量
                pewp.setRgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRcnslgzssdl).summaryStatistics();
                //日场内受累故障损失电量
                pewp.setRcnslgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRjxssdl).summaryStatistics();
                //日检修损失电量
                pewp.setRjxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRcnsljxssdl).summaryStatistics();
                //日场内受累检修损失电量
                pewp.setRcnsljxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRdjssdl).summaryStatistics();
                //日待机损失电量
                pewp.setRdjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRqxjclssdl).summaryStatistics();
                //日缺陷降出力损失电量
                pewp.setRqxjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRsdtjssdl).summaryStatistics();
                //日手动停机损失电量
                pewp.setRsdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRxnssdl).summaryStatistics();
                //日性能损失电量
                pewp.setRxnssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRxdtjssdl).summaryStatistics();
                //日限电停机损失电量
                pewp.setRxdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRxdjclssdl).summaryStatistics();
                //日限电降出力损失电量
                pewp.setRxdjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRcwsldwssdl).summaryStatistics();
                //日场外受累电网损失电量
                pewp.setRcwsldwssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRcwsltqssdl).summaryStatistics();
                //日场外受累天气损失电量
                pewp.setRcwsltqssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRzfdl).summaryStatistics();
                //日增发电量
                pewp.setRzfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRqfdl).summaryStatistics();
                //日欠发电量
                pewp.setRqfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getRzhd).summaryStatistics();
                //日自耗电
                pewp.setRzhd(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }


        //*******************************************日信息统计*********************************************************/

        //*******************************************月信息统计*********************************************************/

        if (pep1map.containsKey(id)) {
            List<ProEconEquipmentInfoDay1> pep1ls = pep1map.get(id);

            if (!pep1ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYzdfs).summaryStatistics();
                //月最大风速
                pewp.setYzdfs(summaryStatistics.getMax());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYzxfs).summaryStatistics();
                //月最小风速
                pewp.setYzxfs(summaryStatistics.getMin());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYpjfs).summaryStatistics();

                //日平均风速
                if (type.equals("FDC")) {
                    //月平均风速
                    pewp.setYpjfs(summaryStatistics.getAverage());
                } else {
                    //月平均风速
                    pewp.setYpjfs(pep1ls.get(0).getYpjfs());

                }
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYzdgl).summaryStatistics();
                //月最大功率
                pewp.setYzdgl(summaryStatistics.getMax());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYzxgl).summaryStatistics();
                //月最小功率
                pewp.setYzxgl(summaryStatistics.getMin());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYpjgl).summaryStatistics();
                //月平均功率
                pewp.setYpjgl(summaryStatistics.getAverage());

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYfdl).summaryStatistics();
                //月发电量
                pewp.setYfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYkydl).summaryStatistics();
                //月可用电量
                pewp.setYkydl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYllfdl).summaryStatistics();
                //月理论发电量
                pewp.setYllfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYgzssdl).summaryStatistics();
                //月故障损失电量
                pewp.setYgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYcnslgzssdl).summaryStatistics();
                //月场内受累故障损失电量
                pewp.setYcnslgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYjxssdl).summaryStatistics();
                //月检修损失电量
                pewp.setYjxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYcnsljxssdl).summaryStatistics();
                //月场内受累检修损失电量
                pewp.setYcnsljxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYdjssdl).summaryStatistics();
                //月待机损失电量
                pewp.setYdjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYqxjclssdl).summaryStatistics();
                //月缺陷降出力损失电量
                pewp.setYqxjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYsdtjssdl).summaryStatistics();
                //月手动停机损失电量
                pewp.setYsdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYxnssdl).summaryStatistics();
                //月性能损失电量
                pewp.setYxnssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYxdtjssdl).summaryStatistics();
                //月限电停机损失电量
                pewp.setYxdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYxdjclssdl).summaryStatistics();
                //月限电降出力损失电量
                pewp.setYxdjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYcwsldwssdl).summaryStatistics();
                //月场外受累电网损失电量
                pewp.setYcwsldwssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYcwsltqssdl).summaryStatistics();
                //月场外受累天气损失电量
                pewp.setYcwsltqssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYzfdl).summaryStatistics();
                //月增发电量
                pewp.setYzfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYqfdl).summaryStatistics();
                //月欠发电量
                pewp.setYqfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getYzhd).summaryStatistics();
                //月自耗电
                pewp.setYzhd(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }

        ///*******************************************月信息统计*********************************************************/

        //*******************************************年信息统计*********************************************************/
        if (pep1map.containsKey(id)) {
            List<ProEconEquipmentInfoDay1> pep1ls = pep1map.get(id);

            if (!pep1ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNzdfs).summaryStatistics();
                //年最大风速
                pewp.setNzdfs(summaryStatistics.getMax());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNzxfs).summaryStatistics();
                //年最小风速
                pewp.setNzxfs(summaryStatistics.getMin());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNpjfs).summaryStatistics();


                if (type.equals("FDC")) {
                    //年平均风速
                    pewp.setNpjfs(summaryStatistics.getAverage());
                } else {
                    //年平均风速
                    pewp.setNpjfs(pep1ls.get(0).getNpjfs());
                    //                    pewp.setNpjfs(summaryStatistics.getSum());
                }
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNzdgl).summaryStatistics();
                //年最大功率
                pewp.setNzdgl(summaryStatistics.getMax());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNzxgl).summaryStatistics();
                //年最小功率
                pewp.setNzxgl(summaryStatistics.getMin());
                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNpjgl).summaryStatistics();
                //年平均功率
                pewp.setNpjgl(summaryStatistics.getAverage());

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNfdl).summaryStatistics();
                //年发电量
                pewp.setNfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNkydl).summaryStatistics();
                //年可用电量
                pewp.setNkydl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNllfdl).summaryStatistics();
                //年理论发电量
                pewp.setNllfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNgzssdl).summaryStatistics();
                //年故障损失电量
                pewp.setNgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNcnslgzssdl).summaryStatistics();
                //年场内受累故障损失电量
                pewp.setNcnslgzssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNjxssdl).summaryStatistics();
                //年检修损失电量
                pewp.setNjxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNcnsljxssdl).summaryStatistics();
                //年场内受累检修损失电量
                pewp.setNcnsljxssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNdjssdl).summaryStatistics();
                //年待机损失电量
                pewp.setNdjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNqxjclssdl).summaryStatistics();
                //年缺陷降出力损失电量
                pewp.setNqxjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNsdtjssdl).summaryStatistics();
                //年手动停机损失电量
                pewp.setNsdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNxnssdl).summaryStatistics();
                //年性能损失电量
                pewp.setNxnssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNxdtjssdl).summaryStatistics();
                //年限电停机损失电量
                pewp.setNxdtjssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNxdjclssdl).summaryStatistics();
                //年限电降出力损失电量
                pewp.setNxdjclssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNcwsldwssdl).summaryStatistics();
                //年场外受累电网损失电量
                pewp.setNcwsldwssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNcwsltqssdl).summaryStatistics();
                //年场外受累天气损失电量
                pewp.setNcwsltqssdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNzfdl).summaryStatistics();
                //年增发电量
                pewp.setNzfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNqfdl).summaryStatistics();
                //年欠发电量
                pewp.setNqfdl(StringUtils.round(summaryStatistics.getSum(), 2));

                summaryStatistics = pep1ls.stream().mapToDouble(ProEconEquipmentInfoDay1::getNzhd).summaryStatistics();
                //年自耗电
                pewp.setNzhd(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }
    }

    private void setPowerandSpeedYear(ProEconPowerstationInfoDay1 pewp) {
        //年最大风速
        pewp.setNzdfs(pewp.getRzdfs());
        //年最小风速
        pewp.setNzxfs(pewp.getRzxfs());
        //年平均风速
        pewp.setNpjfs(pewp.getRpjfs());
        //年最大功率
        pewp.setNzdgl(pewp.getRzdgl());
        //年最小功率
        pewp.setNzxgl(pewp.getRzxgl());
        //年平均功率
        pewp.setNpjgl(pewp.getRpjgl());

    }

    private void setPowerandSpeedMonth(ProEconPowerstationInfoDay1 pewp) {

        //月最大风速
        pewp.setYzdfs(pewp.getRzdfs());
        //月最小风速
        pewp.setYzxfs(pewp.getRzxfs());
        //月平均风速
        pewp.setYpjfs(pewp.getRpjfs());
        //月最大功率
        pewp.setYzdgl(pewp.getRzdgl());
        //月最小功率
        pewp.setYzxgl(pewp.getRzxgl());
        //月平均功率
        pewp.setYpjgl(pewp.getRpjgl());
    }


    public void writeGf(Date date) throws Exception {
        QueryWrapper<ProBaseBackfill> qwf = new QueryWrapper<>();
        qwf.lambda().eq(ProBaseBackfill::getType, "CUSTOM_NDGFZB");
        List<ProBaseBackfill> list = iProBaseBackfillService.list(qwf);
        List<String> str = list.stream().map(ProBaseBackfill::getCode).collect(Collectors.toList());
        List<PointData> realData = edosUtil.getRealData(str);
        QueryWrapper<ProEconAnalysisSubtableBottom> qw = new QueryWrapper<>();
        qw.lambda().eq(ProEconAnalysisSubtableBottom::getRecordDate, date);
        List<ProEconAnalysisSubtableBottom> sel = iProEconAnalysisSubtableBottomService.sel(qw);
        List<ProEconAnalysisSubtableBottom> collect = sel.stream().filter(peasb -> str.contains(peasb.getMeterId())).collect(Collectors.toList());
        List<ProEconAnalysisSubtableBottom> ls = new ArrayList<>();
        if (collect.isEmpty()) {
            for (PointData real : realData) {
                ProEconAnalysisSubtableBottom pb = new ProEconAnalysisSubtableBottom();
                pb.setRecordDate(date);
                String[] split1 = real.getPointName().split("\\.");
                if ("曙光储能电站".equals(split1[2]) || "宁东33光伏场站".equals(split1[2])) {
                    pb.setWpid("GJNY_NXGS_SGB_GDC_STA");
                } else if ("霞光储能电站".equals(split1[2]) || "宁东32光伏场站".equals(split1[2])) {
                    pb.setWpid("GJNY_NXGS_XGB_GDC_STA");
                } else {
                    pb.setWpid("GJNY_NXGS_QZB_GDC_STA");
                }
                pb.setMeterId(real.getPointName());
                pb.setMeterName(real.getPointName());
                pb.setStopCode(real.getPointValueInDouble());
                pb.setStopCodeModify(real.getPointValueInDouble());
                ls.add(pb);
            }
        } else {
            for (PointData real : realData) {
                for (ProEconAnalysisSubtableBottom s : sel) {
                    if (real.getPointName().equals(s.getMeterId())) {
                        ProEconAnalysisSubtableBottom pb = new ProEconAnalysisSubtableBottom();
                        pb.setId(s.getId());
                        pb.setStopCode(real.getPointValueInDouble());
                        pb.setStopCodeModify(real.getPointValueInDouble());
                        pb.setRecordDate(new Date(real.getPointTime()));
                        pb.setMeterName(real.getPointName());
                        pb.setMeterId(real.getPointName());
                        ls.add(pb);
                    }
                }
            }
        }
        try {
            boolean b = iProEconAnalysisSubtableBottomService.batchAdd(ls);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void writeGfHistory(Date date) throws Exception {
        QueryWrapper<ProBaseBackfill> qwf = new QueryWrapper<>();
        qwf.lambda().eq(ProBaseBackfill::getType, "CUSTOM_NDGFZB");
        List<ProBaseBackfill> list = iProBaseBackfillService.list(qwf);
        List<String> str = list.stream().map(ProBaseBackfill::getCode).collect(Collectors.toList());
        List<ProEconAnalysisSubtableBottom> ls = new ArrayList<>();
        String join = String.join(",", str);
        Map<String, PointData2> historySection = adapter.getHistorySection(goldenUri(), join, date.getTime());
        for (String s : str) {
            ProEconAnalysisSubtableBottom pb = new ProEconAnalysisSubtableBottom();
            pb.setRecordDate(date);
            String[] split1 = s.split("\\.");
            if ("曙光储能电站".equals(split1[2]) || "宁东33光伏场站".equals(split1[2])) {
                pb.setWpid("GJNY_NXGS_SGB_GDC_STA");
            } else if ("霞光储能电站".equals(split1[2]) || "宁东32光伏场站".equals(split1[2])) {
                pb.setWpid("GJNY_NXGS_XGB_GDC_STA");
            } else {
                pb.setWpid("GJNY_NXGS_QZB_GDC_STA");
            }
            pb.setMeterId(s);
            pb.setMeterName(s);
            pb.setStopCode(historySection.get(s).getDoubleValue());
            pb.setStopCodeModify(historySection.get(s).getDoubleValue());
            ls.add(pb);
        }
        try {
            boolean b = iProEconAnalysisSubtableBottomService.batchAdd(ls);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public void writeHaWindturbine(Date date) throws Exception {
        QueryWrapper<ProBaseBackfill> qwf = new QueryWrapper<>();
        qwf.lambda().eq(ProBaseBackfill::getType, "AI0003");
        List<ProBaseBackfill> list = iProBaseBackfillService.list(qwf);
        List<String> str = list.stream().map(ProBaseBackfill::getCode).collect(Collectors.toList());
        List<PointData> realData = edosUtil.getRealData(str);
        QueryWrapper<ProEconAnalysisSubtableBottom> qw = new QueryWrapper<>();
        qw.lambda().eq(ProEconAnalysisSubtableBottom::getRecordDate, date);
        List<ProEconAnalysisSubtableBottom> sel = iProEconAnalysisSubtableBottomService.sel(qw);
        List<ProEconAnalysisSubtableBottom> collect = sel.stream().filter(peasb -> str.contains(peasb.getMeterId())).collect(Collectors.toList());
        List<ProEconAnalysisSubtableBottom> ls = new ArrayList<>();
        if (collect.isEmpty()) {
            for (PointData real : realData) {
                ProEconAnalysisSubtableBottom pb = new ProEconAnalysisSubtableBottom();
                pb.setRecordDate(date);
                pb.setWpid("NX_FGS_HA_FDC_STA");
                pb.setMeterId(real.getPointName());
                pb.setMeterName(real.getPointName());
                pb.setStopCode(real.getPointValueInDouble());
                pb.setStopCodeModify(real.getPointValueInDouble());
                ls.add(pb);
            }
        } else {
            for (PointData real : realData) {
                for (ProEconAnalysisSubtableBottom s : sel) {
                    if (real.getPointName().equals(s.getMeterId())) {
                        ProEconAnalysisSubtableBottom pb = new ProEconAnalysisSubtableBottom();
                        pb.setId(s.getId());
                        pb.setStopCode(real.getPointValueInDouble());
                        pb.setStopCodeModify(real.getPointValueInDouble());
                        pb.setRecordDate(date);
                        pb.setMeterName(real.getPointName());
                        pb.setMeterId(real.getPointName());
                        ls.add(pb);
                    }
                }
            }
        }
        try {
            boolean b = iProEconAnalysisSubtableBottomService.batchAdd(ls);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public void writeHaWindturbineHistory(Date date) throws Exception {
        QueryWrapper<ProBaseBackfill> qwf = new QueryWrapper<>();
        qwf.lambda().eq(ProBaseBackfill::getType, "AI0003");
        List<ProBaseBackfill> list = iProBaseBackfillService.list(qwf);
        List<String> str = list.stream().map(ProBaseBackfill::getCode).collect(Collectors.toList());
        long time = date.getTime();

        for (long i = time; i < 1742518800000L; i += 86400000) {
            List<ProEconAnalysisSubtableBottom> ls = new ArrayList<>();
            for (String s : str) {
                Map<String, PointData2> historySection = adapter.getHistorySection(goldenUri(), s, i);
                ProEconAnalysisSubtableBottom pb = new ProEconAnalysisSubtableBottom();
                pb.setRecordDate(new Date(i));
                pb.setWpid("NX_FGS_HA_FDC_STA");
                pb.setMeterId(s);
                pb.setMeterName(s);
                pb.setStopCode(historySection.get(s).getDoubleValue());
                pb.setStopCodeModify(historySection.get(s).getDoubleValue());
                ls.add(pb);
            }
            try {
                boolean b = iProEconAnalysisSubtableBottomService.batchAdd(ls);
            } catch (Exception e) {
                e.printStackTrace();
            }
           
        }
    }


//    public void writeGfHistory(Date date) throws Exception {
//        String s2 = "2024-12-11 23:55:00";
//        String[] split = gf.split(",");
//        List<String> str = new ArrayList<>(Arrays.asList(split));
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date date1 = simpleDateFormat.parse(s2);
//        long time = date1.getTime();
//        for (long i = time; i < 1735106823000L; i += 86400000) {
//            List<ProEconAnalysisSubtableBottom> ls = new ArrayList<>();
//            for (String s : str) {
//                Map<String, PointData2> historySection = adapter.getHistorySection(goldenUri(), s, i);
//                ProEconAnalysisSubtableBottom pb = new ProEconAnalysisSubtableBottom();
//                pb.setRecordDate(new Date(i));
//                String[] split1 = s.split("\\.");
//                if ("曙光储能电站".equals(split1[2]) || "宁东33光伏场站".equals(split1[2])) {
//                    pb.setWpid("GJNY_NXGS_SGB_GDC_STA");
//                } else if ("霞光储能电站".equals(split1[2]) || "宁东32光伏场站".equals(split1[2])) {
//                    pb.setWpid("GJNY_NXGS_XGB_GDC_STA");
//                } else if ("电度表".equals(split1[3])) {
//                    pb.setWpid("NX_FGS_HA_FDC_STA");
//                } else if ("区域集控".equals(split1[0]) && "惠安风场".equals(split1[1])) {
//                    pb.setWpid("NX_FGS_HA_FDC_STA");
//                } else {
//                    pb.setWpid("GJNY_NXGS_QZB_GDC_STA");
//                }
//                pb.setMeterId(s);
//                pb.setMeterName(s);
//                pb.setStopCode(historySection.get(s).getDoubleValue());
//                pb.setStopCodeModify(historySection.get(s).getDoubleValue());
//                ls.add(pb);
//            }
//            try {
//                boolean b = iProEconAnalysisSubtableBottomService.batchAdd(ls);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }
//    }


    /**
     * 执行时间：00:00:00,04:00:00,08:00:00,12:00:00,16:00:00,20:00:00,
     */
    public void writeReport1(Date date) throws Exception {
        QueryWrapper<ProBaseBackfill> qwf = new QueryWrapper<>();
        qwf.lambda().eq(ProBaseBackfill::getType, "AI0005");
        List<ProBaseBackfill> list = iProBaseBackfillService.list(qwf);
        List<String> ls = list.stream().map(ProBaseBackfill::getCode).collect(Collectors.toList());
        LocalDateTime currentTime = LocalDateTime.now();
        LocalDateTime modifiedTime = currentTime
                .withMinute(0)
                .withSecond(0)
                .withNano(0);
        List<PointData> realData = edosUtil.getRealData(ls);
        if (null == realData || realData.isEmpty()) {
            return;
        }
        List<StationInfoHour> shs = new ArrayList<>();
        for (PointData realDa : realData) {
            StationInfoHour sh = new StationInfoHour();
            sh.setRecordDate(modifiedTime);
            sh.setWpid("NX_FGS_HA_FDC_STA");
            sh.setMeterId(realDa.getPointName());
            sh.setMeterName(realDa.getPointName());
            sh.setCode(BigDecimal.valueOf(realDa.getPointValueInDouble()));
            sh.setCodeModify(BigDecimal.valueOf(realDa.getPointValueInDouble()));
            shs.add(sh);
        }
        try {
            boolean b = stationInfoHourService.saveBatch(shs);
            System.out.println("成功");
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

//    public void writeReportHistory(Date date) throws Exception {
////        String[] dateTime = {"2024-12-13 08:00:00","2024-12-13 12:00:00", "2024-12-13 16:00:00", "2024-12-13 20:00:00"};
//        String[] dateTime = {"2024-12-25 00:00:00", "2024-12-25 04:00:00", "2024-12-25 08:00:00", "2024-12-24 20:00:00"};
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        String[] split = repInfo1.split(",");
//        List<String> ls = new ArrayList<>(Arrays.asList(split));
//        for (String s : dateTime) {
//            Date date1 = simpleDateFormat.parse(s);
//            long timestamp = date1.getTime();
////            for (long i = timestamp; i < 1735033631000L; i += 86400000) {
//            List<StationInfoHour> shs = new ArrayList<>();
//            for (String l : ls) {
////                    Map<String, PointData2> historySection = adapter.getHistorySection(goldenUri(), l, i);
//                Map<String, PointData2> historySection = adapter.getHistorySection(goldenUri(), l, timestamp);
//                if (null == historySection || historySection.isEmpty()) {
//                    return;
//                }
//                StationInfoHour sh = new StationInfoHour();
////                        sh.setRecordDate(LocalDateTime.ofInstant(Instant.ofEpochMilli(i),ZoneId.systemDefault()));
//                sh.setRecordDate(LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault()));
//                sh.setWpid("NX_FGS_HA_FDC_STA");
//                sh.setMeterId(l);
//                sh.setMeterName(l);
//                sh.setCode(BigDecimal.valueOf(historySection.get(l).getDoubleValue()));
//                sh.setCodeModify(BigDecimal.valueOf(historySection.get(l).getDoubleValue()));
//                shs.add(sh);
//
//            }
//            try {
//                boolean b = stationInfoHourService.saveBatch(shs);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
////            }
//        }
//
//    }


    /**
     * 执行时间：01:00:00,05:00:00,09:00:00,13:00:00,17:00:00,21:00:00,
     */
    public void writeReport2(Date date) throws Exception {
        QueryWrapper<ProBaseBackfill> qwf = new QueryWrapper<>();
        qwf.lambda().eq(ProBaseBackfill::getType, "AI0006");
        List<ProBaseBackfill> list = iProBaseBackfillService.list(qwf);
        List<String> ls = list.stream().map(ProBaseBackfill::getCode).collect(Collectors.toList());
        LocalDateTime currentTime = LocalDateTime.now();
        LocalDateTime modifiedTime = currentTime
                .withMinute(0)
                .withSecond(0)
                .withNano(0);
        List<PointData> realData = edosUtil.getRealData(ls);
        if (null == realData || realData.isEmpty()) {
            return;
        }
        List<StationInfoHour> shs = new ArrayList<>();
        for (PointData realDa : realData) {
            StationInfoHour sh = new StationInfoHour();
            sh.setRecordDate(modifiedTime);
            sh.setWpid("NX_FGS_HA_FDC_STA");
            sh.setMeterId(realDa.getPointName());
            sh.setMeterName(realDa.getPointName());
            sh.setCode(BigDecimal.valueOf(realDa.getPointValueInDouble()));
            sh.setCodeModify(BigDecimal.valueOf(realDa.getPointValueInDouble()));
            shs.add(sh);
        }
        try {
            boolean b = stationInfoHourService.saveBatch(shs);
            System.out.println(b);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void writeReportHistory2(Date date) throws Exception {
//        String[] dateTime = {"2024-12-13 01:00:00", "2024-12-13 05:00:00", "2024-12-13 09:00:00","2024-12-13 13:00:00", "2024-12-13 17:00:00", "2024-12-13 21:00:00"};
        String[] dateTime = {"2025-03-13 01:00:00", "2025-03-13 05:00:00", "2025-03-13 09:00:00", "2025-03-13 13:00:00", "2025-03-13 17:00:00", "2025-03-13 21:00:00"};
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        QueryWrapper<ProBaseBackfill> qwf = new QueryWrapper<>();
        qwf.lambda().eq(ProBaseBackfill::getType, "AI0006");
        List<ProBaseBackfill> list = iProBaseBackfillService.list(qwf);
        List<String> ls = list.stream().map(ProBaseBackfill::getCode).collect(Collectors.toList());
//        String[] split = repInfo2.split(",");
//        List<String> ls = new ArrayList<>(Arrays.asList(split));
//        List<String> ls = new ArrayList<>();
//        ls.add("区域集控.惠安风场.升压站.110kV宋四风场线测控.Q1");
//        ls.add("区域集控.惠安风场.升压站.110kV宋四风场线测控.UAB1");
        for (String s : dateTime) {
            Date date1 = simpleDateFormat.parse(s);
            long timestamp = date1.getTime();
            for (long i = timestamp; i < 1742176332000L; i += 86400000) {
                List<StationInfoHour> shs = new ArrayList<>();
                for (String l : ls) {
                    Map<String, PointData2> historySection = adapter.getHistorySection(goldenUri(), l, timestamp);
                    if (null == historySection || historySection.isEmpty()) {
                        return;
                    }
                    StationInfoHour sh = new StationInfoHour();
                    sh.setRecordDate(LocalDateTime.ofInstant(Instant.ofEpochMilli(i), ZoneId.systemDefault()));
                    sh.setWpid("NX_FGS_HA_FDC_STA");
                    sh.setMeterId(l);
                    sh.setMeterName(l);
                    sh.setCode(BigDecimal.valueOf(historySection.get(l).getDoubleValue()));
                    sh.setCodeModify(BigDecimal.valueOf(historySection.get(l).getDoubleValue()));
                    shs.add(sh);

                }
                try {
                    boolean b = stationInfoHourService.saveBatch(shs);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

    }


    public void writeReport3(Date date) throws Exception {
        QueryWrapper<ProBaseBackfill> qw = new QueryWrapper<>();
        qw.lambda().eq(ProBaseBackfill::getType, "AI0001");
        List<ProBaseBackfill> backfills = iProBaseBackfillService.list(qw);
        List<ProEconEquipmentInfoJs> jss = new ArrayList<>();
        LocalDate now = LocalDate.now();
        QueryWrapper<ProEconEquipmentInfoJs> qw2 = new QueryWrapper<>();
        qw2.lambda().eq(ProEconEquipmentInfoJs::getRecordDate, now).eq(ProEconEquipmentInfoJs::getMeterId, "AI0001");
        List<ProEconEquipmentInfoJs> projss = iProEconEquipmentInfoJsService.list(qw2);
        if (null != projss && !projss.isEmpty()) {
            List<String> meter = projss.stream().map(ProEconEquipmentInfoJs::getMeterId).collect(Collectors.toList());
            backfills = backfills.stream().filter(bf -> !meter.contains(bf.getCode())).collect(Collectors.toList());
        }
        if (null == backfills || backfills.isEmpty()) {
            return;
        }
        for (ProBaseBackfill backfill : backfills) {
            ProEconEquipmentInfoJs js = new ProEconEquipmentInfoJs();
            js.setRecordDate(now);
            js.setWpid(backfill.getStation());
            js.setMeterId("AI0001");
            js.setMeterName(backfill.getCode());
            jss.add(js);
        }
        try {
            boolean b = iProEconEquipmentInfoJsService.saveBatch(jss);
            System.out.println(b);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


    public void writeReportHistory3(Date date) throws Exception {
        QueryWrapper<ProBaseBackfill> qw = new QueryWrapper<>();
        qw.lambda().eq(ProBaseBackfill::getType, "AI0001");
        List<ProBaseBackfill> backfills = iProBaseBackfillService.list(qw);
        List<ProEconEquipmentInfoJs> jss = new ArrayList<>();
        String[] dateTime = {"2025-01-09"};
        for (String s : dateTime) {
            LocalDate now = LocalDate.parse(s);
            QueryWrapper<ProEconEquipmentInfoJs> qw2 = new QueryWrapper<>();
            qw2.lambda().eq(ProEconEquipmentInfoJs::getRecordDate, now).eq(ProEconEquipmentInfoJs::getMeterId, "AI0001");
            List<ProEconEquipmentInfoJs> projss = iProEconEquipmentInfoJsService.list(qw2);
            if (null != projss && !projss.isEmpty()) {
                List<String> meter = projss.stream().map(ProEconEquipmentInfoJs::getMeterId).collect(Collectors.toList());
                backfills = backfills.stream().filter(bf -> !meter.contains(bf.getCode())).collect(Collectors.toList());
            }
            if (null == backfills || backfills.isEmpty()) {
                return;
            }
            for (ProBaseBackfill backfill : backfills) {
                ProEconEquipmentInfoJs js = new ProEconEquipmentInfoJs();
                js.setRecordDate(now);
                js.setWpid(backfill.getStation());
                js.setMeterId("AI0001");
                js.setMeterName(backfill.getCode());
                jss.add(js);
            }
            try {
                boolean b = iProEconEquipmentInfoJsService.saveBatch(jss);
                System.out.println(b);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }


}







