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.IProEconEquipmentInfoDay2Service;
import com.gyee.generation.service.auto.IProEconPowerstationInfoDay2Service;
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 WindPowerInfo2Service {

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

    @Resource
    private IProEconPowerstationInfoDay2Service proEconPowerstationInfoDay2Service;

    @Resource
    private IProEconEquipmentInfoDay2Service 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<ProEconPowerstationInfoDay2> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.cp.getValue());
        List<ProEconPowerstationInfoDay2> wpinfodayls = proEconPowerstationInfoDay2Service.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<ProEconPowerstationInfoDay2>>> rgmap = new HashMap<>();


            for (ProEconPowerstationInfoDay2 wpinfo : wpinfodayls) {

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

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

            if (idls.size() > 0) {

                proEconPowerstationInfoDay2Service.removeByIds(idls);

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

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

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

                    proEconPowerstationInfoDay2Service.save(qb);
                    proEconPowerstationInfoDay2Service.save(fd);
                    proEconPowerstationInfoDay2Service.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<ProEconPowerstationInfoDay2> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("record_date", DateUtils.truncate(recordDate)).eq("location", Location.wp.getValue());
        List<ProEconPowerstationInfoDay2> wpinfodayls = proEconPowerstationInfoDay2Service.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<ProEconPowerstationInfoDay2>>> cpmap = new HashMap<>();


            for (ProEconPowerstationInfoDay2 wpinfo : wpinfodayls) {

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

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

            if (idls.size() > 0) {

                proEconPowerstationInfoDay2Service.removeByIds(idls);

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

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

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

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


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


            }
        }

    }

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

        if (!ls.isEmpty()) {

            for (ProEconPowerstationInfoDay2 pepid : ls) {
                //日合计故障小时（明细）
                pewp.setRhjgzxsmx(StringUtils.round(pewp.getRhjgzxsmx() + pepid.getRhjgzxsmx(), 2));
                //日合计场内受累故障小时（明细）
                pewp.setRhjcnslgzxsmx(StringUtils.round(pewp.getRhjcnslgzxsmx() + pepid.getRhjcnslgzxsmx(), 2));
                //日合计检修小时（明细）
                pewp.setRhjjxxsmx(StringUtils.round(pewp.getRhjjxxsmx() + pepid.getRhjjxxsmx(), 2));
                //日合计场内受累检修小时（明细）
                pewp.setRhjcnsljxxsmx(StringUtils.round(pewp.getRhjcnsljxxsmx() + pepid.getRhjcnsljxxsmx(), 2));
                //日合计待机小时（明细）
                pewp.setRhjdjxsmx(StringUtils.round(pewp.getRhjdjxsmx() + pepid.getRhjdjxsmx(), 2));
                //日合计缺陷降出力小时（明细）
                pewp.setRhjqxjclxsmx(StringUtils.round(pewp.getRhjqxjclxsmx() + pepid.getRhjqxjclxsmx(), 2));
                //日合计手动停机小时（明细）
                pewp.setRhjsdtjxsmx(StringUtils.round(pewp.getRhjsdtjxsmx() + pepid.getRhjsdtjxsmx(), 2));
                //日合计性能小时（明细）
                pewp.setRhjbwxsmx(StringUtils.round(pewp.getRhjbwxsmx() + pepid.getRhjbwxsmx(), 2));
                //日合计限电停机小时（明细）
                pewp.setRhjxdtjxsmx(StringUtils.round(pewp.getRhjxdtjxsmx() + pepid.getRhjxdtjxsmx(), 2));
                //日合计限电降出力小时（明细）
                pewp.setRhjxdjclxsmx(StringUtils.round(pewp.getRhjxdjclxsmx() + pepid.getRhjxdjclxsmx(), 2));
                //日合计场外受累电网小时（明细）
                pewp.setRhjcwsldwxsmx(StringUtils.round(pewp.getRhjcwsldwxsmx() + pepid.getRhjcwsldwxsmx(), 2));
                //日合计场外受累电网小时（明细）
                pewp.setRhjcwsltqxsmx(StringUtils.round(pewp.getRhjcwsltqxsmx() + pepid.getRhjcwsltqxsmx(), 2));
                //日合计通讯中断小时（明细）
                pewp.setRhjtxzdxsmx(StringUtils.round(pewp.getRhjtxzdxsmx() + pepid.getRhjtxzdxsmx(), 2));
                //日合计离线小时（明细）
                pewp.setRhjlxxsmx(StringUtils.round(pewp.getRhjlxxsmx() + pepid.getRhjlxxsmx(), 2));

                //月合计故障小时（明细）
                pewp.setYhjgzxsmx(StringUtils.round(pewp.getYhjgzxsmx() + pepid.getYhjgzxsmx(), 2));
                //月合计场内受累故障小时（明细）
                pewp.setYhjcnslgzxsmx(StringUtils.round(pewp.getYhjcnslgzxsmx() + pepid.getYhjcnslgzxsmx(), 2));
                //月合计检修小时（明细）
                pewp.setYhjjxxsmx(StringUtils.round(pewp.getYhjjxxsmx() + pepid.getYhjjxxsmx(), 2));
                //月合计场内受累检修小时（明细）
                pewp.setYhjcnsljxxsmx(StringUtils.round(pewp.getYhjcnsljxxsmx() + pepid.getYhjcnsljxxsmx(), 2));
                //月合计待机小时（明细）
                pewp.setYhjdjxsmx(StringUtils.round(pewp.getYhjdjxsmx() + pepid.getYhjdjxsmx(), 2));
                //月合计缺陷降出力小时（明细）
                pewp.setYhjqxjclxsmx(StringUtils.round(pewp.getYhjqxjclxsmx() + pepid.getYhjqxjclxsmx(), 2));
                //月合计手动停机小时（明细）
                pewp.setYhjsdtjxsmx(StringUtils.round(pewp.getYhjsdtjxsmx() + pepid.getYhjsdtjxsmx(), 2));
                //月合计性能小时（明细）
                pewp.setYhjbwxsmx(StringUtils.round(pewp.getYhjbwxsmx() + pepid.getYhjbwxsmx(), 2));
                //月合计限电停机小时（明细）
                pewp.setYhjxdtjxsmx(StringUtils.round(pewp.getYhjxdtjxsmx() + pepid.getYhjxdtjxsmx(), 2));
                //月合计限电降出力小时（明细）
                pewp.setYhjxdjclxsmx(StringUtils.round(pewp.getYhjxdjclxsmx() + pepid.getYhjxdjclxsmx(), 2));
                //月合计场外受累电网小时（明细）
                pewp.setYhjcwsldwxsmx(StringUtils.round(pewp.getYhjcwsldwxsmx() + pepid.getYhjcwsldwxsmx(), 2));
                //月合计场外受累电网小时（明细）
                pewp.setYhjcwsltqxsmx(StringUtils.round(pewp.getYhjcwsltqxsmx() + pepid.getYhjcwsltqxsmx(), 2));
                //月合计通讯中断小时（明细）
                pewp.setYhjtxzdxsmx(StringUtils.round(pewp.getYhjtxzdxsmx() + pepid.getYhjtxzdxsmx(), 2));
                //月合计离线小时（明细）
                pewp.setYhjlxxsmx(StringUtils.round(pewp.getYhjlxxsmx() + pepid.getYhjlxxsmx(), 2));

                //年合计故障小时（明细）
                pewp.setNhjgzxsmx(StringUtils.round(pewp.getNhjgzxsmx() + pepid.getNhjgzxsmx(), 2));
                //年合计场内受累故障小时（明细）
                pewp.setNhjcnslgzxsmx(StringUtils.round(pewp.getNhjcnslgzxsmx() + pepid.getNhjcnslgzxsmx(), 2));
                //年合计检修小时（明细）
                pewp.setNhjjxxsmx(StringUtils.round(pewp.getNhjjxxsmx() + pepid.getNhjjxxsmx(), 2));
                //年合计场内受累检修小时（明细）
                pewp.setNhjcnsljxxsmx(StringUtils.round(pewp.getNhjcnsljxxsmx() + pepid.getNhjcnsljxxsmx(), 2));
                //年合计待机小时（明细）
                pewp.setNhjdjxsmx(StringUtils.round(pewp.getNhjdjxsmx() + pepid.getNhjdjxsmx(), 2));
                //年合计缺陷降出力小时（明细）
                pewp.setNhjqxjclxsmx(StringUtils.round(pewp.getNhjqxjclxsmx() + pepid.getNhjqxjclxsmx(), 2));
                //年合计手动停机小时（明细）
                pewp.setNhjsdtjxsmx(StringUtils.round(pewp.getNhjsdtjxsmx() + pepid.getNhjsdtjxsmx(), 2));
                //年合计性能小时（明细）
                pewp.setNhjbwxsmx(StringUtils.round(pewp.getNhjbwxsmx() + pepid.getNhjbwxsmx(), 2));
                //年合计限电停机小时（明细）
                pewp.setNhjxdtjxsmx(StringUtils.round(pewp.getNhjxdtjxsmx() + pepid.getNhjxdtjxsmx(), 2));
                //年合计限电降出力小时（明细）
                pewp.setNhjxdjclxsmx(StringUtils.round(pewp.getNhjxdjclxsmx() + pepid.getNhjxdjclxsmx(), 2));
                //年合计场外受累电网小时（明细）
                pewp.setNhjcwsldwxsmx(StringUtils.round(pewp.getNhjcwsldwxsmx() + pepid.getNhjcwsldwxsmx(), 2));
                //年合计场外受累电网小时（明细）
                pewp.setNhjcwsltqxsmx(StringUtils.round(pewp.getNhjcwsltqxsmx() + pepid.getNhjcwsltqxsmx(), 2));
                //年合计通讯中断小时（明细）
                pewp.setNhjtxzdxsmx(StringUtils.round(pewp.getNhjtxzdxsmx() + pepid.getNhjtxzdxsmx(), 2));
                //年合计离线小时（明细）
                pewp.setNhjlxxsmx(StringUtils.round(pewp.getNhjlxxsmx() + pepid.getNhjlxxsmx(), 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<ProEconEquipmentInfoDay2>> pep2map = new HashMap<>();
        QueryWrapper<ProEconEquipmentInfoDay2> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("record_date", DateUtils.truncate(recordDate));
        List<ProEconEquipmentInfoDay2> pep1ls = proEconEquipmentInfoDay2Service.list(queryWrapper1);
        if (!pep1ls.isEmpty()) {
            for (ProEconEquipmentInfoDay2 pep : pep1ls) {
                if (pep2map.containsKey(pep.getWindpowerstationId())) {
                    List<ProEconEquipmentInfoDay2> pepls = pep2map.get(pep.getWindpowerstationId());
                    pepls.add(pep);
                } else {
                    List<ProEconEquipmentInfoDay2> pepls = new ArrayList<>();
                    pepls.add(pep);
                    pep2map.put(pep.getWindpowerstationId(), pepls);
                }

            }
        }


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

                ProEconPowerstationInfoDay2 pewp = new ProEconPowerstationInfoDay2();
                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<ProEconPowerstationInfoDay2> 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<ProEconPowerstationInfoDay2> queryWrapper2 = new QueryWrapper<>();
                    queryWrapper2.eq("record_date", DateUtils.truncate(cl.getTime()))
                            .eq("windpowerstation_id", "wp.getId()")
                            .eq("location", Location.wp.getValue());
                    pepidls = proEconPowerstationInfoDay2Service.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);
                // proEconPowerstationInfoDay2Service.save(pewp);
                wpls.add(wp.getId());
            }


        }


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

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

        if (idls.size() > 0) {

            proEconPowerstationInfoDay2Service.removeByIds(idls);

        }

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

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

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

            ProEconPowerstationInfoDay2 pewp = new ProEconPowerstationInfoDay2();
            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<ProEconPowerstationInfoDay2> 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<ProEconPowerstationInfoDay2> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.eq("record_date", DateUtils.truncate(cl.getTime()))
                        .eq("location", Location.pj.getValue())
                        .eq("project_id", pj.getId());
                pepidls = proEconPowerstationInfoDay2Service.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);
            // proEconPowerstationInfoDay2Service.save(pewp);

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

        }

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

        if (idls.size() > 0) {

            proEconPowerstationInfoDay2Service.removeByIds(idls);

        }

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

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

            }
        }

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

            ProEconPowerstationInfoDay2 pewp = new ProEconPowerstationInfoDay2();

            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<ProEconPowerstationInfoDay2> 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<ProEconPowerstationInfoDay2> queryWrapper2 = new QueryWrapper<>();
                queryWrapper2.eq("record_date", DateUtils.truncate(cl.getTime()))
                        .eq("location", Location.ln.getValue())
                        .eq("line_id", ln.getId());
                pepidls = proEconPowerstationInfoDay2Service.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);
            // proEconPowerstationInfoDay2Service.save(pewp);
            if (CacheContext.pjmap.containsKey(ln.getProjectId())) {
                lnls.add(CacheContext.pjmap.get(ln.getProjectId()).getWindpowerstationId());
            }
        }


        //        }


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

        if (idls.size() > 0) {

            proEconPowerstationInfoDay2Service.removeByIds(idls);

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

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

    private void calDetiall(ProEconPowerstationInfoDay2 pewp, String id, Map<String, List<ProEconEquipmentInfoDay2>> 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<ProEconEquipmentInfoDay2> pep2ls = pep2map.get(id);

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRgzxsmx).summaryStatistics();
                //日合计故障小时（明细）
                pewp.setRhjgzxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计场内受累故障小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRcnslgzxsmx).summaryStatistics();
                pewp.setRhjcnslgzxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计检修小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRjxxsmx).summaryStatistics();
                pewp.setRhjjxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计场内受累检修小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRcnsljxxsmx).summaryStatistics();
                pewp.setRhjcnsljxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计待机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRdjxsmx).summaryStatistics();
                pewp.setRhjdjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计缺陷降出力小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRqxjclxsmx).summaryStatistics();
                pewp.setRhjqxjclxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计手动停机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRsdtjxsmx).summaryStatistics();
                pewp.setRhjsdtjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计性能小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRbwxsmx).summaryStatistics();
                pewp.setRhjbwxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计限电停机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRxdtjxsmx).summaryStatistics();
                pewp.setRhjxdtjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计限电降出力小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRxdjclxsmx).summaryStatistics();
                pewp.setRhjxdjclxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计场外受累电网小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRcwsldwxsmx).summaryStatistics();
                pewp.setRhjcwsldwxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计场外受累电网小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRcwsltqxsmx).summaryStatistics();
                pewp.setRhjcwsltqxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计通讯中断小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRtxzdxsmx).summaryStatistics();
                pewp.setRhjtxzdxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计离线小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRlxxsmx).summaryStatistics();
                pewp.setRhjlxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }


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

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

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

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYgzxsmx).summaryStatistics();
                //月合计故障小时（明细）
                pewp.setYhjgzxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计场内受累故障小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYcnslgzxsmx).summaryStatistics();
                pewp.setYhjcnslgzxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计检修小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYjxxsmx).summaryStatistics();
                pewp.setYhjjxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计场内受累检修小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYcnsljxxsmx).summaryStatistics();
                pewp.setYhjcnsljxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计待机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYdjxsmx).summaryStatistics();
                pewp.setYhjdjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计缺陷降出力小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYqxjclxsmx).summaryStatistics();
                pewp.setYhjqxjclxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计手动停机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYsdtjxsmx).summaryStatistics();
                pewp.setYhjsdtjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计性能小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYbwxsmx).summaryStatistics();
                pewp.setYhjbwxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计限电停机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYxdtjxsmx).summaryStatistics();
                pewp.setYhjxdtjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计限电降出力小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYxdjclxsmx).summaryStatistics();
                pewp.setYhjxdjclxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计场外受累电网小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYcwsldwxsmx).summaryStatistics();
                pewp.setYhjcwsldwxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计场外受累电网小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYcwsltqxsmx).summaryStatistics();
                pewp.setYhjcwsltqxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计通讯中断小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYtxzdxsmx).summaryStatistics();
                pewp.setYhjtxzdxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计离线小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYlxxsmx).summaryStatistics();
                pewp.setYhjlxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }


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

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

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNgzxsmx).summaryStatistics();
                //年合计故障小时（明细）
                pewp.setNhjgzxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计场内受累故障小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNcnslgzxsmx).summaryStatistics();
                pewp.setNhjcnslgzxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计检修小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNjxxsmx).summaryStatistics();
                pewp.setNhjjxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计场内受累检修小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNcnsljxxsmx).summaryStatistics();
                pewp.setNhjcnsljxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计待机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNdjxsmx).summaryStatistics();
                pewp.setNhjdjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计缺陷降出力小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNqxjclxsmx).summaryStatistics();
                pewp.setNhjqxjclxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计手动停机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNsdtjxsmx).summaryStatistics();
                pewp.setNhjsdtjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计性能小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNbwxsmx).summaryStatistics();
                pewp.setNhjbwxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计限电停机小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNxdtjxsmx).summaryStatistics();
                pewp.setNhjxdtjxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计限电降出力小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNxdjclxsmx).summaryStatistics();
                pewp.setNhjxdjclxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计场外受累电网小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNcwsldwxsmx).summaryStatistics();
                pewp.setNhjcwsldwxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计场外受累电网小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNcwsltqxsmx).summaryStatistics();
                pewp.setNhjcwsltqxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计通讯中断小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNtxzdxsmx).summaryStatistics();
                pewp.setNhjtxzdxsmx(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计离线小时（明细）
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNlxxsmx).summaryStatistics();
                pewp.setNhjlxxsmx(StringUtils.round(summaryStatistics.getSum(), 2));

            }
        }


    }

    private static void setLossHoursYear(ProEconPowerstationInfoDay2 pewp) {
        //年合计故障小时（明细）
        pewp.setNhjgzxsmx(pewp.getRhjgzxsmx());
        //年合计场内受累故障小时（明细）
        pewp.setNhjcnslgzxsmx(pewp.getRhjcnslgzxsmx());
        //年合计检修小时（明细）
        pewp.setNhjjxxsmx(pewp.getRhjjxxsmx());
        //年合计场内受累检修小时（明细）
        pewp.setNhjcnsljxxsmx(pewp.getRhjcnsljxxsmx());
        //年合计待机小时（明细）
        pewp.setNhjdjxsmx(pewp.getRhjdjxsmx());
        //年合计缺陷降出力小时（明细）
        pewp.setNhjqxjclxsmx(pewp.getRhjqxjclxsmx());
        //年合计手动停机小时（明细）
        pewp.setNhjsdtjxsmx(pewp.getRhjsdtjxsmx());
        //年合计性能小时（明细）
        pewp.setNhjbwxsmx(pewp.getRhjbwxsmx());
        //年合计限电停机小时（明细）
        pewp.setNhjxdtjxsmx(pewp.getRhjxdtjxsmx());
        //年合计限电降出力小时（明细）
        pewp.setNhjxdjclxsmx(pewp.getRhjxdjclxsmx());
        //年合计场外受累电网小时（明细）
        pewp.setNhjcwsldwxsmx(pewp.getRhjcwsldwxsmx());
        //年合计场外受累电网小时（明细）
        pewp.setNhjcwsltqxsmx(pewp.getRhjcwsltqxsmx());
        //年合计通讯中断小时（明细）
        pewp.setNhjtxzdxsmx(pewp.getRhjtxzdxsmx());
        //年合计离线小时（明细）
        pewp.setNhjlxxsmx(pewp.getRhjlxxsmx());
    }

    private static void setLossHoursMonth(ProEconPowerstationInfoDay2 pewp) {
        //月合计故障小时（明细）
        pewp.setYhjgzxsmx(pewp.getRhjgzxsmx());
        //月合计场内受累故障小时（明细）
        pewp.setYhjcnslgzxsmx(pewp.getRhjcnslgzxsmx());
        //月合计检修小时（明细）
        pewp.setYhjjxxsmx(pewp.getRhjjxxsmx());
        //月合计场内受累检修小时（明细）
        pewp.setYhjcnsljxxsmx(pewp.getRhjcnsljxxsmx());
        //月合计待机小时（明细）
        pewp.setYhjdjxsmx(pewp.getRhjdjxsmx());
        //月合计缺陷降出力小时（明细）
        pewp.setYhjqxjclxsmx(pewp.getRhjqxjclxsmx());
        //月合计手动停机小时（明细）
        pewp.setYhjsdtjxsmx(pewp.getRhjsdtjxsmx());
        //月合计性能小时（明细）
        pewp.setYhjbwxsmx(pewp.getRhjbwxsmx());
        //月合计限电停机小时（明细）
        pewp.setYhjxdtjxsmx(pewp.getRhjxdtjxsmx());
        //月合计限电降出力小时（明细）
        pewp.setYhjxdjclxsmx(pewp.getRhjxdjclxsmx());
        //月合计场外受累电网小时（明细）
        pewp.setYhjcwsldwxsmx(pewp.getRhjcwsldwxsmx());
        //月合计场外受累电网小时（明细）
        pewp.setYhjcwsltqxsmx(pewp.getRhjcwsltqxsmx());
        //月合计通讯中断小时（明细）
        pewp.setYhjtxzdxsmx(pewp.getRhjtxzdxsmx());
        //月合计离线小时（明细）
        pewp.setYhjlxxsmx(pewp.getRhjlxxsmx());
    }


    private static void setLossHoursMonthSimple(ProEconPowerstationInfoDay2 pewp) {
        //月合计待机小时
        pewp.setYhjdjxs(pewp.getRhjdjxs());
        //月合计维护停机小时
        pewp.setYhjjxtjxs(pewp.getRhjjxtjxs());
        // 月合计故障停机小时
        pewp.setYhjgztjxs(pewp.getRhjgztjxs());
        //月合计运行小时
        pewp.setYhjyxxs(pewp.getRhjyxxs());
        //月合计限电小时
        pewp.setYhjxdxs(pewp.getRhjxdxs());
        //月合计通讯中断小时
        pewp.setYhjtxzdxs(pewp.getRhjtxzdxs());
        //月合计受累小时
        pewp.setYhjslxs(pewp.getRhjslxs());
    }

    private static void setLossHoursYearSimple(ProEconPowerstationInfoDay2 pewp) {
        //年合计待机小时
        pewp.setNhjdjxs(pewp.getRhjdjxs());
        //年合计维护停机小时
        pewp.setNhjjxtjxs(pewp.getRhjjxtjxs());
        // 年合计故障小时
        pewp.setNhjgztjxs(pewp.getRhjgztjxs());
        //年合计运行小时
        pewp.setNhjyxxs(pewp.getRhjyxxs());
        //年合计限电小时
        pewp.setNhjxdxs(pewp.getRhjxdxs());
        //年合计通讯中断小时
        pewp.setNhjtxzdxs(pewp.getRhjtxzdxs());
        //年合计受累小时
        pewp.setNhjslxs(pewp.getRhjslxs());
    }

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


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

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRdjxs).summaryStatistics();
                //日合计待机小时
                pewp.setRhjdjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计维护停机小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRjxtjxs).summaryStatistics();
                pewp.setRhjjxtjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                // 日合计待机小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRdjxs).summaryStatistics();
                pewp.setRhjdjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计运行小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRyxxs).summaryStatistics();
                pewp.setRhjyxxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计限电小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRxdxs).summaryStatistics();
                pewp.setRhjxdxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计通讯中断小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRtxzdxs).summaryStatistics();
                pewp.setRhjtxzdxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //日合计受累小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getRslxs).summaryStatistics();
                pewp.setRhjslxs(StringUtils.round(summaryStatistics.getSum(), 2));
            }
        }

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

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

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYdjxs).summaryStatistics();
                //月合计待机小时
                pewp.setYhjdjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计维护停机小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYjxtjxs).summaryStatistics();
                pewp.setYhjjxtjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                // 月合计待机小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYdjxs).summaryStatistics();
                pewp.setYhjdjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计运行小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYyxxs).summaryStatistics();
                pewp.setYhjyxxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计限电小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYxdxs).summaryStatistics();
                pewp.setYhjxdxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计通讯中断小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYtxzdxs).summaryStatistics();
                pewp.setYhjtxzdxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //月合计受累小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getYslxs).summaryStatistics();
                pewp.setYhjslxs(StringUtils.round(summaryStatistics.getSum(), 2));
            }
        }
        //*******************************************月信息统计*********************************************************/

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

            if (!pep2ls.isEmpty()) {
                DoubleSummaryStatistics summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNdjxs).summaryStatistics();
                //年合计待机小时
                pewp.setNhjdjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计维护停机小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNjxtjxs).summaryStatistics();
                pewp.setNhjjxtjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                // 年合计待机小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNdjxs).summaryStatistics();
                pewp.setNhjdjxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计运行小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNyxxs).summaryStatistics();
                pewp.setNhjyxxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计限电小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNxdxs).summaryStatistics();
                pewp.setNhjxdxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计通讯中断小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNtxzdxs).summaryStatistics();
                pewp.setNhjtxzdxs(StringUtils.round(summaryStatistics.getSum(), 2));
                //年合计受累小时
                summaryStatistics = pep2ls.stream().mapToDouble(ProEconEquipmentInfoDay2::getNslxs).summaryStatistics();
                pewp.setNhjslxs(StringUtils.round(summaryStatistics.getSum(), 2));
            }
        }
        //*******************************************年信息统计*********************************************************/
    }


}







