package com.gyee.generation.service;//package com.gyee.generation.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.common.model.StringUtils;
import com.gyee.generation.init.CacheContext;
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.IProEconEquipmentInfoDay3Service;
import com.gyee.generation.service.auto.IProEconPowerstationInfoDay3Service;
import com.gyee.generation.util.DateUtils;
import com.gyee.generation.util.realtimesource.IEdosUtil;
import com.gyee.generation.util.statisticcs.Initial;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class WindPowerInfo3Service {

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

    @Resource
    private IProEconPowerstationInfoDay3Service IProEconPoproEconPowerstationInfoDay3Service;

    @Resource
    private IProEconEquipmentInfoDay3Service proEconEquipmentInfoDay2Service;

    /**
     * 计算区域日信息
     */
    public void calRegionInfoDay(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<ProEconPowerstationInfoDay3> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.cp.getValue());
        List<ProEconPowerstationInfoDay3> wpinfodayls = IProEconPoproEconPowerstationInfoDay3Service.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<ProEconPowerstationInfoDay3>>> rgmap = new HashMap<>();


            for (ProEconPowerstationInfoDay3 wpinfo : wpinfodayls) {

                if (rgmap.containsKey(wpinfo.getRegionId())) {
                    Map<String, List<ProEconPowerstationInfoDay3>> map = rgmap.get(wpinfo.getRegionId());
                    List<ProEconPowerstationInfoDay3> qbls = map.get(CompanyType.qb.id);
                    List<ProEconPowerstationInfoDay3> fdls = map.get(CompanyType.fd.id);
                    List<ProEconPowerstationInfoDay3> 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<ProEconPowerstationInfoDay3>> map = new HashMap<>();

                    List<ProEconPowerstationInfoDay3> qbls = new ArrayList<>();
                    List<ProEconPowerstationInfoDay3> gfls = new ArrayList<>();
                    List<ProEconPowerstationInfoDay3> 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<ProEconPowerstationInfoDay3> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.rg.getValue());
            List<String> idls = IProEconPoproEconPowerstationInfoDay3Service.list(queryWrapper2).stream()
                    //                    .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
                    ////                            && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
                    //                            && i.getLocation().equals(Location.rg.getValue()))
                    .map(ProEconPowerstationInfoDay3::getId)
                    .collect(Collectors.toList());

            if (idls.size() > 0) {

                IProEconPoproEconPowerstationInfoDay3Service.removeByIds(idls);

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

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

                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);

                    IProEconPoproEconPowerstationInfoDay3Service.save(qb);
                    IProEconPoproEconPowerstationInfoDay3Service.save(fd);
                    IProEconPoproEconPowerstationInfoDay3Service.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<ProEconPowerstationInfoDay3> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.wp.getValue());
        List<ProEconPowerstationInfoDay3> wpinfodayls = IProEconPoproEconPowerstationInfoDay3Service.list(queryWrapper);
        //                .stream()
        //                .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
        ////                        && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
        //                        && i.getLocation().equals(Location.wp.getValue()))
        //                .collect(Collectors.toList());
        if (!wpinfodayls.isEmpty()) {

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


            for (ProEconPowerstationInfoDay3 wpinfo : wpinfodayls) {

                if (cpmap.containsKey(wpinfo.getCompanyId())) {
                    Map<String, List<ProEconPowerstationInfoDay3>> map = cpmap.get(wpinfo.getCompanyId());
                    List<ProEconPowerstationInfoDay3> qbls = map.get(CompanyType.qb.id);
                    List<ProEconPowerstationInfoDay3> fdls = map.get(CompanyType.fd.id);
                    List<ProEconPowerstationInfoDay3> 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<ProEconPowerstationInfoDay3>> map = new HashMap<>();

                    List<ProEconPowerstationInfoDay3> qbls = new ArrayList<>();
                    List<ProEconPowerstationInfoDay3> gfls = new ArrayList<>();
                    List<ProEconPowerstationInfoDay3> 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<ProEconPowerstationInfoDay3> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.cp.getValue());
            List<String> idls = IProEconPoproEconPowerstationInfoDay3Service.list(queryWrapper2).stream()
                    //                    .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
                    ////                            && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
                    //                            && i.getLocation().equals(Location.cp.getValue()))
                    .map(ProEconPowerstationInfoDay3::getId)
                    .collect(Collectors.toList());

            if (idls.size() > 0) {

                IProEconPoproEconPowerstationInfoDay3Service.removeByIds(idls);

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

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

                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);

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


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


            }
        }

    }

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

        if (!ls.isEmpty()) {

            for (ProEconPowerstationInfoDay3 pepid : ls) {
                //日合计故障次数（明细）
                pewp.setRhjgzcsmx(StringUtils.round(pewp.getRhjgzcsmx() + pepid.getRhjgzcsmx(), 2));
                //日合计场内受累故障次数（明细）
                pewp.setRhjcnslgzcsmx(StringUtils.round(pewp.getRhjcnslgzcsmx() + pepid.getRhjcnslgzcsmx(), 2));
                //日合计检修次数（明细）
                pewp.setRhjjxcsmx(StringUtils.round(pewp.getRhjjxcsmx() + pepid.getRhjjxcsmx(), 2));
                //日合计场内受累检修次数（明细）
                pewp.setRhjcnsljxcsmx(StringUtils.round(pewp.getRhjcnsljxcsmx() + pepid.getRhjcnsljxcsmx(), 2));
                //日合计待机次数（明细）
                pewp.setRhjdjcsmx(StringUtils.round(pewp.getRhjdjcsmx() + pepid.getRhjdjcsmx(), 2));
                //日合计缺陷降出力次数（明细）
                pewp.setRhjqxjclcsmx(StringUtils.round(pewp.getRhjqxjclcsmx() + pepid.getRhjqxjclcsmx(), 2));
                //日合计手动停机次数（明细）
                pewp.setRhjsdtjcsmx(StringUtils.round(pewp.getRhjsdtjcsmx() + pepid.getRhjsdtjcsmx(), 2));
                //日合计性能次数（明细）
                pewp.setRhjbwcsmx(StringUtils.round(pewp.getRhjbwcsmx() + pepid.getRhjbwcsmx(), 2));
                //日合计限电停机次数（明细）
                pewp.setRhjxdtjcsmx(StringUtils.round(pewp.getRhjxdtjcsmx() + pepid.getRhjxdtjcsmx(), 2));
                //日合计限电降出力次数（明细）
                pewp.setRhjxdjclcsmx(StringUtils.round(pewp.getRhjxdjclcsmx() + pepid.getRhjxdjclcsmx(), 2));
                //日合计场外受累电网次数（明细）
                pewp.setRhjcwsldwcsmx(StringUtils.round(pewp.getRhjcwsldwcsmx() + pepid.getRhjcwsldwcsmx(), 2));
                //日合计场外受累电网次数（明细）
                pewp.setRhjcwsltqcsmx(StringUtils.round(pewp.getRhjcwsltqcsmx() + pepid.getRhjcwsltqcsmx(), 2));
                //日合计通讯中断次数（明细）
                pewp.setRhjtxzdcsmx(StringUtils.round(pewp.getRhjtxzdcsmx() + pepid.getRhjtxzdcsmx(), 2));
                //日合计离线次数（明细）
                pewp.setRhjlxcsmx(StringUtils.round(pewp.getRhjlxcsmx() + pepid.getRhjlxcsmx(), 2));

                //月合计故障次数（明细）
                pewp.setYhjgzcsmx(StringUtils.round(pewp.getYhjgzcsmx() + pepid.getYhjgzcsmx(), 2));
                //月合计场内受累故障次数（明细）
                pewp.setYhjcnslgzcsmx(StringUtils.round(pewp.getYhjcnslgzcsmx() + pepid.getYhjcnslgzcsmx(), 2));
                //月合计检修次数（明细）
                pewp.setYhjjxcsmx(StringUtils.round(pewp.getYhjjxcsmx() + pepid.getYhjjxcsmx(), 2));
                //月合计场内受累检修次数（明细）
                pewp.setYhjcnsljxcsmx(StringUtils.round(pewp.getYhjcnsljxcsmx() + pepid.getYhjcnsljxcsmx(), 2));
                //月合计待机次数（明细）
                pewp.setYhjdjcsmx(StringUtils.round(pewp.getYhjdjcsmx() + pepid.getYhjdjcsmx(), 2));
                //月合计缺陷降出力次数（明细）
                pewp.setYhjqxjclcsmx(StringUtils.round(pewp.getYhjqxjclcsmx() + pepid.getYhjqxjclcsmx(), 2));
                //月合计手动停机次数（明细）
                pewp.setYhjsdtjcsmx(StringUtils.round(pewp.getYhjsdtjcsmx() + pepid.getYhjsdtjcsmx(), 2));
                //月合计性能次数（明细）
                pewp.setYhjbwcsmx(StringUtils.round(pewp.getYhjbwcsmx() + pepid.getYhjbwcsmx(), 2));
                //月合计限电停机次数（明细）
                pewp.setYhjxdtjcsmx(StringUtils.round(pewp.getYhjxdtjcsmx() + pepid.getYhjxdtjcsmx(), 2));
                //月合计限电降出力次数（明细）
                pewp.setYhjxdjclcsmx(StringUtils.round(pewp.getYhjxdjclcsmx() + pepid.getYhjxdjclcsmx(), 2));
                //月合计场外受累电网次数（明细）
                pewp.setYhjcwsldwcsmx(StringUtils.round(pewp.getYhjcwsldwcsmx() + pepid.getYhjcwsldwcsmx(), 2));
                //月合计场外受累电网次数（明细）
                pewp.setYhjcwsltqcsmx(StringUtils.round(pewp.getYhjcwsltqcsmx() + pepid.getYhjcwsltqcsmx(), 2));
                //月合计通讯中断次数（明细）
                pewp.setYhjtxzdcsmx(StringUtils.round(pewp.getYhjtxzdcsmx() + pepid.getYhjtxzdcsmx(), 2));
                //月合计离线次数（明细）
                pewp.setYhjlxcsmx(StringUtils.round(pewp.getYhjlxcsmx() + pepid.getYhjlxcsmx(), 2));

                //年合计故障次数（明细）
                pewp.setNhjgzcsmx(StringUtils.round(pewp.getNhjgzcsmx() + pepid.getNhjgzcsmx(), 2));
                //年合计场内受累故障次数（明细）
                pewp.setNhjcnslgzcsmx(StringUtils.round(pewp.getNhjcnslgzcsmx() + pepid.getNhjcnslgzcsmx(), 2));
                //年合计检修次数（明细）
                pewp.setNhjjxcsmx(StringUtils.round(pewp.getNhjjxcsmx() + pepid.getNhjjxcsmx(), 2));
                //年合计场内受累检修次数（明细）
                pewp.setNhjcnsljxcsmx(StringUtils.round(pewp.getNhjcnsljxcsmx() + pepid.getNhjcnsljxcsmx(), 2));
                //年合计待机次数（明细）
                pewp.setNhjdjcsmx(StringUtils.round(pewp.getNhjdjcsmx() + pepid.getNhjdjcsmx(), 2));
                //年合计缺陷降出力次数（明细）
                pewp.setNhjqxjclcsmx(StringUtils.round(pewp.getNhjqxjclcsmx() + pepid.getNhjqxjclcsmx(), 2));
                //年合计手动停机次数（明细）
                pewp.setNhjsdtjcsmx(StringUtils.round(pewp.getNhjsdtjcsmx() + pepid.getNhjsdtjcsmx(), 2));
                //年合计性能次数（明细）
                pewp.setNhjbwcsmx(StringUtils.round(pewp.getNhjbwcsmx() + pepid.getNhjbwcsmx(), 2));
                //年合计限电停机次数（明细）
                pewp.setNhjxdtjcsmx(StringUtils.round(pewp.getNhjxdtjcsmx() + pepid.getNhjxdtjcsmx(), 2));
                //年合计限电降出力次数（明细）
                pewp.setNhjxdjclcsmx(StringUtils.round(pewp.getNhjxdjclcsmx() + pepid.getNhjxdjclcsmx(), 2));
                //年合计场外受累电网次数（明细）
                pewp.setNhjcwsldwcsmx(StringUtils.round(pewp.getNhjcwsldwcsmx() + pepid.getNhjcwsldwcsmx(), 2));
                //年合计场外受累电网次数（明细）
                pewp.setNhjcwsltqcsmx(StringUtils.round(pewp.getNhjcwsltqcsmx() + pepid.getNhjcwsltqcsmx(), 2));
                //年合计通讯中断次数（明细）
                pewp.setNhjtxzdcsmx(StringUtils.round(pewp.getNhjtxzdcsmx() + pepid.getNhjtxzdcsmx(), 2));
                //年合计离线次数（明细）
                pewp.setNhjlxcsmx(StringUtils.round(pewp.getNhjlxcsmx() + pepid.getNhjlxcsmx(), 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<ProEconEquipmentInfoDay3>> pep2map = new HashMap<>();
        QueryWrapper<ProEconEquipmentInfoDay3> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("record_date", DateUtils.truncate(recordDate));
        List<ProEconEquipmentInfoDay3> pep1ls = proEconEquipmentInfoDay2Service.list(queryWrapper1);
        if (!pep1ls.isEmpty()) {
            for (ProEconEquipmentInfoDay3 pep : pep1ls) {
                if (pep2map.containsKey(pep.getWindpowerstationId())) {
                    List<ProEconEquipmentInfoDay3> pepls = pep2map.get(pep.getWindpowerstationId());
                    pepls.add(pep);
                } else {
                    List<ProEconEquipmentInfoDay3> pepls = new ArrayList<>();
                    pepls.add(pep);
                    pep2map.put(pep.getWindpowerstationId(), pepls);
                }

            }
        }


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

                ProEconPowerstationInfoDay3 pewp = new ProEconPowerstationInfoDay3();
                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());

                //昨日的统计结果
                List<ProEconPowerstationInfoDay3> pepidls = new ArrayList<>();
                Calendar cl = Calendar.getInstance();
                cl.setTime(recordDate);
                //昨日的统计结果
                cl.add(Calendar.DAY_OF_MONTH, -1);
                if (cl.get(Calendar.DAY_OF_MONTH) != 1) {

                    QueryWrapper<ProEconPowerstationInfoDay3> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("record_date", DateUtils.truncate(cl.getTime()))
                            .eq("windpowerstation_id", "wp.getId()")
                            .eq("location", Location.wp.getValue());
                    pepidls = IProEconPoproEconPowerstationInfoDay3Service.list(queryWrapper2);
                    //                            .stream()
                    //                            .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(cl.getTime())) == 0
                    //
                    //                                    && i.getLocation().equals(Location.wp.getValue())
                    //                                    && i.getWindpowerstationId().equals(wp.getId())
                    //                            )
                    //                            .collect(Collectors.toList());
                }
                calDetiall(pewp, wp.getId(), pep2map);

                calSimple(pewp, wp.getId(), pep2map);
                //*******************************************年信息统计*********************************************************/
                //                wpinfodayls.add(pewp);
                dayls.add(pewp);
                // IProEconPoproEconPowerstationInfoDay3Service.save(pewp);
                wpls.add(wp.getId());
            }


        }


        //判断是否有重复记录，先删除重复记录
        QueryWrapper<ProEconPowerstationInfoDay3> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate))
                .in("windpowerstation_id", wpls).eq("location", Location.wp.getValue());

        List<String> idls = IProEconPoproEconPowerstationInfoDay3Service.list(queryWrapper).stream()
                //                .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(recordDate)) == 0
                //                        && CacheContext.wpmap.containsKey(i.getWindpowerstationId())
                //                        && i.getLocation().equals(Location.wp.getValue()))
                .map(ProEconPowerstationInfoDay3::getId)
                .collect(Collectors.toList());

        if (idls.size() > 0) {

            IProEconPoproEconPowerstationInfoDay3Service.removeByIds(idls);

        }

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

        if (!templs.isEmpty()) {
            IProEconPoproEconPowerstationInfoDay3Service.saveBatch(templs);
        }
        //        IProEconPoproEconPowerstationInfoDay3Service.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<ProEconEquipmentInfoDay3>> pep2map = new HashMap<>();
        QueryWrapper<ProEconEquipmentInfoDay3> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("record_date", DateUtils.truncate(recordDate));
        List<ProEconEquipmentInfoDay3> pep1ls = proEconEquipmentInfoDay2Service.list(queryWrapper1);
        if (!pep1ls.isEmpty()) {
            for (ProEconEquipmentInfoDay3 pep : pep1ls) {
                if (pep2map.containsKey(pep.getProjectId())) {
                    List<ProEconEquipmentInfoDay3> pepls = pep2map.get(pep.getProjectId());
                    pepls.add(pep);
                } else {
                    List<ProEconEquipmentInfoDay3> pepls = new ArrayList<>();
                    pepls.add(pep);
                    pep2map.put(pep.getProjectId(), pepls);
                }

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

            ProEconPowerstationInfoDay3 pewp = new ProEconPowerstationInfoDay3();
            if (CacheContext.wpmap.containsKey(pj.getWindpowerstationId())) {
                ProBasicPowerstation wp = CacheContext.wpmap.get(pj.getWindpowerstationId());
                pewp.setRegionId(wp.getRegionId());
                pewp.setCompanyId(wp.getCompanyId());
            }
            Initial.initial(pewp);
            pewp.setForeignKeyId(pj.getId());
            pewp.setWindpowerstationId(pj.getWindpowerstationId());
            pewp.setProjectId(pj.getId());
            pewp.setLocation(Location.pj.getValue());
            pewp.setRecordDate(DateUtils.truncate(recordDate));

            //昨日的统计结果
            List<ProEconPowerstationInfoDay3> pepidls = new ArrayList<>();
            Calendar cl = Calendar.getInstance();
            cl.setTime(recordDate);
            //昨日的统计结果
            cl.add(Calendar.DAY_OF_MONTH, -1);
            if (cl.get(Calendar.DAY_OF_MONTH) != 1) {
                QueryWrapper<ProEconPowerstationInfoDay3> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.eq("record_date", DateUtils.truncate(cl.getTime()))
                        .eq("location", Location.pj.getValue())
                        .eq("project_id", pj.getId());
                pepidls = IProEconPoproEconPowerstationInfoDay3Service.list(queryWrapper2);
                //                        .stream()
                //                        .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(cl.getTime())) == 0
                //
                //                                && i.getLocation().equals(Location.pj.getValue())
                //                                && i.getProjectId().equals(pj.getId())
                //                        )
                //                        .collect(Collectors.toList());
            }


            calDetiall(pewp, pj.getId(), pep2map);

            calSimple(pewp, pj.getId(), pep2map);

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

            //            }
            pjls.add(pj.getWindpowerstationId());

        }

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

        if (idls.size() > 0) {

            IProEconPoproEconPowerstationInfoDay3Service.removeByIds(idls);

        }

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

        if (!templs.isEmpty()) {
            IProEconPoproEconPowerstationInfoDay3Service.saveBatch(templs);
        }
        //        IProEconPoproEconPowerstationInfoDay3Service.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<ProEconEquipmentInfoDay3>> pep2map = new HashMap<>();
        QueryWrapper<ProEconEquipmentInfoDay3> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("record_date", DateUtils.truncate(recordDate));
        List<ProEconEquipmentInfoDay3> pep1ls = proEconEquipmentInfoDay2Service.list(queryWrapper1);
        if (!pep1ls.isEmpty()) {
            for (ProEconEquipmentInfoDay3 pep : pep1ls) {
                if (pep2map.containsKey(pep.getLineId())) {
                    List<ProEconEquipmentInfoDay3> pepls = pep2map.get(pep.getLineId());
                    pepls.add(pep);
                } else {
                    List<ProEconEquipmentInfoDay3> pepls = new ArrayList<>();
                    pepls.add(pep);
                    pep2map.put(pep.getLineId(), pepls);
                }

            }
        }

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

            ProEconPowerstationInfoDay3 pewp = new ProEconPowerstationInfoDay3();

            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());
                }

            }
            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));

            //昨日的统计结果
            List<ProEconPowerstationInfoDay3> pepidls = new ArrayList<>();
            Calendar cl = Calendar.getInstance();
            cl.setTime(recordDate);
            //昨日的统计结果
            cl.add(Calendar.DAY_OF_MONTH, -1);
            if (cl.get(Calendar.DAY_OF_MONTH) != 1) {
                QueryWrapper<ProEconPowerstationInfoDay3> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.eq("record_date", DateUtils.truncate(cl.getTime()))
                        .eq("location", Location.ln.getValue())
                        .eq("line_id", ln.getId());
                pepidls = IProEconPoproEconPowerstationInfoDay3Service.list(queryWrapper2);
                //                        .stream()
                //                        .filter(i -> i.getRecordDate().compareTo(DateUtils.truncate(cl.getTime())) == 0
                //                                && i.getLocation().equals(Location.ln.getValue())
                //                                && i.getLineId().equals(ln.getId())
                //                        )
                //                        .collect(Collectors.toList());
            }
            calDetiall(pewp, ln.getId(), pep2map);

            calSimple(pewp, ln.getId(), pep2map);
            dayls.add(pewp);
            // IProEconPoproEconPowerstationInfoDay3Service.save(pewp);
            if (CacheContext.pjmap.containsKey(ln.getProjectId())) {
                lnls.add(CacheContext.pjmap.get(ln.getProjectId()).getWindpowerstationId());
            }
        }


        //        }


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

        if (idls.size() > 0) {

            IProEconPoproEconPowerstationInfoDay3Service.removeByIds(idls);

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

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

    private void calDetiall(ProEconPowerstationInfoDay3 pewp, String id, Map<String, List<ProEconEquipmentInfoDay3>> pep2map) throws Exception {
        //        //                0	待机
        //                1	手动停机
        //                2	正常发电
        //                3	发电降出力
        //                4	故障
        //                5	故障受累
        //                6	检修
        //                7	检修受累
        //                8	限电降出力
        //                9	限电停机
        //                10	电网受累
        //                11	环境受累
        //                12	通讯中断
        //                13	设备离线

        double lastState;//上一分钟状态

        double djsc = 0;//待机时长
        double sdtjsc = 0;//手动停机时长
        double zcfdsc = 0;//正常发电时长
        double fdjclsc = 0;//发电降出力时长
        double gzsc = 0;//故障时长
        double gzslsc = 0;//故障受累时长
        double jxsc = 0;//检修时长
        double jxslsc = 0;//检修受累时长
        double xdjclsc = 0;//限电降出力时长
        double xdtjsc = 0;//限电停机时长
        double dwslsc = 0;//电网受累时长
        double hjslsc = 0;//环境受累时长
        double txzdsc = 0;//通讯中断时长
        double sblxsc = 0;//设备离线时长

        if (pep2map.containsKey(id)) {
            List<ProEconEquipmentInfoDay3> pep2ls = pep2map.get(id);

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRgzcsmx).summaryStatistics();
                //日合计故障次数（明细）
                pewp.setRhjgzcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计场内受累故障次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRcnslgzcsmx).summaryStatistics();
                pewp.setRhjcnslgzcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计检修次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRjxcsmx).summaryStatistics();
                pewp.setRhjjxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计场内受累检修次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRcnsljxcsmx).summaryStatistics();
                pewp.setRhjcnsljxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计待机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRdjcsmx).summaryStatistics();
                pewp.setRhjdjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计缺陷降出力次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRqxjclcsmx).summaryStatistics();
                pewp.setRhjqxjclcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计手动停机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRsdtjcsmx).summaryStatistics();
                pewp.setRhjsdtjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计性能次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRbwcsmx).summaryStatistics();
                pewp.setRhjbwcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计限电停机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRxdtjcsmx).summaryStatistics();
                pewp.setRhjxdtjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计限电降出力次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRxdjclcsmx).summaryStatistics();
                pewp.setRhjxdjclcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计场外受累电网次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRcwsldwcsmx).summaryStatistics();
                pewp.setRhjcwsldwcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计场外受累电网次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRcwsltqcsmx).summaryStatistics();
                pewp.setRhjcwsltqcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计通讯中断次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRtxzdcsmx).summaryStatistics();
                pewp.setRhjtxzdcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计离线次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRlxcsmx).summaryStatistics();
                pewp.setRhjlxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }


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

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

        if (pep2map.containsKey(id)) {
            List<ProEconEquipmentInfoDay3> pep2ls = pep2map.get(id);

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYgzcsmx).summaryStatistics();
                //月合计故障次数（明细）
                pewp.setYhjgzcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计场内受累故障次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYcnslgzcsmx).summaryStatistics();
                pewp.setYhjcnslgzcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计检修次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYjxcsmx).summaryStatistics();
                pewp.setYhjjxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计场内受累检修次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYcnsljxcsmx).summaryStatistics();
                pewp.setYhjcnsljxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计待机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYdjcsmx).summaryStatistics();
                pewp.setYhjdjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计缺陷降出力次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYqxjclcsmx).summaryStatistics();
                pewp.setYhjqxjclcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计手动停机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYsdtjcsmx).summaryStatistics();
                pewp.setYhjsdtjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计性能次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYbwcsmx).summaryStatistics();
                pewp.setYhjbwcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计限电停机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYxdtjcsmx).summaryStatistics();
                pewp.setYhjxdtjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计限电降出力次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYxdjclcsmx).summaryStatistics();
                pewp.setYhjxdjclcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计场外受累电网次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYcwsldwcsmx).summaryStatistics();
                pewp.setYhjcwsldwcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计场外受累电网次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYcwsltqcsmx).summaryStatistics();
                pewp.setYhjcwsltqcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计通讯中断次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYtxzdcsmx).summaryStatistics();
                pewp.setYhjtxzdcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计离线次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYlxcsmx).summaryStatistics();
                pewp.setYhjlxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }


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

        //*******************************************年信息统计*********************************************************/
        if (pep2map.containsKey(id)) {
            List<ProEconEquipmentInfoDay3> pep2ls = pep2map.get(id);

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNgzcsmx).summaryStatistics();
                //年合计故障次数（明细）
                pewp.setNhjgzcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计场内受累故障次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNcnslgzcsmx).summaryStatistics();
                pewp.setNhjcnslgzcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计检修次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNjxcsmx).summaryStatistics();
                pewp.setNhjjxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计场内受累检修次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNcnsljxcsmx).summaryStatistics();
                pewp.setNhjcnsljxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计待机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNdjcsmx).summaryStatistics();
                pewp.setNhjdjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计缺陷降出力次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNqxjclcsmx).summaryStatistics();
                pewp.setNhjqxjclcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计手动停机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNsdtjcsmx).summaryStatistics();
                pewp.setNhjsdtjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计性能次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNbwcsmx).summaryStatistics();
                pewp.setNhjbwcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计限电停机次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNxdtjcsmx).summaryStatistics();
                pewp.setNhjxdtjcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计限电降出力次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNxdjclcsmx).summaryStatistics();
                pewp.setNhjxdjclcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计场外受累电网次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNcwsldwcsmx).summaryStatistics();
                pewp.setNhjcwsldwcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计场外受累电网次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNcwsltqcsmx).summaryStatistics();
                pewp.setNhjcwsltqcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计通讯中断次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNtxzdcsmx).summaryStatistics();
                pewp.setNhjtxzdcsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计离线次数（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNlxcsmx).summaryStatistics();
                pewp.setNhjlxcsmx(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }


    }

    private static void setLossHoursYear(ProEconPowerstationInfoDay3 pewp) {
        //年合计故障次数（明细）
        pewp.setNhjgzcsmx(pewp.getRhjgzcsmx());
        //年合计场内受累故障次数（明细）
        pewp.setNhjcnslgzcsmx(pewp.getRhjcnslgzcsmx());
        //年合计检修次数（明细）
        pewp.setNhjjxcsmx(pewp.getRhjjxcsmx());
        //年合计场内受累检修次数（明细）
        pewp.setNhjcnsljxcsmx(pewp.getRhjcnsljxcsmx());
        //年合计待机次数（明细）
        pewp.setNhjdjcsmx(pewp.getRhjdjcsmx());
        //年合计缺陷降出力次数（明细）
        pewp.setNhjqxjclcsmx(pewp.getRhjqxjclcsmx());
        //年合计手动停机次数（明细）
        pewp.setNhjsdtjcsmx(pewp.getRhjsdtjcsmx());
        //年合计性能次数（明细）
        pewp.setNhjbwcsmx(pewp.getRhjbwcsmx());
        //年合计限电停机次数（明细）
        pewp.setNhjxdtjcsmx(pewp.getRhjxdtjcsmx());
        //年合计限电降出力次数（明细）
        pewp.setNhjxdjclcsmx(pewp.getRhjxdjclcsmx());
        //年合计场外受累电网次数（明细）
        pewp.setNhjcwsldwcsmx(pewp.getRhjcwsldwcsmx());
        //年合计场外受累电网次数（明细）
        pewp.setNhjcwsltqcsmx(pewp.getRhjcwsltqcsmx());
        //年合计通讯中断次数（明细）
        pewp.setNhjtxzdcsmx(pewp.getRhjtxzdcsmx());
        //年合计离线次数（明细）
        pewp.setNhjlxcsmx(pewp.getRhjlxcsmx());
    }

    private static void setLossHoursMonth(ProEconPowerstationInfoDay3 pewp) {
        //月合计故障次数（明细）
        pewp.setYhjgzcsmx(pewp.getRhjgzcsmx());
        //月合计场内受累故障次数（明细）
        pewp.setYhjcnslgzcsmx(pewp.getRhjcnslgzcsmx());
        //月合计检修次数（明细）
        pewp.setYhjjxcsmx(pewp.getRhjjxcsmx());
        //月合计场内受累检修次数（明细）
        pewp.setYhjcnsljxcsmx(pewp.getRhjcnsljxcsmx());
        //月合计待机次数（明细）
        pewp.setYhjdjcsmx(pewp.getRhjdjcsmx());
        //月合计缺陷降出力次数（明细）
        pewp.setYhjqxjclcsmx(pewp.getRhjqxjclcsmx());
        //月合计手动停机次数（明细）
        pewp.setYhjsdtjcsmx(pewp.getRhjsdtjcsmx());
        //月合计性能次数（明细）
        pewp.setYhjbwcsmx(pewp.getRhjbwcsmx());
        //月合计限电停机次数（明细）
        pewp.setYhjxdtjcsmx(pewp.getRhjxdtjcsmx());
        //月合计限电降出力次数（明细）
        pewp.setYhjxdjclcsmx(pewp.getRhjxdjclcsmx());
        //月合计场外受累电网次数（明细）
        pewp.setYhjcwsldwcsmx(pewp.getRhjcwsldwcsmx());
        //月合计场外受累电网次数（明细）
        pewp.setYhjcwsltqcsmx(pewp.getRhjcwsltqcsmx());
        //月合计通讯中断次数（明细）
        pewp.setYhjtxzdcsmx(pewp.getRhjtxzdcsmx());
        //月合计离线次数（明细）
        pewp.setYhjlxcsmx(pewp.getRhjlxcsmx());
    }


    private static void setLossHoursMonthSimple(ProEconPowerstationInfoDay3 pewp) {
        //月合计待机次数
        pewp.setYhjdjcs(pewp.getRhjdjcs());
        //月合计维护停机次数
        pewp.setYhjjxtjcs(pewp.getRhjjxtjcs());
        // 月合计故障停机次数
        pewp.setYhjgztjcs(pewp.getRhjgztjcs());
        //月合计运行次数
        pewp.setYhjyxcs(pewp.getRhjyxcs());
        //月合计限电次数
        pewp.setYhjxdcs(pewp.getRhjxdcs());
        //月合计通讯中断次数
        pewp.setYhjtxzdcs(pewp.getRhjtxzdcs());
        //月合计受累次数
        pewp.setYhjslcs(pewp.getRhjslcs());
    }

    private static void setLossHoursYearSimple(ProEconPowerstationInfoDay3 pewp) {
        //年合计待机次数
        pewp.setNhjdjcs(pewp.getRhjdjcs());
        //年合计维护停机次数
        pewp.setNhjjxtjcs(pewp.getRhjjxtjcs());
        // 年合计故障次数
        pewp.setNhjgztjcs(pewp.getRhjgztjcs());
        //年合计运行次数
        pewp.setNhjyxcs(pewp.getRhjyxcs());
        //年合计限电次数
        pewp.setNhjxdcs(pewp.getRhjxdcs());
        //年合计通讯中断次数
        pewp.setNhjtxzdcs(pewp.getRhjtxzdcs());
        //年合计受累次数
        pewp.setNhjslcs(pewp.getRhjslcs());
    }

    private void calSimple(ProEconPowerstationInfoDay3 pewp, String id, Map<String, List<ProEconEquipmentInfoDay3>> pep2map) throws Exception {
        //        0	待机
        //        1	运行
        //        2	故障
        //        3	检修
        //        4	限电
        //        5	受累
        //        6	离线
        //*******************************************日信息统计*********************************************************/


        if (pep2map.containsKey(id)) {
            List<ProEconEquipmentInfoDay3> pep2ls = pep2map.get(id);

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRdjcs).summaryStatistics();
                //日合计待机次数
                pewp.setRhjdjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计维护停机次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRjxtjcs).summaryStatistics();
                pewp.setRhjjxtjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                // 日合计待机次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRdjcs).summaryStatistics();
                pewp.setRhjdjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计运行次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRyxcs).summaryStatistics();
                pewp.setRhjyxcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计限电次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRxdcs).summaryStatistics();
                pewp.setRhjxdcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计通讯中断次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRtxzdcs).summaryStatistics();
                pewp.setRhjtxzdcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计受累次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getRslcs).summaryStatistics();
                pewp.setRhjslcs(StringUtils.round(summaryStatistics.getSum(), 2));
            }
        }

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

        //*******************************************月信息统计*********************************************************/
        if (pep2map.containsKey(id)) {
            List<ProEconEquipmentInfoDay3> pep2ls = pep2map.get(id);

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYdjcs).summaryStatistics();
                //月合计待机次数
                pewp.setYhjdjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计维护停机次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYjxtjcs).summaryStatistics();
                pewp.setYhjjxtjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                // 月合计待机次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYdjcs).summaryStatistics();
                pewp.setYhjdjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计运行次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYyxcs).summaryStatistics();
                pewp.setYhjyxcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计限电次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYxdcs).summaryStatistics();
                pewp.setYhjxdcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计通讯中断次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYtxzdcs).summaryStatistics();
                pewp.setYhjtxzdcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计受累次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getYslcs).summaryStatistics();
                pewp.setYhjslcs(StringUtils.round(summaryStatistics.getSum(), 2));
            }
        }
        //*******************************************月信息统计*********************************************************/

        //*******************************************年信息统计*********************************************************/
        if (pep2map.containsKey(id)) {
            List<ProEconEquipmentInfoDay3> pep2ls = pep2map.get(id);

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNdjcs).summaryStatistics();
                //年合计待机次数
                pewp.setNhjdjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计维护停机次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNjxtjcs).summaryStatistics();
                pewp.setNhjjxtjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                // 年合计待机次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNdjcs).summaryStatistics();
                pewp.setNhjdjcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计运行次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNyxcs).summaryStatistics();
                pewp.setNhjyxcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计限电次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNxdcs).summaryStatistics();
                pewp.setNhjxdcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计通讯中断次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNtxzdcs).summaryStatistics();
                pewp.setNhjtxzdcs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计受累次数
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay3::getNslcs).summaryStatistics();
                pewp.setNhjslcs(StringUtils.round(summaryStatistics.getSum(), 2));
            }
        }
        //*******************************************年信息统计*********************************************************/
    }


}

