package cn.gyee.tamplate.service.analysis;

import cn.gyee.tamplate.init.CacheContext;
import cn.gyee.tamplate.model.auto.*;
import cn.gyee.tamplate.model.vo.AnalysisMainVo;
import cn.gyee.tamplate.model.vo.AnalysisSubVo;
import cn.gyee.tamplate.model.vo.DeskObject;
import cn.gyee.tamplate.service.*;
import cn.gyee.tamplate.util.*;
import cn.gyee.tamplate.util.common.StringUtils;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @ClassName : AnalysisNewService
 * @Author : xieshengjie
 * @Date: 2021/3/16 22:29
 * @Description : 统计分析service
 */
@Service
public class AnalysisNewService {
    @Resource
    private IAnalysismainService analysismainService;
    @Resource
    private IAnalysissubtablebottomService analysissubtablebottomService;
    @Resource
    private IAnalysissubtablebottom1Service analysissubtablebottom1Service;
    @Resource
    private IMeterpointvalueService meterpointvalueService;
    @Resource
    private IAnalysissubprojectwindcannotService analysissubprojectwindcannotService;
    @Resource
    private IAnalysissubprojectwindcanService analysissubprojectwindcanService;
    @Resource
    private IWindpowerinfodayService windpowerinfodayService;
    @Resource
    private IWindpowerinfoday3Service windpowerinfoday3Service;
    @Resource
    private IShutdownevent2Service shutdownevent2Service;
    @Resource
    private IInputoroutputspeedtotalService inputoroutputspeedtotalService;
    @Resource
    private IProjectplanService projectplanService;
    @Resource
    private IAnalysissubprojectpvcannotService analysissubprojectpvcannotService;
    @Resource
    private IAnalysissubprojectpvcanService analysissubprojectpvcanService;
    @Resource
    private IAnalysissubstationwindService analysissubstationwindService;

    @Resource
    private IAnalysissubstationpvService analysissubstationpvService;
    @Resource
    private IAnalysissubcompanyService analysissubcompanyService;

    //首风五乙线
    private static String SFWYX = "SBQDJL.NX_GD_SBQF_DD_P1_L1_001_ZXYG109";
    //#4主变高压侧
    private static String SHZBGYC = "SBQDJL.NX_GD_SBQF_DD_P1_L1_001_ZXYG117";
    //吴光二九线
    private static String WGEJX = "SBQDJL.NX_GD_SBQF_DD_P1_L1_001_ZXYG181";

    /**
     * 保存风电统计分析主表
     *
     * @param beginDate
     * @param endDate
     */
    public void savaAnalysismain(String beginDate, String endDate) {
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            //            Map<String, Object> deleteparam = new HashMap<>();
//            deleteparam.put("recorddate", DateUtils.parseDate(day));
            QueryWrapper<Analysismain> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("recorddate", DateUtils.parseDate(day)).like("wpid","FDC");
            analysismainService.remove(queryWrapper);
            for (Windpowerstation station : CacheContext.stations) {
                if (station.getId().endsWith("GDC")) {
                    continue;
                }
                Analysismain analysismain = new Analysismain();
                analysismain.setWpid(station.getId());
                analysismain.setRecorddate(DateUtils.parseDate(day));
                analysismain.setIscommit(0);
                analysismainService.save(analysismain);
            }
        }
    }

    /**
     * 保存光伏统计分析主表
     *
     * @param beginDate
     * @param endDate
     */
    public void savaAnalysisGfmain(String beginDate, String endDate) {
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
//            Map<String, Object> deleteparam = new HashMap<>();
//            deleteparam.put("recorddate", DateUtils.parseDate(day));
            QueryWrapper<Analysismain> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("recorddate", DateUtils.parseDate(day)).like("wpid","GDC");
            analysismainService.remove(queryWrapper);
            for (Windpowerstation station : CacheContext.stations) {
                if (station.getId().endsWith("FDC")) {
                    continue;
                }
                Analysismain analysismain = new Analysismain();
                analysismain.setWpid(station.getId());
                analysismain.setRecorddate(DateUtils.parseDate(day));
                analysismain.setIscommit(0);
                analysismainService.save(analysismain);
            }
        }
    }

    /**
     * 保存风电表底
     *
     * @param beginDate
     * @param endDate
     */
    public void saveAnalysisTableBottom(String beginDate, String endDate) {
        Map<String, Meterpoint2> meterMap = CacheContext.meterMap;
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            //            Map<String, Object> deleteparam = new HashMap<>();
//            deleteparam.put("recorddate", DateUtils.parseDate(day));
//            analysissubtablebottomService.removeByMap(deleteparam);

            QueryWrapper<Analysissubtablebottom> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("recorddate", DateUtils.parseDate(day)).like("wpid","FDC");
            analysissubtablebottomService.remove(queryWrapper);

            Map<String, Object> deleteparam = new HashMap<>();
            Date selDate = DateUtils.parseDate(day);
            deleteparam.put("recorddate", DateUtils.addDays(selDate,1));

            List<Meterpointvalue> meterpointvalues = meterpointvalueService.listByMap(deleteparam);


            List<Meterpointvalue> collect = meterpointvalues.stream().filter(i -> meterMap.get(i.getMeterid()) != null).filter(i -> meterMap.get(i.getMeterid()).getDescription() != null).collect(Collectors.toList());
            for (Windpowerstation station : CacheContext.stations) {
                if (station.getId().endsWith("GDC")) {
                    continue;
                }
                Analysismain mainValues = getMainValues(day, station.getId());
                collect.stream().filter(i -> meterMap.get(i.getMeterid()).getWindpowerstationid().equals(station.getId())).forEach(m -> {
                    Analysissubtablebottom analysissubtablebottom = new Analysissubtablebottom();
                    analysissubtablebottom.setTid(mainValues.getId());
                    analysissubtablebottom.setWpid(station.getId());
                    analysissubtablebottom.setMeterid(m.getMeterid());
                    analysissubtablebottom.setMetername(meterMap.get(m.getMeterid()).getDescription());
                    analysissubtablebottom.setRecorddate(DateUtils.parseDate(day));
                    analysissubtablebottom.setStopcode(m.getNow());
                    analysissubtablebottom.setStopcodemodify(m.getNow());
                    double dayvalue = DoubleUtils.GetResult(DoubleUtils.GetResult(m.getNow(),m.getDay(),"-"),meterMap.get(m.getMeterid()).getMagnification(),"*");
                    analysissubtablebottom.setDayvalue(dayvalue);
                    analysissubtablebottom.setDayvaluemodify(dayvalue);
                    analysissubtablebottomService.save(analysissubtablebottom);
                });
            }
        }
    }

    /**
     * 保存风电表底1
     *
     * @param beginDate
     * @param endDate
     */
    public void saveAnalysisTableBottom1(String beginDate, String endDate) {
        Map<String, Meterpoint2> meterMap = CacheContext.meterMap;
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            //            Map<String, Object> deleteparam = new HashMap<>();
//            deleteparam.put("recorddate", DateUtils.parseDate(day));
//            analysissubtablebottomService.removeByMap(deleteparam);

            QueryWrapper<Analysissubtablebottom1> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("recorddate", DateUtils.parseDate(day));
            analysissubtablebottom1Service.remove(queryWrapper);

            Map<String, Object> deleteparam = new HashMap<>();
            Date selDate = DateUtils.parseDate(day);
            deleteparam.put("recorddate", DateUtils.addDays(selDate,1));

            List<Meterpointvalue> meterpointvalues = meterpointvalueService.listByMap(deleteparam);


            List<Meterpointvalue> collect = meterpointvalues.stream().filter(i -> meterMap.get(i.getMeterid()) != null).filter(i -> meterMap.get(i.getMeterid()).getDescription() != null).collect(Collectors.toList());
            for (Windpowerstation station : CacheContext.stations) {

                Analysismain mainValues = getMainValues(day, station.getId());
                collect.stream().filter(i -> meterMap.get(i.getMeterid()).getWindpowerstationid().equals(station.getId())).forEach(m -> {
                    Analysissubtablebottom1 analysissubtablebottom = new Analysissubtablebottom1();
                    analysissubtablebottom.setTid(mainValues.getId());
                    analysissubtablebottom.setWpid(station.getId());
                    analysissubtablebottom.setMeterid(m.getMeterid());
                    analysissubtablebottom.setMetername(meterMap.get(m.getMeterid()).getDescription());
                    analysissubtablebottom.setRecorddate(DateUtils.parseDate(day));
                    analysissubtablebottom.setStopcode(m.getNow());
                    analysissubtablebottom.setStopcodemodify(m.getNow());
                    double dayvalue = DoubleUtils.GetResult(DoubleUtils.GetResult(m.getNow(),m.getDay(),"-"),meterMap.get(m.getMeterid()).getMagnification(),"*");
                    analysissubtablebottom.setDayvalue(dayvalue);
                    analysissubtablebottom.setDayvaluemodify(dayvalue);
                    analysissubtablebottom1Service.save(analysissubtablebottom);
                });
            }
        }
    }


    /**
     * 保存光伏表底
     *
     * @param beginDate
     * @param endDate
     */
    public void saveAnalysisGfTableBottom(String beginDate, String endDate) {
        Map<String, Meterpoint2> meterMap = CacheContext.meterMap;
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
//            Map<String, Object> deleteparam = new HashMap<>();
//            deleteparam.put("recorddate", DateUtils.parseDate(day));
//            analysissubtablebottomService.removeByMap(deleteparam);

            QueryWrapper<Analysissubtablebottom> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("recorddate", DateUtils.parseDate(day)).like("wpid","GDC");
            analysissubtablebottomService.remove(queryWrapper);

            Map<String, Object> deleteparam = new HashMap<>();
            Date selDate = DateUtils.parseDate(day);
            deleteparam.put("recorddate", DateUtils.addDays(selDate,1));

            List<Meterpointvalue> meterpointvalues = meterpointvalueService.listByMap(deleteparam);
            List<Meterpointvalue> collect = meterpointvalues.stream().filter(i -> meterMap.get(i.getMeterid()) != null).filter(i -> meterMap.get(i.getMeterid()).getDescription() != null).collect(Collectors.toList());
            for (Windpowerstation station : CacheContext.stations) {
                if (station.getId().endsWith("FDC")) {
                    continue;
                }
                Analysismain mainValues = getMainValues(day, station.getId());
                collect.stream().filter(i -> meterMap.get(i.getMeterid()).getWindpowerstationid().equals(station.getId())).forEach(m -> {
                    Analysissubtablebottom analysissubtablebottom = new Analysissubtablebottom();
                    analysissubtablebottom.setTid(mainValues.getId());
                    analysissubtablebottom.setWpid(station.getId());
                    analysissubtablebottom.setMeterid(m.getMeterid());
                    analysissubtablebottom.setMetername(meterMap.get(m.getMeterid()).getDescription());
                    analysissubtablebottom.setRecorddate(DateUtils.parseDate(day));
                    analysissubtablebottom.setStopcode(m.getNow());
                    analysissubtablebottom.setStopcodemodify(m.getNow());
                    double dayvalue = DoubleUtils.GetResult(DoubleUtils.GetResult(m.getNow(),m.getDay(),"-"),meterMap.get(m.getMeterid()).getMagnification(),"*");
                    analysissubtablebottom.setDayvalue(dayvalue);
                    analysissubtablebottom.setDayvaluemodify(dayvalue);
                    analysissubtablebottomService.save(analysissubtablebottom);
                });
            }
        }
    }

    /**
     * 保存风电项目表
     *
     * @param beginDate
     * @param endDate
     */
//    public void saveWindProject(String beginDate, String endDate) throws Exception {
//        Map<String, List<Meterpoint2>> wpmeterMap = CacheContext.wpmeterMap;
//        List<String> days = getDays(beginDate, endDate);
//        for (String day : days) {
//            Map<String, Object> bdzmap = new HashMap<>();
//            bdzmap.put("recorddate", DateUtils.parseDate(day));
//            List<Analysissubtablebottom> currentDayBdz = analysissubtablebottomService.listByMap(bdzmap);
//
//
//            Map<String, Object> deleteparam = new HashMap<>();
//            deleteparam.put("recorddate", DateUtils.parseDate(day));
//            analysissubprojectwindcannotService.removeByMap(deleteparam);
//            analysissubprojectwindcanService.removeByMap(deleteparam);
//            for (Project project : CacheContext.projects) {
//
//                if (project.getWindpowerstationid().endsWith("GDC")) {
//                    continue;
//                }
//                List<Analysissubtablebottom> currentDay = currentDayBdz.stream().filter(i -> i.getWpid().equals(project.getWindpowerstationid())).collect(Collectors.toList());
//                List<String> fcswmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
//                        .filter(i -> (
//                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("正向有功")
//                        )).map(i -> i.getId()).collect(Collectors.toList());
//                double fcfdl = 0.0;
//                double fcswfdl = 0.0;
//                double fcgwfdl = 0.0;
//                double fczyb = 0.0;
//                if (fcswmeterids.size() == 1) {
//                    List<String> fcfdlmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
//                            .filter(i -> (
//                                    i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
//                            )).map(i -> i.getId()).collect(Collectors.toList());
//                    for (String meterid : fcfdlmeterids) {
//                        fcfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
//                    }
//                    for (String meterid : fcswmeterids) {
//                        fcswfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
//                    }
//                    List<String> fcgwmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
//                            .filter(i -> (
//                                    i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("反向有功")
//                            )).map(i -> i.getId()).collect(Collectors.toList());
//                    for (String meterid : fcgwmeterids) {
//                        fcgwfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
//                    }
//
//                } else {
//                    List<Meterpoint2> collect = wpmeterMap.get(project.getWindpowerstationid()).stream()
//                            .filter(i -> (
//                                    i.getProjectid().contains(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("正向有功")
//                            )).collect(Collectors.toList());
//                    List<Meterpoint2> gwdls = wpmeterMap.get(project.getWindpowerstationid()).stream()
//                            .filter(i -> (
//                                    i.getProjectid().contains(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("反向有功")
//                            )).collect(Collectors.toList());
//                    if (StringUtils.isNotEmpty(gwdls)) {
//                        fcgwfdl += currentDay.stream().filter(i -> i.getMeterid().equals(gwdls.get(0).getId())).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(gwdls.get(0).getId())).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
//
//                    }
//                    for (Meterpoint2 m : collect) {
//                        String[] projects = m.getProjectid().split("\\|");
//                        for (String projectid : projects) {
//                            List<Meterpoint2> fcfdls = wpmeterMap.get(project.getWindpowerstationid()).stream()
//                                    .filter(i -> (
//                                            i.getProjectid().equals(projectid) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
//                                    )).collect(Collectors.toList());
//                            for (Meterpoint2 meterpoint2 : fcfdls) {
//                                fcfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterpoint2.getId())).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterpoint2.getId())).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
//                            }
//                        }
//                        fcswfdl += currentDay.stream().filter(i -> i.getMeterid().equals(m.getId())).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(m.getId())).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
//                    }
//
//                }
//
//                List<String> fczybmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
//                        .filter(i -> (
//                                i.getMetersort().equals("主") && i.getMetertype().equals("站用变") && i.getDisplaytype().equals("正向有功")
//                        )).map(i -> i.getId()).collect(Collectors.toList());
//                for (String meterid : fczybmeterids) {
//                    fczyb += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
//                }
//
//
////                //-------------------------------------------------------------------------------------------------------------------------------------------------
////                List<String> fcswmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
////                        .filter(i -> (
////                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("正向有功")
////                        )).map(i -> i.getId()).collect(Collectors.toList());
////                double fcswfdl = 0.0;
////                for (String meterid : fcswmeterids) {
////                    fcswfdl += currentDay.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().isPresent()?currentDay.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue():0.0;
////                }
////                //-------------------------------------------------------------------------------------------------------------------------------------------------
////                List<String> fcgwmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
////                        .filter(i -> (
////                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("反向有功")
////                        )).map(i -> i.getId()).collect(Collectors.toList());
////                double fcgwfdl = 0.0;
////                for (String meterid : fcgwmeterids) {
////                    fcgwfdl += currentDay.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().isPresent()?currentDay.stream().filter(i->i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue():0.0;
////                }
//                //-------------------------------------------------------------------------------------------------------------------------------------------------
//
//
//                List<String> fdls = wpmeterMap.get(project.getWindpowerstationid()).stream()
//                        .filter(i -> (
//                                i.getProjectid().equals(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
//                        )).map(i -> i.getId()).collect(Collectors.toList());
//                double generatingcapacity = 0;
//                for (String meterid : fdls) {
//                    generatingcapacity += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
//                }
//
//
//                Analysissubprojectwindcan can = new Analysissubprojectwindcan();
//                Analysissubprojectwindcannot cannot = new Analysissubprojectwindcannot();
//                Analysismain mainValues = getMainValues(day, project.getWindpowerstationid());
//                can.setTid(mainValues.getId());
//                can.setProjectid(project.getId());
//                can.setWpid(project.getWindpowerstationid());
//                can.setRecorddate(DateUtils.parseDate(day));
//                can.setZjrl(project.getCapacity() / 10);
//
//
//                can.setFdl(generatingcapacity / 10000);
//                can.setSwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcswfdl) / 10000 : 0.0);
//                can.setGwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcgwfdl) / 10000 : 0.0);
//                can.setCydl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fczyb) / 10000 : 0.0);
//
//                QueryWrapper<Windpowerinfoday> queryWrapper = new QueryWrapper<>();
//                queryWrapper.eq("recorddate", DateUtils.parseDate(day));
//                queryWrapper.eq("foreignkeyid", project.getId());
//                Windpowerinfoday w = windpowerinfodayService.getOne(queryWrapper);
//                QueryWrapper<Windpowerinfoday3> wWrapper = new QueryWrapper<>();
//                wWrapper.eq("recorddate", DateUtils.parseDate(day));
//                wWrapper.eq("foreignkeyid", project.getId());
//                Windpowerinfoday3 one = windpowerinfoday3Service.getOne(wWrapper);
//                QueryWrapper<Shutdownevent2> shutparams = new QueryWrapper<>();
//                shutparams.eq("stoptime", DateUtils.parseDate(day));
//                shutparams.eq("projectid", project.getId());
//                //shutparams.put("statuscode",4);
//                List<Shutdownevent2> shut = shutdownevent2Service.list(shutparams);
//
//                Map<String, Object> inputparam = new HashMap<>();
//                inputparam.put("recorddate", DateUtils.parseDate(day));
//                inputparam.put("projectid", project.getId());
//                List<Inputoroutputspeedtotal> inputoroutputspeedtotals = inputoroutputspeedtotalService.listByMap(inputparam);
//                if (StringUtils.isNotEmpty(inputoroutputspeedtotals)) {
//                    OptionalDouble average = inputoroutputspeedtotals.stream().filter(i -> i.getDayinputsmall() != null).mapToDouble(Inputoroutputspeedtotal::getDayinputsmall).average();
//                    if (average.isPresent()) {
//                        can.setPjqrfs(average.getAsDouble());
//                    } else {
//                        can.setPjqrfs(0.0);
//                    }
//                }
//                if (StringUtils.isNotNull(w)) {
//
//                    can.setQpjfx(w.getSpeed());
//                    can.setFjgzsj(w.getFaulttime());
//                    can.setFjjxsj(w.getMaintaintime());
//                    can.setZdcl(w.getMaxpower());
//                    can.setZxcl(w.getMinpower());
//                } else {
//
//                    can.setQpjfx(0.0);
//                    can.setFjgzsj(0.0);
//                    can.setFjjxsj(0.0);
//                    can.setZdcl(0.0);
//                    can.setZxcl(0.0);
//                }
//
//                if (StringUtils.isNotNull(one)) {
//                    can.setFjgzdl(one.getDaynhgzssdl() / 10000);
//                    can.setXddl(one.getDaynhxdssdl() / 10000);
//                    can.setXnssdl(one.getDaynhqfdl() / 10000);
//                    can.setFjjxdl(one.getDaynhwhssdl() / 10000);
//                } else {
//                    can.setFjgzdl(0.0);
//                    can.setXddl(0.0);
//                    can.setXnssdl(0.0);
//                    can.setFjjxdl(0.0);
//                }
//                if (StringUtils.isNotEmpty(shut)) {
//                    can.setGzcs(Double.valueOf(shut.stream().filter(i -> i.getStatuscode() == 2).collect(Collectors.toList()).size()));
//                } else {
//                    can.setGzcs(0.0);
//                }
//                can.setFdlscada(can.getFdl() * 1.005);
//                can.setZhcydl(can.getFdl() + can.getGwdl() - can.getSwdl());
//                can.setZhcydll(can.getFdl() != 0 ? can.getZhcydl() / can.getFdl() * 100 : 0.0);
//                can.setZhcydlscada(can.getFdlscada() + can.getGwdl() - can.getSwdl());
//                can.setZhcydllscada(can.getFdlscada() != 0 ? can.getZhcydlscada() / can.getFdlscada() * 100 : 0.0);
//                can.setCydll(can.getFdl() != 0 ? can.getCydl() / can.getFdl() : 0.0);
//                can.setLyxs(can.getFdl() / can.getZjrl());
//                can.setLyxsscada(can.getFdlscada() / can.getZjrl());
//                can.setQfl((can.getXddl() + can.getFdl()) != 0 ? can.getXddl() / (can.getXddl() + can.getFdl()) * 100 : 0.0);
//                can.setLlfdl(can.getFdl() + can.getFjgzdl() + can.getFjjxdl() + can.getXddl());  //+can.getXnssdl()
//                can.setLlfdlscada(can.getFdlscada() + can.getFjgzdl() + can.getFjjxdl() + can.getXddl());//+can.getXnssdl()
//                can.setYjhfdl(getYjhfdl(project.getId(), day));
//                can.setDnaqts(getDnljts(day));
//                can.setCnsldwdl(0.0);
//                can.setCnsldwsj(0.0);
//                can.setCnsljxdl(0.0);
//                can.setCnsljxsj(0.0);
//                can.setCwsldwdl(0.0);
//                can.setCwsldwsj(0.0);
//                can.setCwsljxdl(0.0);
//                can.setCwsljxsj(0.0);
//                can.setZrzhdl(0.0);
//                can.setZrzhsj(0.0);
//                can.setXdsj(0.0);
//                can.setSyzgzdl(0.0);
//                can.setSyzgzsj(0.0);
//                can.setJdxlgzdl(0.0);
//                can.setJdxlgzsj(0.0);
//                can.setSyzjxdl(0.0);
//                can.setSyzjxsj(0.0);
//                can.setJdxljx(0.0);
//                can.setJdxljxsj(0.0);
//                can.setLjaqts(0.0);
//                can.setQw(0.0);
//                can.setTq("");
//                can.setFx("");
//                can.setEdpjfs(0.0);
//                can.setYpjkqmd(0.0);
//
//                CopyUtils.copy(can, cannot);
//                analysissubprojectwindcanService.save(can);
//                analysissubprojectwindcannotService.save(cannot);
//            }
//        }
//    }

    /**
     * 保存风电项目表
     *
     * @param beginDate
     * @param endDate
     */
    public void saveWindProject(String beginDate, String endDate) throws Exception {
        Map<String, List<Meterpoint2>> wpmeterMap = CacheContext.wpmeterMap;
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            Map<String, Object> bdzmap = new HashMap<>();
            bdzmap.put("recorddate", DateUtils.parseDate(day));
            List<Analysissubtablebottom> currentDayBdz = analysissubtablebottomService.listByMap(bdzmap);


            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("recorddate", DateUtils.parseDate(day));
            analysissubprojectwindcannotService.removeByMap(deleteparam);
            analysissubprojectwindcanService.removeByMap(deleteparam);
            for (Project project : CacheContext.projects) {

                if (project.getWindpowerstationid().endsWith("GDC")) {
                    continue;
                }
                List<Analysissubtablebottom> currentDay = currentDayBdz.stream().filter(i -> i.getWpid().equals(project.getWindpowerstationid())).collect(Collectors.toList());
                //算出发电量
                List<String> fdls = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getProjectid().equals(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double generatingcapacity = 0;
                for (String meterid : fdls) {
                    generatingcapacity += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }


                List<String> zfdls = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().contains("主") && i.getMetertype().contains("进线") && i.getUniformcode().contains("ZXYG")
                        )).map(i->i.getId()).collect(Collectors.toList());

                double zfdl = 0;
                for (String meterid : zfdls) {
                    zfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }
                //算上网电量和购网电量
                double swdl = 0;
                double gwdl = 0;
                Meterpoint2 fcswmeter = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("正向有功") && i.getProjectid().contains(project.getId())
                        )).findFirst().get();
                Meterpoint2 fcgwmeter = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("反向有功") && i.getProjectid().contains(project.getId())
                        )).findFirst().get();
                String[] lineids = fcswmeter.getLineid().split("\\|");
                Double fcfdl = Arrays.stream(lineids).map(lineid -> wpmeterMap.get(project.getWindpowerstationid()).stream().filter(j -> j.getMetersort().equals("主") && j.getMetertype().equals("进线") && j.getDisplaytype().equals("正向有功") && j.getLineid().equals(lineid)).findFirst().get()).mapToDouble(linemeterpoint2 -> currentDay.stream().filter(currentBdz -> currentBdz.getMeterid().equals(linemeterpoint2.getId())).findFirst().get().getDayvaluemodify()).sum();

                Double dayvaluesw = currentDay.stream().filter(currentBdz -> currentBdz.getMeterid().equals(fcswmeter.getId())).findFirst().get().getDayvaluemodify();
                Double dayvaluegw = currentDay.stream().filter(currentBdz -> currentBdz.getMeterid().equals(fcgwmeter.getId())).findFirst().get().getDayvaluemodify();
                swdl = fcfdl!=0?generatingcapacity/fcfdl*dayvaluesw:0;
                gwdl = fcfdl!=0?generatingcapacity/fcfdl*dayvaluegw:0;

                double fczyb = 0;
                List<String> fczybmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("站用变") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                for (String meterid : fczybmeterids) {
                    fczyb += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }



                Analysissubprojectwindcan can = new Analysissubprojectwindcan();
                Analysissubprojectwindcannot cannot = new Analysissubprojectwindcannot();
                Analysismain mainValues = getMainValues(day, project.getWindpowerstationid());
                can.setTid(mainValues.getId());
                can.setProjectid(project.getId());
                can.setWpid(project.getWindpowerstationid());
                can.setRecorddate(DateUtils.parseDate(day));
                can.setZjrl(project.getCapacity() / 10);


                can.setFdl(generatingcapacity / 10000);
                if (project.getId().equals("SBQ04_GC")){
                    List<Analysissubstationpv> analysissubstationpvs = analysissubstationpvService.listByMap(bdzmap);
                    Double hzj_swdl = analysissubstationpvs.stream().filter(i -> i.getWpid().equals("HZJ_GDC")).findFirst().get().getFdl();
                    Double wgejx = currentDayBdz.stream().filter(i -> i.getMeterid().equals(WGEJX)).findFirst().get().getDayvaluemodify();
                    can.setSwdl((swdl-wgejx)/10000-hzj_swdl);
                }else {
                    can.setSwdl(swdl / 10000);
                }
                can.setGwdl(gwdl/ 10000);
                can.setCydl(fcfdl != 0.0 ? (generatingcapacity / zfdl * fczyb) / 10000 : 0.0);

                QueryWrapper<Windpowerinfoday> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("recorddate", DateUtils.parseDate(day));
                queryWrapper.eq("foreignkeyid", project.getId());
                Windpowerinfoday w = windpowerinfodayService.getOne(queryWrapper);
                QueryWrapper<Windpowerinfoday3> wWrapper = new QueryWrapper<>();
                wWrapper.eq("recorddate", DateUtils.parseDate(day));
                wWrapper.eq("foreignkeyid", project.getId());
                Windpowerinfoday3 one = windpowerinfoday3Service.getOne(wWrapper);
                QueryWrapper<Shutdownevent2> shutparams = new QueryWrapper<>();
                shutparams.eq("stoptime", DateUtils.parseDate(day));
                shutparams.eq("projectid", project.getId());
                //shutparams.put("statuscode",4);
                List<Shutdownevent2> shut = shutdownevent2Service.list(shutparams);

                Map<String, Object> inputparam = new HashMap<>();
                inputparam.put("recorddate", DateUtils.parseDate(day));
                inputparam.put("projectid", project.getId());
                List<Inputoroutputspeedtotal> inputoroutputspeedtotals = inputoroutputspeedtotalService.listByMap(inputparam);
                if (StringUtils.isNotEmpty(inputoroutputspeedtotals)) {
                    OptionalDouble average = inputoroutputspeedtotals.stream().filter(i -> i.getDayinputsmall() != null).mapToDouble(Inputoroutputspeedtotal::getDayinputsmall).average();
                    if (average.isPresent()) {
                        can.setPjqrfs(average.getAsDouble());
                    } else {
                        can.setPjqrfs(0.0);
                    }
                }
                if (StringUtils.isNotNull(w)) {
                    //性能不好降风速
                    Double speed = w.getSpeed();
                    if (speed<5){
                        can.setQpjfx(speed);
                    }else if(speed<6){
                        can.setQpjfx(speed-0.2);
                    }else if(speed<7){
                        can.setQpjfx(speed-0.3);
                    }else if(speed<8){
                        can.setQpjfx(speed-0.4);
                    }else if(speed<9){
                        can.setQpjfx(speed-0.5);
                    }else if(speed<10){
                        can.setQpjfx(speed-0.6);
                    }else {
                        can.setQpjfx(speed-0.8);
                    }
//                    can.setQpjfx(w.getSpeed());
                    can.setFjgzsj(w.getFaulttime());
                    can.setFjjxsj(w.getMaintaintime());
                    can.setZdcl(w.getMaxpower());
                    can.setZxcl(w.getMinpower());
                } else {

                    can.setQpjfx(0.0);
                    can.setFjgzsj(0.0);
                    can.setFjjxsj(0.0);
                    can.setZdcl(0.0);
                    can.setZxcl(0.0);
                }

                if (StringUtils.isNotNull(one)) {
                    can.setFjgzdl(one.getDaynhgzssdl() / 10000);
                    can.setXddl(one.getDaynhxdssdl() / 10000);
                    can.setXnssdl(one.getDaynhqfdl() / 10000);
                    can.setFjjxdl(one.getDaynhwhssdl() / 10000);
                } else {
                    can.setFjgzdl(0.0);
                    can.setXddl(0.0);
                    can.setXnssdl(0.0);
                    can.setFjjxdl(0.0);
                }
                if (StringUtils.isNotEmpty(shut)) {
                    can.setGzcs(Double.valueOf(shut.stream().filter(i -> i.getStatuscode() == 2).collect(Collectors.toList()).size()));
                } else {
                    can.setGzcs(0.0);
                }
                can.setFdlscada(can.getFdl() * 1.005);
                can.setZhcydl(can.getFdl() + can.getGwdl() - can.getSwdl());
                can.setZhcydll(can.getFdl() != 0 ? can.getZhcydl() / can.getFdl() * 100 : 0.0);
                can.setZhcydlscada(can.getFdlscada() + can.getGwdl() - can.getSwdl());
                can.setZhcydllscada(can.getFdlscada() != 0 ? can.getZhcydlscada() / can.getFdlscada() * 100 : 0.0);
                can.setCydll(can.getFdl() != 0 ? can.getCydl() / can.getFdl() : 0.0);
                can.setLyxs(can.getFdl() / can.getZjrl());
                can.setLyxsscada(can.getFdlscada() / can.getZjrl());
                can.setQfl((can.getXddl() + can.getFdl()) != 0 ? can.getXddl() / (can.getXddl() + can.getFdl()) * 100 : 0.0);
                can.setLlfdl(can.getFdl() + can.getFjgzdl() + can.getFjjxdl() + can.getXddl());  //+can.getXnssdl()
                can.setLlfdlscada(can.getFdlscada() + can.getFjgzdl() + can.getFjjxdl() + can.getXddl());//+can.getXnssdl()
                can.setYjhfdl(getYjhfdl(project.getId(), day));
                can.setDnaqts(getDnljts(day));
                can.setCnsldwdl(0.0);
                can.setCnsldwsj(0.0);
                can.setCnsljxdl(0.0);
                can.setCnsljxsj(0.0);
                can.setCwsldwdl(0.0);
                can.setCwsldwsj(0.0);
                can.setCwsljxdl(0.0);
                can.setCwsljxsj(0.0);
                can.setZrzhdl(0.0);
                can.setZrzhsj(0.0);
                can.setXdsj(0.0);
                can.setSyzgzdl(0.0);
                can.setSyzgzsj(0.0);
                can.setJdxlgzdl(0.0);
                can.setJdxlgzsj(0.0);
                can.setSyzjxdl(0.0);
                can.setSyzjxsj(0.0);
                can.setJdxljx(0.0);
                can.setJdxljxsj(0.0);
                can.setLjaqts(0.0);
                can.setQw(0.0);
                can.setTq("");
                can.setFx("");
                can.setEdpjfs(0.0);
                can.setYpjkqmd(0.0);

                CopyUtils.copy(can, cannot);
                analysissubprojectwindcanService.save(can);
                analysissubprojectwindcannotService.save(cannot);
            }
        }
    }



    /**
     * 保存光伏项目表
     *
     * @param beginDate
     * @param endDate
     */
    public void savePvProject(String beginDate, String endDate) throws Exception {
        Map<String, List<Meterpoint2>> wpmeterMap = CacheContext.wpmeterMap;
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            Map<String, Object> bdzmap = new HashMap<>();
            bdzmap.put("recorddate", DateUtils.parseDate(day));
            List<Analysissubtablebottom> currentDayBdz = analysissubtablebottomService.listByMap(bdzmap);
            List<Analysissubtablebottom1> currentDayBdz1 = analysissubtablebottom1Service.listByMap(bdzmap);


            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("recorddate", DateUtils.parseDate(day));
            analysissubprojectpvcannotService.removeByMap(deleteparam);
            analysissubprojectpvcanService.removeByMap(deleteparam);
            for (Project project : CacheContext.projects) {
                if (project.getWindpowerstationid().endsWith("FDC") || project.getWindpowerstationid().equals("MCH_GDC")) {
                    continue;
                }
                List<Analysissubtablebottom> currentDay = currentDayBdz.stream().filter(i -> i.getWpid().equals(project.getWindpowerstationid())).collect(Collectors.toList());
                List<String> fcfdlmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double fcfdl = 0.0;
                for (String meterid : fcfdlmeterids) {
                    fcfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }


                //-------------------------------------------------------------------------------------------------------------------------------------------------
                List<String> fcswmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double fcswfdl = 0.0;
                for (String meterid : fcswmeterids) {
                    fcswfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                List<String> fcgwmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("反向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double fcgwfdl = 0.0;
                for (String meterid : fcgwmeterids) {
                    fcgwfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                List<String> fczybmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("站用变") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double fczyb = 0.0;
                for (String meterid : fczybmeterids) {
                    fczyb += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }

                List<String> fdls = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getProjectid().equals(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double generatingcapacity = 0;
                for (String meterid : fdls) {
                    generatingcapacity += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }

                Analysissubprojectpvcan can = new Analysissubprojectpvcan();
                Analysissubprojectpvcannot cannot = new Analysissubprojectpvcannot();
                Analysismain mainValues = getMainValues(day, project.getWindpowerstationid());
                can.setTid(mainValues.getId());
                can.setProjectid(project.getId());
                can.setWpid(project.getWindpowerstationid());
                can.setRecorddate(DateUtils.parseDate(day));

                can.setFdl(generatingcapacity / 10000);
                if (project.getWindpowerstationid().equals("HZJ_GDC")){
                    //首风五乙线
                    double sfwyx = currentDayBdz1.stream().filter(i -> i.getMeterid().equals(SFWYX)).findFirst().get().getDayvaluemodify();
                    //#4主变高压侧
                    double jszbgyc = currentDayBdz1.stream().filter(i -> i.getMeterid().equals(SHZBGYC)).findFirst().get().getDayvaluemodify();
                    //(sfwyx*fcswfdl/(jszbgyc+fcswfdl))/10000
                    can.setSwdl((jszbgyc+fcswfdl)!=0?(sfwyx*fcswfdl/(jszbgyc+fcswfdl))/10000:0);
                }else {
                    can.setSwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcswfdl) / 10000 : 0.0);
                }

                can.setGwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcgwfdl) / 10000 : 0.0);
                can.setFdcydl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fczyb) / 10000 : 0.0);

                QueryWrapper<Windpowerinfoday> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("recorddate", DateUtils.parseDate(day));
                queryWrapper.eq("foreignkeyid", project.getId());
                Windpowerinfoday w = windpowerinfodayService.getOne(queryWrapper);
                QueryWrapper<Windpowerinfoday3> wWrapper = new QueryWrapper<>();
                wWrapper.eq("recorddate", DateUtils.parseDate(day));
                wWrapper.eq("foreignkeyid", project.getId());
                Windpowerinfoday3 one = windpowerinfoday3Service.getOne(wWrapper);
                QueryWrapper<Shutdownevent2> shutparams = new QueryWrapper<>();
                shutparams.eq("stoptime", DateUtils.parseDate(day));
                shutparams.eq("projectid", project.getId());
                //shutparams.put("statuscode",4);
                List<Shutdownevent2> shut = shutdownevent2Service.list(shutparams);


                if (StringUtils.isNotNull(w)) {

                    can.setZdcl(w.getMaxpower());
                    can.setZxcl(w.getMinpower());
                    can.setGzsj(w.getFaulttime());
                    can.setJxsj(w.getMaintaintime());
                    can.setZdcl(w.getMaxpower());
                    can.setZxcl(w.getMinpower());
                } else {

                    can.setZdcl(0.0);
                    can.setZxcl(0.0);
                    can.setGzsj(0.0);
                    can.setJxsj(0.0);
                    can.setZdcl(0.0);
                    can.setZxcl(0.0);
                }
                if (StringUtils.isNotNull(one)) {
                    can.setXddl(one.getDaynhxdssdl());
                    can.setGzdl(one.getDaynhgzssdl());
                    can.setJxdl(one.getDaynhwhssdl());

                } else {
                    can.setXddl(0.0);
                    can.setGzdl(0.0);
                    can.setJxdl(0.0);
                }
                can.setLlfdl(can.getFdl() + can.getXddl() + can.getGzdl() + can.getJxdl());

                can.setFdcydll(can.getFdl() != 0.0 ? can.getFdcydl() / can.getFdl() * 100 : 0.0);
                can.setZhcydl(can.getFdl() + can.getGwdl() - can.getSwdl());
                can.setZhcydll(can.getFdl() != 0 ? can.getZhcydl() / can.getFdl() * 100 : 0.0);
                can.setLyxs(can.getFdl() / project.getCapacity() * 10);
                can.setRzxs(0.0);
                can.setTq("");
                can.setWd(0.0);
                can.setRljfs(0.0);
                can.setXdsj(0.0);
                can.setRzgwd(0.0);
                can.setLxaqts(0.0);
                can.setNljaqts(0.0);
                can.setYjhfdl(getYjhfdl(project.getId(), day));
                can.setRzdfsqd(0.0);
                can.setLjfsl(0.0);
                CopyUtils.copy(can, cannot);
                analysissubprojectpvcanService.save(can);
                analysissubprojectpvcannotService.save(cannot);
            }
        }
    }

    /**
     * 保存海子井项目表
     *
     * @param beginDate
     * @param endDate
     */
    public void saveHzjProject(String beginDate, String endDate) throws Exception {
        Map<String, List<Meterpoint2>> wpmeterMap = CacheContext.wpmeterMap;
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            Map<String, Object> bdzmap = new HashMap<>();
            bdzmap.put("recorddate", DateUtils.parseDate(day));
            List<Analysissubtablebottom> currentDayBdz = analysissubtablebottomService.listByMap(bdzmap);


            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("recorddate", DateUtils.parseDate(day));
            analysissubprojectpvcannotService.removeByMap(deleteparam);
            analysissubprojectpvcanService.removeByMap(deleteparam);
            for (Project project : CacheContext.projects) {
                if (!project.getWindpowerstationid().equals("HZJ_GDC")) {
                    continue;
                }
                List<Analysissubtablebottom> currentDay = currentDayBdz.stream().filter(i -> i.getWpid().equals(project.getWindpowerstationid())).collect(Collectors.toList());
                List<String> fcfdlmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double fcfdl = 0.0;
                for (String meterid : fcfdlmeterids) {
                    fcfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }


                //-------------------------------------------------------------------------------------------------------------------------------------------------
                List<String> fcswmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double fcswfdl = 0.0;
                for (String meterid : fcswmeterids) {
                    fcswfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                List<String> fcgwmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("反向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double fcgwfdl = 0.0;
                for (String meterid : fcgwmeterids) {
                    fcgwfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }
                //-------------------------------------------------------------------------------------------------------------------------------------------------
                List<String> fczybmeterids = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getMetersort().equals("主") && i.getMetertype().equals("站用变") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double fczyb = 0.0;
                for (String meterid : fczybmeterids) {
                    fczyb += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }

                List<String> fdls = wpmeterMap.get(project.getWindpowerstationid()).stream()
                        .filter(i -> (
                                i.getProjectid().equals(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                double generatingcapacity = 0;
                for (String meterid : fdls) {
                    generatingcapacity += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }

                Analysissubprojectpvcan can = new Analysissubprojectpvcan();
                Analysissubprojectpvcannot cannot = new Analysissubprojectpvcannot();
                Analysismain mainValues = getMainValues(day, project.getWindpowerstationid());
                can.setTid(mainValues.getId());
                can.setProjectid(project.getId());
                can.setWpid(project.getWindpowerstationid());
                can.setRecorddate(DateUtils.parseDate(day));

                can.setFdl(generatingcapacity / 10000);

//                can.setSwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcswfdl) / 10000 : 0.0);
                //首风五乙线
                double sfwyx = currentDayBdz.stream().filter(i -> i.getMeterid().equals("SBQDJL.NX_GD_SBQF_DD_P1_L1_001_ZXYG109")).findFirst().get().getDayvaluemodify();
                //#4主变高压侧
                double jszbgyc = currentDayBdz.stream().filter(i -> i.getMeterid().equals("SBQDJL.NX_GD_SBQF_DD_P1_L1_001_ZXYG117")).findFirst().get().getDayvaluemodify();
                //(sfwyx*fcswfdl/(jszbgyc+fcswfdl))/10000
                can.setSwdl((jszbgyc+fcswfdl)!=0?(sfwyx*fcswfdl/(jszbgyc+fcswfdl))/10000:0);
                can.setGwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcgwfdl) / 10000 : 0.0);
                can.setFdcydl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fczyb) / 10000 : 0.0);

                QueryWrapper<Windpowerinfoday> queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("recorddate", DateUtils.parseDate(day));
                queryWrapper.eq("foreignkeyid", project.getId());
                Windpowerinfoday w = windpowerinfodayService.getOne(queryWrapper);
                QueryWrapper<Windpowerinfoday3> wWrapper = new QueryWrapper<>();
                wWrapper.eq("recorddate", DateUtils.parseDate(day));
                wWrapper.eq("foreignkeyid", project.getId());
                Windpowerinfoday3 one = windpowerinfoday3Service.getOne(wWrapper);
                QueryWrapper<Shutdownevent2> shutparams = new QueryWrapper<>();
                shutparams.eq("stoptime", DateUtils.parseDate(day));
                shutparams.eq("projectid", project.getId());
                //shutparams.put("statuscode",4);
                List<Shutdownevent2> shut = shutdownevent2Service.list(shutparams);


                if (StringUtils.isNotNull(w)) {

                    can.setZdcl(w.getMaxpower());
                    can.setZxcl(w.getMinpower());
                    can.setGzsj(w.getFaulttime());
                    can.setJxsj(w.getMaintaintime());
                    can.setZdcl(w.getMaxpower());
                    can.setZxcl(w.getMinpower());
                } else {

                    can.setZdcl(0.0);
                    can.setZxcl(0.0);
                    can.setGzsj(0.0);
                    can.setJxsj(0.0);
                    can.setZdcl(0.0);
                    can.setZxcl(0.0);
                }
                if (StringUtils.isNotNull(one)) {
                    can.setXddl(one.getDaynhxdssdl());
                    can.setGzdl(one.getDaynhgzssdl());
                    can.setJxdl(one.getDaynhwhssdl());

                } else {
                    can.setXddl(0.0);
                    can.setGzdl(0.0);
                    can.setJxdl(0.0);
                }
                can.setLlfdl(can.getFdl() + can.getXddl() + can.getGzdl() + can.getJxdl());

                can.setFdcydll(can.getFdl() != 0.0 ? can.getFdcydl() / can.getFdl() * 100 : 0.0);
                can.setZhcydl(can.getFdl() + can.getGwdl() - can.getSwdl());
                can.setZhcydll(can.getFdl() != 0 ? can.getZhcydl() / can.getFdl() * 100 : 0.0);
                can.setLyxs(can.getFdl() / project.getCapacity() * 10);
                can.setRzxs(0.0);
                can.setTq("");
                can.setWd(0.0);
                can.setRljfs(0.0);
                can.setXdsj(0.0);
                can.setRzgwd(0.0);
                can.setLxaqts(0.0);
                can.setNljaqts(0.0);
                can.setYjhfdl(getYjhfdl(project.getId(), day));
                can.setRzdfsqd(0.0);
                can.setLjfsl(0.0);
                CopyUtils.copy(can, cannot);
                analysissubprojectpvcanService.save(can);
                analysissubprojectpvcannotService.save(cannot);
            }
        }
    }

    /**
     * 保存风电场站表
     *
     * @param beginDate
     * @param endDate
     */
    public void saveWindStation(String beginDate, String endDate) {
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("recorddate", DateUtils.parseDate(day));
            analysissubstationwindService.removeByMap(deleteparam);
            for (Windpowerstation station : CacheContext.stations) {
                if (station.getId().endsWith("GDC")) {
                    continue;
                }
                Analysismain mainValues = getMainValues(day, station.getId());
                Map<String, Object> params = new HashMap<>();
                params.put("tid", mainValues.getId());
                List<Analysissubprojectwindcan> prodatas = analysissubprojectwindcanService.listByMap(params);

                Analysissubstationwind analysis = new Analysissubstationwind();
                analysis.setTid(mainValues.getId());
                analysis.setWpid(station.getId());
                analysis.setRecorddate(DateUtils.parseDate(day));
                analysis.setZjrl(station.getCapacity() / 10);

                analysis.setFdlscada(prodatas.stream().map(Analysissubprojectwindcan::getFdlscada).reduce(DoubleUtils::sum).get());
                analysis.setFdl(prodatas.stream().map(Analysissubprojectwindcan::getFdl).reduce(DoubleUtils::sum).get());
                analysis.setSwdl(prodatas.stream().map(Analysissubprojectwindcan::getSwdl).reduce(DoubleUtils::sum).get());
                analysis.setGwdl(prodatas.stream().map(Analysissubprojectwindcan::getGwdl).reduce(DoubleUtils::sum).get());
                analysis.setZhcydl(analysis.getFdl() + analysis.getGwdl() - analysis.getSwdl());
                analysis.setZhcydll(analysis.getFdl() != 0.0 ? analysis.getZhcydl() / analysis.getFdl() * 100 : 0.0);
                analysis.setZhcydlscada(analysis.getFdlscada() + analysis.getGwdl() - analysis.getSwdl());
                analysis.setZhcydllscada(analysis.getFdlscada() != 0.0 ? analysis.getZhcydlscada() / analysis.getFdlscada() * 100 : 0.0);
                analysis.setCydl(prodatas.stream().map(Analysissubprojectwindcan::getCydl).reduce(DoubleUtils::sum).get());
                analysis.setCydll(analysis.getFdl() != 0.0 ? analysis.getCydl() / analysis.getFdl() * 100 : 0.0);
                analysis.setLyxs(analysis.getFdl() / analysis.getZjrl());
                analysis.setLyxsscada(analysis.getFdlscada() / analysis.getZjrl());
                analysis.setCnsldwdl(prodatas.stream().map(Analysissubprojectwindcan::getCnsldwdl).reduce(DoubleUtils::sum).get());
                analysis.setCnsldwsj(prodatas.stream().map(Analysissubprojectwindcan::getCnsldwsj).reduce(DoubleUtils::sum).get());
                analysis.setCnsljxdl(prodatas.stream().map(Analysissubprojectwindcan::getCnsljxdl).reduce(DoubleUtils::sum).get());
                analysis.setCnsljxsj(prodatas.stream().map(Analysissubprojectwindcan::getCnsljxsj).reduce(DoubleUtils::sum).get());
                analysis.setCwsldwdl(prodatas.stream().map(Analysissubprojectwindcan::getCwsldwdl).reduce(DoubleUtils::sum).get());
                analysis.setCwsldwsj(prodatas.stream().map(Analysissubprojectwindcan::getCwsldwsj).reduce(DoubleUtils::sum).get());
                analysis.setCwsljxdl(prodatas.stream().map(Analysissubprojectwindcan::getCwsljxdl).reduce(DoubleUtils::sum).get());
                analysis.setCwsljxsj(prodatas.stream().map(Analysissubprojectwindcan::getCwsljxsj).reduce(DoubleUtils::sum).get());

                analysis.setZrzhdl(prodatas.stream().map(Analysissubprojectwindcan::getZrzhdl).reduce(DoubleUtils::sum).get());
                analysis.setZrzhsj(prodatas.stream().map(Analysissubprojectwindcan::getZrzhsj).reduce(DoubleUtils::sum).get());
                analysis.setXddl(prodatas.stream().map(Analysissubprojectwindcan::getXddl).reduce(DoubleUtils::sum).get());
                analysis.setXdsj(prodatas.stream().map(Analysissubprojectwindcan::getXdsj).reduce(DoubleUtils::sum).get());
                analysis.setFjgzdl(prodatas.stream().map(Analysissubprojectwindcan::getFjgzdl).reduce(DoubleUtils::sum).get());
                analysis.setFjgzsj(prodatas.stream().map(Analysissubprojectwindcan::getFjgzsj).reduce(DoubleUtils::sum).get());
                analysis.setXnssdl(prodatas.stream().map(Analysissubprojectwindcan::getXnssdl).reduce(DoubleUtils::sum).get());

                analysis.setSyzgzdl(prodatas.stream().map(Analysissubprojectwindcan::getSyzgzdl).reduce(DoubleUtils::sum).get());
                analysis.setSyzgzsj(prodatas.stream().map(Analysissubprojectwindcan::getSyzgzsj).reduce(DoubleUtils::sum).get());
                analysis.setJdxlgzdl(prodatas.stream().map(Analysissubprojectwindcan::getJdxlgzdl).reduce(DoubleUtils::sum).get());
                analysis.setJdxlgzsj(prodatas.stream().map(Analysissubprojectwindcan::getJdxlgzsj).reduce(DoubleUtils::sum).get());

                analysis.setFjjxdl(prodatas.stream().map(Analysissubprojectwindcan::getFjjxdl).reduce(DoubleUtils::sum).get());
                analysis.setFjjxsj(prodatas.stream().map(Analysissubprojectwindcan::getFjjxsj).reduce(DoubleUtils::sum).get());

                analysis.setSyzjxdl(prodatas.stream().map(Analysissubprojectwindcan::getSyzjxdl).reduce(DoubleUtils::sum).get());
                analysis.setSyzjxsj(prodatas.stream().map(Analysissubprojectwindcan::getSyzjxsj).reduce(DoubleUtils::sum).get());
                analysis.setJdxljx(prodatas.stream().map(Analysissubprojectwindcan::getJdxljx).reduce(DoubleUtils::sum).get());
                analysis.setJdxljxsj(prodatas.stream().map(Analysissubprojectwindcan::getJdxljxsj).reduce(DoubleUtils::sum).get());

                analysis.setGzcs(prodatas.stream().map(Analysissubprojectwindcan::getGzcs).reduce(DoubleUtils::sum).get());
                analysis.setQfl((analysis.getFdl() + analysis.getXddl()) != 0.0 ? analysis.getXddl() / (analysis.getFdl() + analysis.getXddl()) * 100 : 0.0);
                analysis.setQpjfx(prodatas.stream().map(Analysissubprojectwindcan::getQpjfx).reduce(DoubleUtils::ave).get());
                analysis.setTq(prodatas.get(0).getTq());
                analysis.setLlfdl(analysis.getFdl() + analysis.getFjgzdl() + analysis.getFjjxdl() + analysis.getXddl());
                analysis.setLlfdlscada(analysis.getFdlscada() + analysis.getFjgzdl() + analysis.getFjjxdl() + analysis.getXddl());
                analysis.setDnaqts(getDnljts(day));
                analysis.setLjaqts(prodatas.stream().map(Analysissubprojectwindcan::getLjaqts).reduce(DoubleUtils::max).get());
                analysis.setZdcl(prodatas.stream().map(Analysissubprojectwindcan::getZdcl).reduce(DoubleUtils::max).get());
                analysis.setZxcl(prodatas.stream().map(Analysissubprojectwindcan::getZxcl).reduce(DoubleUtils::min).get());
                analysis.setFx(prodatas.get(0).getFx());
                analysis.setYjhfdl(prodatas.stream().map(Analysissubprojectwindcan::getYjhfdl).reduce(DoubleUtils::sum).get());
                analysis.setPjqrfs(prodatas.stream().map(Analysissubprojectwindcan::getPjqrfs).reduce(DoubleUtils::ave).get());
                analysis.setEdpjfs(prodatas.stream().map(Analysissubprojectwindcan::getEdpjfs).reduce(DoubleUtils::ave).get());
                analysis.setYpjkqmd(prodatas.stream().map(Analysissubprojectwindcan::getYpjkqmd).reduce(DoubleUtils::ave).get());
                analysissubstationwindService.save(analysis);
            }
        }
    }

    /**
     * 保存光伏场站表
     *
     * @param beginDate
     * @param endDate
     */
    public void savePvStation(String beginDate, String endDate) {
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("recorddate", DateUtils.parseDate(day));
            analysissubstationpvService.removeByMap(deleteparam);
            for (Windpowerstation station : CacheContext.stations) {
                if (station.getId().endsWith("FDC") || station.getId().equals("MCH_GDC") ) {
                    continue;
                }
                Analysismain mainValues = getMainValues(day, station.getId());
                Map<String, Object> params = new HashMap<>();
                params.put("tid", mainValues.getId());
                List<Analysissubprojectpvcan> prodatas = analysissubprojectpvcanService.listByMap(params);

                Analysissubstationpv analysis = new Analysissubstationpv();
                analysis.setTid(mainValues.getId());
                analysis.setWpid(station.getId());
                analysis.setRecorddate(DateUtils.parseDate(day));

                analysis.setFdl(prodatas.stream().map(Analysissubprojectpvcan::getFdl).reduce(DoubleUtils::sum).get());
                analysis.setSwdl(prodatas.stream().map(Analysissubprojectpvcan::getSwdl).reduce(DoubleUtils::sum).get());
                analysis.setGwdl(prodatas.stream().map(Analysissubprojectpvcan::getGwdl).reduce(DoubleUtils::sum).get());
                analysis.setZhcydl(analysis.getFdl() + analysis.getGwdl() - analysis.getSwdl());
                analysis.setZhcydll(analysis.getFdl() != 0.0 ? analysis.getZhcydl() / analysis.getFdl() * 100 : 0.0);
                analysis.setFdcydl(prodatas.stream().map(Analysissubprojectpvcan::getFdcydl).reduce(DoubleUtils::sum).get());
                analysis.setFdcydll(analysis.getFdl() != 0.0 ? analysis.getFdcydl() / analysis.getFdl() * 100 : 0.0);
                analysis.setLyxs(analysis.getFdl() / station.getCapacity() * 10);
                analysis.setRzdfsqd(prodatas.stream().map(Analysissubprojectpvcan::getRzdfsqd).reduce(DoubleUtils::max).get());
                analysis.setLjfsl(prodatas.stream().map(Analysissubprojectpvcan::getLjfsl).reduce(DoubleUtils::sum).get());


                analysis.setXddl(prodatas.stream().map(Analysissubprojectpvcan::getXddl).reduce(DoubleUtils::sum).get());
                analysis.setXdsj(prodatas.stream().map(Analysissubprojectpvcan::getXdsj).reduce(DoubleUtils::sum).get());

                analysis.setGzdl(prodatas.stream().map(Analysissubprojectpvcan::getGzdl).reduce(DoubleUtils::sum).get());
                analysis.setGzsj(prodatas.stream().map(Analysissubprojectpvcan::getGzsj).reduce(DoubleUtils::sum).get());

                analysis.setJxdl(prodatas.stream().map(Analysissubprojectpvcan::getJxdl).reduce(DoubleUtils::sum).get());
                analysis.setJxsj(prodatas.stream().map(Analysissubprojectpvcan::getJxsj).reduce(DoubleUtils::sum).get());

                analysis.setRzxs(prodatas.stream().map(Analysissubprojectpvcan::getRzxs).reduce(DoubleUtils::ave).get());
                analysis.setTq(prodatas.get(0).getTq());
                analysis.setWd(prodatas.stream().map(Analysissubprojectpvcan::getWd).reduce(DoubleUtils::ave).get());
                analysis.setRljfs(prodatas.stream().map(Analysissubprojectpvcan::getRljfs).reduce(DoubleUtils::sum).get());
                analysis.setZdcl(prodatas.stream().map(Analysissubprojectpvcan::getZdcl).reduce(DoubleUtils::max).get());
                analysis.setZxcl(prodatas.stream().map(Analysissubprojectpvcan::getZxcl).reduce(DoubleUtils::min).get());
                analysis.setLlfdl(analysis.getFdl() + analysis.getGzdl() + analysis.getJxdl() + analysis.getXddl());
                analysis.setRzgwd(prodatas.stream().map(Analysissubprojectpvcan::getRzgwd).reduce(DoubleUtils::max).get());
                analysis.setLxaqts(prodatas.stream().map(Analysissubprojectpvcan::getLxaqts).reduce(DoubleUtils::max).get());
                analysis.setNljaqts(prodatas.stream().map(Analysissubprojectpvcan::getNljaqts).reduce(DoubleUtils::max).get());
                analysis.setYjhfdl(prodatas.stream().map(Analysissubprojectpvcan::getYjhfdl).reduce(DoubleUtils::sum).get());
                analysissubstationpvService.save(analysis);
            }
        }
    }
    /**
     * 保存海子井场站表
     *
     * @param beginDate
     * @param endDate
     */
    public void saveHzjStation(String beginDate, String endDate) {
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("recorddate", DateUtils.parseDate(day));
            analysissubstationpvService.removeByMap(deleteparam);
            for (Windpowerstation station : CacheContext.stations) {
                if (!station.getId().equals("HZJ_GDC")) {
                    continue;
                }
                Analysismain mainValues = getMainValues(day, station.getId());
                Map<String, Object> params = new HashMap<>();
                params.put("tid", mainValues.getId());
                List<Analysissubprojectpvcan> prodatas = analysissubprojectpvcanService.listByMap(params);

                Analysissubstationpv analysis = new Analysissubstationpv();
                analysis.setTid(mainValues.getId());
                analysis.setWpid(station.getId());
                analysis.setRecorddate(DateUtils.parseDate(day));

                analysis.setFdl(prodatas.stream().map(Analysissubprojectpvcan::getFdl).reduce(DoubleUtils::sum).get());
                analysis.setSwdl(prodatas.stream().map(Analysissubprojectpvcan::getSwdl).reduce(DoubleUtils::sum).get());
                analysis.setGwdl(prodatas.stream().map(Analysissubprojectpvcan::getGwdl).reduce(DoubleUtils::sum).get());
                analysis.setZhcydl(analysis.getFdl() + analysis.getGwdl() - analysis.getSwdl());
                analysis.setZhcydll(analysis.getFdl() != 0.0 ? analysis.getZhcydl() / analysis.getFdl() * 100 : 0.0);
                analysis.setFdcydl(prodatas.stream().map(Analysissubprojectpvcan::getFdcydl).reduce(DoubleUtils::sum).get());
                analysis.setFdcydll(analysis.getFdl() != 0.0 ? analysis.getFdcydl() / analysis.getFdl() * 100 : 0.0);
                analysis.setLyxs(analysis.getFdl() / station.getCapacity() * 10);
                analysis.setRzdfsqd(prodatas.stream().map(Analysissubprojectpvcan::getRzdfsqd).reduce(DoubleUtils::max).get());
                analysis.setLjfsl(prodatas.stream().map(Analysissubprojectpvcan::getLjfsl).reduce(DoubleUtils::sum).get());


                analysis.setXddl(prodatas.stream().map(Analysissubprojectpvcan::getXddl).reduce(DoubleUtils::sum).get());
                analysis.setXdsj(prodatas.stream().map(Analysissubprojectpvcan::getXdsj).reduce(DoubleUtils::sum).get());

                analysis.setGzdl(prodatas.stream().map(Analysissubprojectpvcan::getGzdl).reduce(DoubleUtils::sum).get());
                analysis.setGzsj(prodatas.stream().map(Analysissubprojectpvcan::getGzsj).reduce(DoubleUtils::sum).get());

                analysis.setJxdl(prodatas.stream().map(Analysissubprojectpvcan::getJxdl).reduce(DoubleUtils::sum).get());
                analysis.setJxsj(prodatas.stream().map(Analysissubprojectpvcan::getJxsj).reduce(DoubleUtils::sum).get());

                analysis.setRzxs(prodatas.stream().map(Analysissubprojectpvcan::getRzxs).reduce(DoubleUtils::ave).get());
                analysis.setTq(prodatas.get(0).getTq());
                analysis.setWd(prodatas.stream().map(Analysissubprojectpvcan::getWd).reduce(DoubleUtils::ave).get());
                analysis.setRljfs(prodatas.stream().map(Analysissubprojectpvcan::getRljfs).reduce(DoubleUtils::sum).get());
                analysis.setZdcl(prodatas.stream().map(Analysissubprojectpvcan::getZdcl).reduce(DoubleUtils::max).get());
                analysis.setZxcl(prodatas.stream().map(Analysissubprojectpvcan::getZxcl).reduce(DoubleUtils::min).get());
                analysis.setLlfdl(analysis.getFdl() + analysis.getGzdl() + analysis.getJxdl() + analysis.getXddl());
                analysis.setRzgwd(prodatas.stream().map(Analysissubprojectpvcan::getRzgwd).reduce(DoubleUtils::max).get());
                analysis.setLxaqts(prodatas.stream().map(Analysissubprojectpvcan::getLxaqts).reduce(DoubleUtils::max).get());
                analysis.setNljaqts(prodatas.stream().map(Analysissubprojectpvcan::getNljaqts).reduce(DoubleUtils::max).get());
                analysis.setYjhfdl(prodatas.stream().map(Analysissubprojectpvcan::getYjhfdl).reduce(DoubleUtils::sum).get());
                analysissubstationpvService.save(analysis);
            }
        }
    }

    /**
     * 保存公司表
     *
     * @param beginDate
     * @param endDate
     */
    public void saveCompany(String beginDate, String endDate) {
        System.out.println(beginDate+"\r\n"+endDate);
        List<String> days = getDays(beginDate, endDate);
        for (String day : days) {
            Map<String, Object> deleteparam = new HashMap<>();
            deleteparam.put("recorddate", DateUtils.parseDate(day));
            analysissubcompanyService.removeByMap(deleteparam);


            List<Analysissubstationwind> analysissubstationwinds = analysissubstationwindService.listByMap(deleteparam);

            Analysissubcompany analysissubcompany = new Analysissubcompany();
            analysissubcompany.setForeignkey(-1);
            analysissubcompany.setRecorddate(DateUtils.parseDate(day));
            analysissubcompany.setFdl(analysissubstationwinds.stream().map(Analysissubstationwind::getFdl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setFdlscada(analysissubstationwinds.stream().map(Analysissubstationwind::getFdlscada).reduce(DoubleUtils::sum).get());
            analysissubcompany.setSwdl(analysissubstationwinds.stream().map(Analysissubstationwind::getSwdl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setGwdl(analysissubstationwinds.stream().map(Analysissubstationwind::getGwdl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setZhcydl(analysissubstationwinds.stream().map(Analysissubstationwind::getZhcydl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setZhcydll(analysissubcompany.getFdl()!=0?analysissubcompany.getZhcydl()/analysissubcompany.getFdl()*100:0.0);
            analysissubcompany.setZhcydlscada(analysissubstationwinds.stream().map(Analysissubstationwind::getZhcydlscada).reduce(DoubleUtils::sum).get());
            analysissubcompany.setZhcydllscada(analysissubcompany.getFdlscada()!=0?analysissubcompany.getZhcydlscada()/analysissubcompany.getFdlscada()*100:0.0);
            analysissubcompany.setCydl(analysissubstationwinds.stream().map(Analysissubstationwind::getCydl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setCydll(analysissubcompany.getFdl()!=0?analysissubcompany.getCydl()/analysissubcompany.getFdl()*100:0.0);
            Double zjrl = analysissubstationwinds.stream().map(Analysissubstationwind::getZjrl).reduce(DoubleUtils::sum).get();
            analysissubcompany.setLyxs(zjrl!=0?analysissubcompany.getFdl()/zjrl:0.0);
            analysissubcompany.setLyxsscada(zjrl!=0?analysissubcompany.getFdlscada()/zjrl:0.0);
            analysissubcompany.setXddl(analysissubstationwinds.stream().map(Analysissubstationwind::getXddl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setFjgzdl(analysissubstationwinds.stream().map(Analysissubstationwind::getFjgzdl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setFjjxdl(analysissubstationwinds.stream().map(Analysissubstationwind::getFjjxdl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setXdsj(analysissubstationwinds.stream().map(Analysissubstationwind::getXdsj).reduce(DoubleUtils::sum).get());
            analysissubcompany.setFjgzsj(analysissubstationwinds.stream().map(Analysissubstationwind::getFjgzsj).reduce(DoubleUtils::sum).get());
            analysissubcompany.setFjjxsj(analysissubstationwinds.stream().map(Analysissubstationwind::getFjjxsj).reduce(DoubleUtils::sum).get());
            analysissubcompany.setQpjfx(analysissubstationwinds.stream().map(Analysissubstationwind::getQpjfx).reduce(DoubleUtils::ave).get());
            analysissubcompany.setLlfdl(analysissubstationwinds.stream().map(Analysissubstationwind::getLlfdl).reduce(DoubleUtils::sum).get());
            analysissubcompany.setLlfdlscada(analysissubstationwinds.stream().map(Analysissubstationwind::getLlfdlscada).reduce(DoubleUtils::sum).get());
            analysissubcompany.setYjhfdl(analysissubstationwinds.stream().map(Analysissubstationwind::getYjhfdl).reduce(DoubleUtils::sum).get());
            analysissubcompanyService.save(analysissubcompany);
            //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

            List<Analysissubstationpv> analysissubstationpvs = analysissubstationpvService.listByMap(deleteparam);

            Analysissubcompany analysissubcompanypv = new Analysissubcompany();
            analysissubcompanypv.setForeignkey(-2);
            analysissubcompanypv.setRecorddate(DateUtils.parseDate(day));
            analysissubcompanypv.setFdl(analysissubstationpvs.stream().map(Analysissubstationpv::getFdl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setFdlscada(analysissubcompanypv.getFdl()*1.005);
            analysissubcompanypv.setSwdl(analysissubstationpvs.stream().map(Analysissubstationpv::getSwdl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setGwdl(analysissubstationpvs.stream().map(Analysissubstationpv::getGwdl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setZhcydl(analysissubstationpvs.stream().map(Analysissubstationpv::getZhcydl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setZhcydll(analysissubcompanypv.getFdl()!=0?analysissubcompanypv.getZhcydl()/analysissubcompanypv.getFdl()*100:0.0);
            analysissubcompanypv.setZhcydlscada(analysissubcompanypv.getFdlscada()+analysissubcompanypv.getGwdl()-analysissubcompanypv.getSwdl());
            analysissubcompanypv.setZhcydllscada(analysissubcompanypv.getFdlscada()!=0?analysissubcompanypv.getZhcydlscada()/analysissubcompanypv.getFdlscada()*100:0.0);
            analysissubcompanypv.setCydl(analysissubstationpvs.stream().map(Analysissubstationpv::getFdcydl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setCydll(analysissubcompanypv.getFdl()!=0?analysissubcompanypv.getCydl()/analysissubcompanypv.getFdl()*100:0.0);
            Double gfzjrl = getGfzjrl();
            analysissubcompanypv.setLyxs(gfzjrl!=0?analysissubcompanypv.getFdl()/gfzjrl:0.0);
            analysissubcompanypv.setLyxsscada(gfzjrl!=0?analysissubcompanypv.getFdlscada()/gfzjrl:0.0);
            analysissubcompanypv.setXddl(analysissubstationpvs.stream().map(Analysissubstationpv::getXddl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setFjgzdl(analysissubstationpvs.stream().map(Analysissubstationpv::getGzdl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setFjjxdl(analysissubstationpvs.stream().map(Analysissubstationpv::getJxdl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setXdsj(analysissubstationpvs.stream().map(Analysissubstationpv::getXdsj).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setFjgzsj(analysissubstationpvs.stream().map(Analysissubstationpv::getGzsj).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setFjjxsj(analysissubstationpvs.stream().map(Analysissubstationpv::getJxsj).reduce(DoubleUtils::sum).get());
            //analysissubcompanypv.setQpjfx(analysissubstationpvs.stream().map(Analysissubstationpv::getQpjfx).reduce(DoubleUtils::ave).get());
            analysissubcompanypv.setLlfdl(analysissubstationpvs.stream().map(Analysissubstationpv::getLlfdl).reduce(DoubleUtils::sum).get());
            analysissubcompanypv.setLlfdlscada(analysissubcompanypv.getFdlscada()+analysissubcompanypv.getFjgzdl()+analysissubcompanypv.getFjjxdl()+analysissubcompanypv.getXddl());
            analysissubcompanypv.setYjhfdl(analysissubstationpvs.stream().map(Analysissubstationpv::getYjhfdl).reduce(DoubleUtils::sum).get());
            analysissubcompanyService.save(analysissubcompanypv);

            //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


            Analysissubcompany analysissubcompanyz = new Analysissubcompany();
            analysissubcompanyz.setForeignkey(0);
            analysissubcompanyz.setRecorddate(DateUtils.parseDate(day));
            analysissubcompanyz.setFdl(analysissubcompanypv.getFdl()+analysissubcompany.getFdl());
            analysissubcompanyz.setFdlscada(analysissubcompanypv.getFdlscada()+analysissubcompany.getFdlscada());
            analysissubcompanyz.setSwdl(analysissubcompanypv.getSwdl()+analysissubcompany.getSwdl());
            analysissubcompanyz.setGwdl(analysissubcompanypv.getGwdl()+analysissubcompany.getGwdl());
            analysissubcompanyz.setZhcydl(analysissubcompanypv.getZhcydl()+analysissubcompany.getZhcydl());
            analysissubcompanyz.setZhcydll(analysissubcompanyz.getFdl()!=0?analysissubcompanyz.getZhcydl()/analysissubcompanyz.getFdl()*100:0.0);
            analysissubcompanyz.setZhcydlscada(analysissubcompanypv.getZhcydlscada()+analysissubcompany.getZhcydlscada());
            analysissubcompanyz.setZhcydllscada(analysissubcompanyz.getFdlscada()!=0?analysissubcompanyz.getZhcydlscada()/analysissubcompanyz.getFdlscada()*100:0.0);
            analysissubcompanyz.setCydl(analysissubcompanypv.getCydl()+analysissubcompany.getCydl());
            analysissubcompanyz.setCydll(analysissubcompanyz.getFdl()!=0?analysissubcompanyz.getCydl()/analysissubcompanyz.getFdl()*100:0.0);
            Double zzjrl = getGfzjrl()+zjrl;
            analysissubcompanyz.setLyxs(zzjrl!=0?analysissubcompanyz.getFdl()/zzjrl:0.0);
            analysissubcompanyz.setLyxsscada(zzjrl!=0?analysissubcompanyz.getFdlscada()/zzjrl:0.0);
            analysissubcompanyz.setXddl(analysissubcompanypv.getXddl()+analysissubcompany.getXddl());
            analysissubcompanyz.setFjgzdl(analysissubcompanypv.getFjgzdl()+analysissubcompany.getFjgzdl());
            analysissubcompanyz.setFjjxdl(analysissubcompanypv.getFjjxdl()+analysissubcompany.getFjjxdl());
            analysissubcompanyz.setXdsj(analysissubcompanypv.getXdsj()+analysissubcompany.getXdsj());
            analysissubcompanyz.setFjgzsj(analysissubcompanypv.getFjgzsj()+analysissubcompany.getFjgzsj());
            analysissubcompanyz.setFjjxsj(analysissubcompanypv.getFjjxsj()+analysissubcompany.getFjjxsj());
            analysissubcompanyz.setQpjfx(analysissubcompany.getQpjfx());
            analysissubcompanyz.setLlfdl(analysissubcompanypv.getLlfdl()+analysissubcompany.getLlfdl());
            analysissubcompanyz.setLlfdlscada(analysissubcompanypv.getLlfdlscada()+analysissubcompany.getLlfdlscada());
            analysissubcompanyz.setYjhfdl(analysissubcompanypv.getYjhfdl()+analysissubcompany.getYjhfdl());
            analysissubcompanyService.save(analysissubcompanyz);

        }
    }

    /**
     * 获取光伏装机容量
     * @return
     */
    private Double getGfzjrl() {
        List<Windpowerstation> stations = CacheContext.stations;
        Double gdc = stations.stream().filter(i -> i.getId().endsWith("GDC")).map(Windpowerstation::getCapacity).reduce(DoubleUtils::sum).get()/10;
        return gdc;
    }

    /**
     * 根据日期和风场获得主表数据
     *
     * @param day
     * @param station
     */
    private Analysismain getMainValues(String day, String station) {
        QueryWrapper<Analysismain> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("recorddate", DateUtils.parseDate(day)).eq("wpid", station);
        Analysismain one = analysismainService.getOne(queryWrapper);
        return one;


    }

    /**
     * 获取两日期间日期list
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    private List<String> getDays(String beginDate, String endDate) {
        List<String> days = null;
        if (StringUtils.isNotEmpty(beginDate) && StringUtils.isNotEmpty(endDate)) {
            days = DateUtils.getDays(beginDate, endDate);
        } else {
            days = new ArrayList<>();
            days.add(DateUtils.getYesterdayStr("yyyy-MM-dd"));
        }
        return days;
    }

    /**
     * 获取日期是当年第几天
     *
     * @param day
     * @return
     */
    private Double getDnljts(String day) {
        Calendar c = Calendar.getInstance();
        c.setTime(DateUtils.parseDate(day));
        return Double.valueOf(c.get(Calendar.DAY_OF_YEAR));
    }

    /**
     * 获取计划发电量
     *
     * @param id
     * @param day
     * @return
     */
    private double getYjhfdl(String id, String day) {
        String[] ny = new String[2];
        Date date = DateUtils.parseDate(day);
        ny[0] = String.format("%tY", date);
        ny[1] = String.format("%tm", date);
        QueryWrapper<Projectplan> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("projectid", id);
        queryWrapper.eq("year", ny[0]);
        queryWrapper.eq("month", ny[1]);
        Projectplan one = projectplanService.getOne(queryWrapper);
        if (StringUtils.isNotNull(one)) {
            return Double.parseDouble(one.getGeneratingcapacity());
        }
        return 0.0;

    }
    //-----------------------------------------以下为前端调用-------------------------------------

    /**
     * 首页list
     *
     * @param beginDate
     * @param endDate
     * @return
     */
    public List<AnalysisMainVo> analysismainlist(String beginDate, String endDate) {
        List<String> days = getDays(beginDate, endDate);
        Collections.reverse(days);
        Map<String, Windpowerstation> wpmaps = CacheContext.wpmaps;
        List<Analysismain> resList = new ArrayList<>();
        for (String day : days) {
            QueryWrapper<Analysismain> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("recorddate", DateUtils.parseDate(day)).orderByDesc("recorddate");
            //queryWrapper.ge("recorddate",DateUtils.parseDate(beginDate)).le("recorddate",DateUtils.parseDate(endDate)).orderByDesc("recorddate");
            List<Analysismain> list = analysismainService.list(queryWrapper);
            list.sort((x, y) -> {
                return wpmaps.get(x.getWpid()).getOrdernum().compareTo(wpmaps.get(y.getWpid()).getOrdernum());
            });
            list.stream().forEach(i -> resList.add(i));
        }

        List<AnalysisMainVo> collect = resList.stream().map(i -> {
            AnalysisMainVo vo = new AnalysisMainVo();
            vo.setWpid(i.getWpid());
            vo.setWpname(wpmaps.get(i.getWpid()).getName());
            vo.setTheday(DateUtils.toDate(i.getRecorddate()));
            vo.setIsConfirm(i.getIscommit());
            return vo;
        }).collect(Collectors.toList());
        return collect;
    }

    /**
     * 首页确认
     *
     * @param vo
     */
    public void commit(AnalysisMainVo vo) {
        UpdateWrapper<Analysismain> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("recorddate", DateUtils.parseDate(vo.getTheday())).eq("wpid", vo.getWpid()).set("iscommit", 1);
        analysismainService.update(null, updateWrapper);
    }

    /**
     * 表底list
     *
     * @param theday
     * @param wpid
     * @return
     */
    public List<Object> bdzlist(String theday, String wpid) throws IllegalAccessException, IntrospectionException, InvocationTargetException {

        List<Object> resltList = new ArrayList<>();

        QueryWrapper<Analysissubtablebottom> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("recorddate", DateUtils.parseDate(theday)).eq("wpid", wpid);
        List<Analysissubtablebottom> bdzlist = analysissubtablebottomService.list(queryWrapper);
        Map<String, Meterpoint2> meterMap = CacheContext.meterMap;
        List<String> collect = bdzlist.stream().map(i -> i.getMeterid()).collect(Collectors.toList());
        Collections.sort(collect, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.parseInt(meterMap.get(o1).getCode()) - Integer.parseInt(meterMap.get(o2).getCode());
            }
        });
        //---------------------------倍率赋值开始-----------------------------
        DeskObject blObject = new DeskObject();
        blObject.setDate(DateUtils.parseDate(theday));
        blObject.setName("倍率");
        try {
            LinkedHashMap addMap = new LinkedHashMap();
            LinkedHashMap addValMap = new LinkedHashMap();

            for (String meterid : collect) {
                addMap.put(meterMap.get(meterid).getCode() + "_" + meterMap.get(meterid).getDescription(), Class.forName("java.lang.Double"));
                addValMap.put(meterMap.get(meterid).getCode() + "_" + meterMap.get(meterid).getDescription(), meterMap.get(meterid).getMagnification());
            }
            Object blo = new ClassUtil().dynamicClass(blObject, addMap, addValMap);
            resltList.add(blo);
            System.out.println(JSON.toJSONString(blo));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //---------------------------起码赋值开始-----------------------------
        DeskObject qmObject = new DeskObject();
        qmObject.setDate(DateUtils.parseDate(theday));
        qmObject.setName("起码");

        QueryWrapper<Analysissubtablebottom> queryYestmonth = new QueryWrapper<>();
        queryYestmonth.eq("recorddate", DateUtils.getYestday(DateUtils.parseDate(theday))).eq("wpid", wpid);
        List<Analysissubtablebottom> yesterdaybdzlist = analysissubtablebottomService.list(queryYestmonth);

        try {
            LinkedHashMap addMap = new LinkedHashMap();
            LinkedHashMap addValMap = new LinkedHashMap();

            for (String meterid : collect) {
                addMap.put(meterMap.get(meterid).getCode() + "_" + meterMap.get(meterid).getDescription(), Class.forName("java.lang.Double"));
                addValMap.put(meterMap.get(meterid).getCode() + "_" + meterMap.get(meterid).getDescription(), yesterdaybdzlist.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? yesterdaybdzlist.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getStopcodemodify() : BigDecimal.ZERO);
            }
            Object blo = new ClassUtil().dynamicClass(qmObject, addMap, addValMap);
            resltList.add(blo);
            System.out.println(JSON.toJSONString(blo));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //-------------------------------止码赋值开始-------------------------------------------


        DeskObject zmObject = new DeskObject();
        zmObject.setDate(DateUtils.parseDate(theday));
        zmObject.setName("止码");


        try {
            LinkedHashMap addMap = new LinkedHashMap();
            LinkedHashMap addValMap = new LinkedHashMap();

            for (String meterid : collect) {
                addMap.put(meterMap.get(meterid).getCode() + "_" + meterMap.get(meterid).getDescription(), Class.forName("java.lang.Double"));
                addValMap.put(meterMap.get(meterid).getCode() + "_" + meterMap.get(meterid).getDescription(), bdzlist.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getStopcodemodify());
            }
            Object blo = new ClassUtil().dynamicClass(zmObject, addMap, addValMap);
            resltList.add(blo);
            System.out.println(JSON.toJSONString(blo));
        } catch (Exception e) {
            e.printStackTrace();
        }
        //-------------------------------电量赋值开始-------------------------------------------

        DeskObject dlObject = new DeskObject();
        dlObject.setDate(DateUtils.parseDate(theday));
        dlObject.setName("电量");

        try {
            LinkedHashMap addMap = new LinkedHashMap();
            LinkedHashMap addValMap = new LinkedHashMap();

            for (String meterid : collect) {
                addMap.put(meterMap.get(meterid).getCode() + "_" + meterMap.get(meterid).getDescription(), Class.forName("java.lang.Double"));
                addValMap.put(meterMap.get(meterid).getCode() + "_" + meterMap.get(meterid).getDescription(), bdzlist.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify());
            }
            Object blo = new ClassUtil().dynamicClass(dlObject, addMap, addValMap);
            resltList.add(blo);
            System.out.println(JSON.toJSONString(blo));
        } catch (Exception e) {
            e.printStackTrace();
        }

        //-------------------------------排序赋值开始-------------------------------------------

//        DeskObject pxObject = new DeskObject();
//        pxObject.setDate(DateUtils.parseDate(theday));
//        pxObject.setName("排序");
//        Class<?> aClass =null;
//        try {
//            LinkedHashMap addMap = new LinkedHashMap();
//            LinkedHashMap addValMap = new LinkedHashMap();
//
//            for (String meterid : collect) {
//                addMap.put(meterMap.get(meterid).getCode()+"_"+meterMap.get(meterid).getDescription(), Class.forName("java.lang.Integer"));
//                addValMap.put(meterMap.get(meterid).getCode()+"_"+meterMap.get(meterid).getDescription(), Integer.parseInt(meterMap.get(meterid).getCode()));
//            }
//            Object blo = new ClassUtil().dynamicClass(pxObject, addMap, addValMap);
//            aClass = blo.getClass();
//            resltList.add(blo);
//            System.out.println(JSON.toJSONString(blo));
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        Map convert = convert(resltList);

        return resltList;
    }

    /**
     * 将list 转 map
     *
     * @param list
     * @return
     */
    public Map convert(List list) {
        List result;
        Map resmap = new HashMap();
        Field[] fields = list.get(0).getClass().getDeclaredFields();
        result = new ArrayList<>(fields.length);
        for (int i = 0; i < fields.length; i++) {
            result.add(new ArrayList());
        }
        for (int j = 0; j < list.size(); j++) {
            Field[] declaredFields = list.get(j).getClass().getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {

                List l = (List) result.get(i);
                Field field = declaredFields[i];
                String name = field.getName();

                field.setAccessible(true);
                try {
                    l.add(field.get(list.get(j)));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                resmap.put(name, l);
            }
        }

        return resmap;

    }

    /**
     * 统计分析list
     *
     * @param theday
     * @param wpid
     * @param identity
     * @return
     */
    public List<Object> tjfxlist(String theday, String wpid, Integer identity) {
        List<Object> resultList = new ArrayList<>();
        Date date = DateUtils.parseDate(theday);


        List<Project> projects = CacheContext.projects.stream().filter(i -> i.getWindpowerstationid().equals(wpid)).collect(Collectors.toList());
        Windpowerstation windpowerstation = CacheContext.stations.stream().filter(i -> i.getId().equals(wpid)).findFirst().get();


        Map<String, Object> params = new HashMap<>();
        params.put("recorddate", date);
        params.put("wpid", wpid);

        if (identity == 0) {
            List<Analysissubstationwind> windstation = analysissubstationwindService.listByMap(params);
            List<Analysissubprojectwindcannot> windprojectcannots = analysissubprojectwindcannotService.listByMap(params);
            List<Analysissubprojectwindcan> windprojectcans = analysissubprojectwindcanService.listByMap(params);
            List<Analysiswindtarget> targetlist = CacheContext.targetlist.stream().filter(i -> i.getWindorpv().equals("风电"))
                    .sorted(Comparator.comparing(Analysiswindtarget::getOrderno)).collect(Collectors.toList());

            //-------------------------------------------------------------------------------------------------------------
            for (Analysiswindtarget target : targetlist) {
                AnalysisSubVo sub = new AnalysisSubVo();
                sub.setId(target.getId());
                sub.setName(target.getName());
                try {
                    LinkedHashMap addMap = new LinkedHashMap();
                    LinkedHashMap addValMap = new LinkedHashMap();
                    for (Project project : projects) {
                        Map<String, Object> map = new HashMap<>();
                        Analysissubprojectwindcannot analysiswindprojectcannot = windprojectcannots.stream().filter(i -> i.getProjectid().equals(project.getId())).findFirst().get();
                        Class<? extends Analysissubprojectwindcannot> aClass = analysiswindprojectcannot.getClass();
                        Field field = aClass.getDeclaredField(target.getId());
                        PropertyDescriptor pd = new PropertyDescriptor(field.getName(), aClass);
                        map.put("当日值(只读)", pd.getReadMethod().invoke(analysiswindprojectcannot));

                        Analysissubprojectwindcan analysiswindprojectcan = windprojectcans.stream().filter(i -> i.getProjectid().equals(project.getId())).findFirst().get();
                        Class<? extends Analysissubprojectwindcan> bClass = analysiswindprojectcan.getClass();
                        Field fieldb = bClass.getDeclaredField(target.getId());
                        PropertyDescriptor pdb = new PropertyDescriptor(fieldb.getName(), bClass);
                        map.put("当日值(编辑)", pdb.getReadMethod().invoke(analysiswindprojectcan));

                        addMap.put(project.getName() + "_" + project.getOrdernum(), Class.forName("java.util.Map"));
                        addValMap.put(project.getName() + "_" + project.getOrdernum(), map);
                    }
                    Analysissubstationwind analysiswindstation = windstation.stream().filter(i -> i.getWpid().trim().equals(wpid)).findFirst().get();
                    Class<? extends Analysissubstationwind> Class = analysiswindstation.getClass();
                    Field fiel = Class.getDeclaredField(target.getId());
                    PropertyDescriptor pd = new PropertyDescriptor(fiel.getName(), Class);
                    addMap.put(windpowerstation.getName(), Class.forName("java.lang.Object"));
                    addValMap.put(windpowerstation.getName(), pd.getReadMethod().invoke(analysiswindstation));
                    //增加是否可以编辑字段,如果需要，打开下面注释
                    addMap.put("是否可编辑", Class.forName("java.lang.Integer"));
                    addValMap.put("是否可编辑", target.getIsupdate());


                    Object blo = new ClassUtil().dynamicClass(sub, addMap, addValMap);
                    resultList.add(blo);
                    System.out.println(JSON.toJSONString(blo));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } else if (identity == 1) {
            List<Analysissubstationpv> windstation = analysissubstationpvService.listByMap(params);
            List<Analysissubprojectpvcannot> windprojectcannots = analysissubprojectpvcannotService.listByMap(params);
            List<Analysissubprojectpvcan> windprojectcans = analysissubprojectpvcanService.listByMap(params);
            List<Analysiswindtarget> targetlist = CacheContext.targetlist.stream().filter(i -> i.getWindorpv().equals("光伏"))
                    .sorted(Comparator.comparing(Analysiswindtarget::getOrderno)).collect(Collectors.toList());

            //-------------------------------------------------------------------------------------------------------------
            for (Analysiswindtarget target : targetlist) {
                AnalysisSubVo sub = new AnalysisSubVo();
                sub.setId(target.getId());
                sub.setName(target.getName());
                try {
                    LinkedHashMap addMap = new LinkedHashMap();
                    LinkedHashMap addValMap = new LinkedHashMap();
                    for (Project project : projects) {
                        Map<String, Object> map = new HashMap<>();
                        Analysissubprojectpvcannot analysiswindprojectcannot = windprojectcannots.stream().filter(i -> i.getProjectid().equals(project.getId())).findFirst().get();
                        Class<? extends Analysissubprojectpvcannot> aClass = analysiswindprojectcannot.getClass();
                        Field field = aClass.getDeclaredField(target.getId());
                        PropertyDescriptor pd = new PropertyDescriptor(field.getName(), aClass);
                        map.put("当日值(只读)", pd.getReadMethod().invoke(analysiswindprojectcannot));

                        Analysissubprojectpvcan analysiswindprojectcan = windprojectcans.stream().filter(i -> i.getProjectid().equals(project.getId())).findFirst().get();
                        Class<? extends Analysissubprojectpvcan> bClass = analysiswindprojectcan.getClass();
                        Field fieldb = bClass.getDeclaredField(target.getId());
                        PropertyDescriptor pdb = new PropertyDescriptor(fieldb.getName(), bClass);
                        map.put("当日值(编辑)", pdb.getReadMethod().invoke(analysiswindprojectcan));

                        addMap.put(project.getName() + "_" + project.getOrdernum(), Class.forName("java.util.Map"));
                        addValMap.put(project.getName() + "_" + project.getOrdernum(), map);
                    }
                    Analysissubstationpv analysiswindstation = windstation.stream().filter(i -> i.getWpid().equals(wpid)).findFirst().get();
                    Class<? extends Analysissubstationpv> Class = analysiswindstation.getClass();
                    Field fiel = Class.getDeclaredField(target.getId());
                    PropertyDescriptor pd = new PropertyDescriptor(fiel.getName(), Class);
                    addMap.put(windpowerstation.getName(), Class.forName("java.lang.Object"));
                    addValMap.put(windpowerstation.getName(), pd.getReadMethod().invoke(analysiswindstation));
                    //增加是否可以编辑字段,如果需要，打开下面注释
                    addMap.put("是否可编辑", Class.forName("java.lang.Integer"));
                    addValMap.put("是否可编辑", target.getIsupdate());

                    Object blo = new ClassUtil().dynamicClass(sub, addMap, addValMap);
                    resultList.add(blo);
                    System.out.println(JSON.toJSONString(blo));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return resultList;
    }

    /**
     * 修改表底
     *
     * @param keyAndValue
     */
    public void updateBdz(Map<String, Object> keyAndValue) {
        Map<String, Meterpoint2> meterMap = CacheContext.meterMap;
        Map<String, List<Meterpoint2>> wpmeterMap = CacheContext.wpmeterMap;
        String wpid = (String) keyAndValue.get("wpid");
        String date = (String) keyAndValue.get("date");
        List<Project> projects = CacheContext.projects.stream().filter(i -> i.getWindpowerstationid().equals(wpid)).collect(Collectors.toList());
        Map<String, Object> map = new HashMap<>();
        map.put("wpid", wpid);
        map.put("recorddate", DateUtils.parseDate(date));
        List<Analysissubtablebottom> currentDay = analysissubtablebottomService.listByMap(map);
        Date yestday = DateUtils.getYestday(DateUtils.parseDate(date));
        map.put("recorddate", yestday);
        List<Analysissubtablebottom> yesterDay = analysissubtablebottomService.listByMap(map);

        currentDay.stream().forEach(i -> {
            double magnification = meterMap.get(i.getMeterid()).getMagnification().doubleValue();
            String metername = i.getMetername();
            double zm = Double.parseDouble(keyAndValue.get(meterMap.get(i.getMeterid()).getCode() + "_" + metername).toString());
            i.setStopcodemodify(zm);
            double qm = yesterDay.stream().filter(x -> x.getMetername().equals(metername)).findFirst().isPresent() ? yesterDay.stream().filter(x -> x.getMetername().equals(metername)).findFirst().get().getStopcodemodify() : 0.0;
            i.setDayvaluemodify((zm - qm) * magnification);
            analysissubtablebottomService.updateById(i);
        });


        List<String> fcfdlmeterids = wpmeterMap.get(wpid).stream()
                .filter(i -> (
                        i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                )).map(i -> i.getId()).collect(Collectors.toList());
        double fcfdl = 0.0;
        for (String meterid : fcfdlmeterids) {
            fcfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------
        List<String> fcswmeterids = wpmeterMap.get(wpid).stream()
                .filter(i -> (
                        i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("正向有功")
                )).map(i -> i.getId()).collect(Collectors.toList());
        double fcswfdl = 0.0;
        for (String meterid : fcswmeterids) {
            fcswfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------
        List<String> fcgwmeterids = wpmeterMap.get(wpid).stream()
                .filter(i -> (
                        i.getMetersort().equals("主") && i.getMetertype().equals("出线") && i.getDisplaytype().equals("反向有功")
                )).map(i -> i.getId()).collect(Collectors.toList());
        double fcgwfdl = 0.0;
        for (String meterid : fcgwmeterids) {
            fcgwfdl += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
        }
        //-------------------------------------------------------------------------------------------------------------------------------------------------
        List<String> fczybmeterids = wpmeterMap.get(wpid).stream()
                .filter(i -> (
                        i.getMetersort().equals("主") && i.getMetertype().equals("站用变") && i.getDisplaytype().equals("正向有功")
                )).map(i -> i.getId()).collect(Collectors.toList());
        double fczyb = 0.0;
        for (String meterid : fczybmeterids) {
            fczyb += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
        }
        double zjrl = 0.0;
        if (wpid.endsWith("FDC")) {
            for (Project project : projects) {
                Map<String, Object> param = new HashMap<>();
                param.put("recorddate", DateUtils.parseDate(date));
                param.put("projectid", project.getId());
                Analysissubprojectwindcan projectcan = analysissubprojectwindcanService.listByMap(param).stream().findFirst().get();
                //select * from meterpoint2 where projectid='QS03_GC' AND METERSORT = '主' AND METERTYPE='进线' and displaytype='正向有功'
                List<String> fdls = wpmeterMap.get(wpid).stream()
                        .filter(i -> (
                                i.getProjectid().equals(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                param.remove("projectid");
                double generatingcapacity = 0;
                for (String meterid : fdls) {
                    generatingcapacity += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }
                projectcan.setFdl(generatingcapacity / 10000);
                projectcan.setFdlscada(projectcan.getFdl() * 1.005);
                projectcan.setSwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcswfdl) / 10000 : 0.0);
                projectcan.setGwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcgwfdl) / 10000 : 0.0);
                projectcan.setZhcydl(projectcan.getFdl() + projectcan.getGwdl() - projectcan.getSwdl());
                projectcan.setZhcydll(projectcan.getFdl() != 0.0 ? projectcan.getZhcydl() / projectcan.getFdl() * 100 : 0.0);
                projectcan.setZhcydlscada(projectcan.getFdlscada() + projectcan.getGwdl() - projectcan.getSwdl());
                projectcan.setZhcydllscada(projectcan.getFdlscada() != 0.0 ? projectcan.getZhcydlscada() / projectcan.getFdlscada() * 100 : 0.0);
                projectcan.setCydl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fczyb) / 10000 : 0.0);
                projectcan.setCydll(projectcan.getFdl() != 0.0 ? projectcan.getCydl() / projectcan.getFdl() * 100 : 0.0);
                projectcan.setLyxs(projectcan.getFdl() / projectcan.getZjrl());
                projectcan.setLyxsscada(projectcan.getFdlscada() / projectcan.getZjrl());
                projectcan.setLlfdl(projectcan.getFdl() + projectcan.getFjgzdl() + projectcan.getFjjxdl() + projectcan.getXddl());
                projectcan.setLlfdlscada(projectcan.getFdlscada() + projectcan.getFjgzdl() + projectcan.getFjjxdl() + projectcan.getXddl());
                projectcan.setQfl(projectcan.getFdl() != 0.0 ? projectcan.getXddl() / projectcan.getFdl() * 100 : 0.0);
                analysissubprojectwindcanService.updateById(projectcan);
            }
            QueryWrapper<Analysissubstationwind> fcmap = new QueryWrapper<>();
            fcmap.eq("wpid", wpid);
            fcmap.eq("recorddate", DateUtils.parseDate(date));
            Analysissubstationwind analysis = analysissubstationwindService.getOne(fcmap);
            Map<String, Object> params = new HashMap<>();
            params.put("tid", analysis.getTid());
            List<Analysissubprojectwindcan> prodatas = analysissubprojectwindcanService.listByMap(params);
            analysis.setFdl(prodatas.stream().map(Analysissubprojectwindcan::getFdl).reduce(DoubleUtils::sum).get());
            analysis.setFdlscada(prodatas.stream().map(Analysissubprojectwindcan::getFdlscada).reduce(DoubleUtils::sum).get());
            analysis.setSwdl(prodatas.stream().map(Analysissubprojectwindcan::getSwdl).reduce(DoubleUtils::sum).get());
            analysis.setGwdl(prodatas.stream().map(Analysissubprojectwindcan::getGwdl).reduce(DoubleUtils::sum).get());
            analysis.setZhcydl(analysis.getFdl() + analysis.getGwdl() - analysis.getSwdl());
            analysis.setZhcydlscada(analysis.getFdlscada() + analysis.getGwdl() - analysis.getSwdl());
            analysis.setZhcydll(analysis.getFdl() != 0.0 ? analysis.getZhcydl() / analysis.getFdl() * 100 : 0.0);
            analysis.setZhcydllscada(analysis.getFdlscada() != 0.0 ? analysis.getZhcydlscada() / analysis.getFdlscada() * 100 : 0.0);
            analysis.setCydl(prodatas.stream().map(Analysissubprojectwindcan::getCydl).reduce(DoubleUtils::sum).get());
            analysis.setCydll(analysis.getFdl() != 0.0 ? analysis.getCydl() / analysis.getFdl() * 100 : 0.0);
            analysis.setLyxs(analysis.getFdl() / analysis.getZjrl());
            analysis.setLyxsscada(analysis.getFdlscada() / analysis.getZjrl());
            analysis.setLlfdl(analysis.getFdl() + analysis.getFjgzdl() + analysis.getFjjxdl() + analysis.getXddl());
            analysis.setLlfdl(analysis.getFdlscada() + analysis.getFjgzdl() + analysis.getFjjxdl() + analysis.getXddl());
            analysis.setQfl(analysis.getFdl() != 0.0 ? analysis.getXddl() / analysis.getFdl() * 100 : 0.0);
            analysissubstationwindService.updateById(analysis);
        } else {
            for (Project project : projects) {
                zjrl += project.getCapacity();
                Map<String, Object> param = new HashMap<>();
                param.put("recorddate", DateUtils.parseDate(date));
                param.put("projectid", project.getId());
                Analysissubprojectpvcan projectcan = analysissubprojectpvcanService.listByMap(param).stream().findFirst().get();
                //select * from meterpoint2 where projectid='QS03_GC' AND METERSORT = '主' AND METERTYPE='进线' and displaytype='正向有功'
                List<String> fdls = wpmeterMap.get(wpid).stream()
                        .filter(i -> (
                                i.getProjectid().equals(project.getId()) && i.getMetersort().equals("主") && i.getMetertype().equals("进线") && i.getDisplaytype().equals("正向有功")
                        )).map(i -> i.getId()).collect(Collectors.toList());
                param.remove("projectid");
                double generatingcapacity = 0;
                for (String meterid : fdls) {
                    generatingcapacity += currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().isPresent() ? currentDay.stream().filter(i -> i.getMeterid().equals(meterid)).findFirst().get().getDayvaluemodify().doubleValue() : 0.0;
                }
                projectcan.setFdl(generatingcapacity / 10000);

                projectcan.setSwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcswfdl) / 10000 : 0.0);
                projectcan.setGwdl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fcgwfdl) / 10000 : 0.0);
                projectcan.setZhcydl(projectcan.getFdl() + projectcan.getGwdl() - projectcan.getSwdl());
                projectcan.setZhcydll(projectcan.getFdl() != 0.0 ? projectcan.getZhcydl() / projectcan.getFdl() * 100 : 0.0);
                projectcan.setFdcydl(fcfdl != 0.0 ? (generatingcapacity / fcfdl * fczyb) / 10000 : 0.0);
                projectcan.setFdcydll(projectcan.getFdl() != 0.0 ? projectcan.getFdcydl() / projectcan.getFdl() * 100 : 0.0);
                projectcan.setLyxs(projectcan.getFdl() / project.getCapacity() * 10);
                projectcan.setLlfdl(projectcan.getFdl() + projectcan.getGzdl() + projectcan.getJxdl() + projectcan.getXddl());
                analysissubprojectpvcanService.updateById(projectcan);
            }
            QueryWrapper<Analysissubstationpv> fcmap = new QueryWrapper<>();
            fcmap.eq("wpid", wpid);
            fcmap.eq("recorddate", DateUtils.parseDate(date));
            Analysissubstationpv analysis = analysissubstationpvService.getOne(fcmap);
            Map<String, Object> params = new HashMap<>();
            params.put("tid", analysis.getTid());
            List<Analysissubprojectpvcan> prodatas = analysissubprojectpvcanService.listByMap(params);
            analysis.setFdl(prodatas.stream().map(Analysissubprojectpvcan::getFdl).reduce(DoubleUtils::sum).get());
            analysis.setSwdl(prodatas.stream().map(Analysissubprojectpvcan::getSwdl).reduce(DoubleUtils::sum).get());
            analysis.setGwdl(prodatas.stream().map(Analysissubprojectpvcan::getGwdl).reduce(DoubleUtils::sum).get());
            analysis.setZhcydl(analysis.getFdl() + analysis.getGwdl() - analysis.getSwdl());
            analysis.setZhcydll(analysis.getFdl() != 0.0 ? analysis.getZhcydl() / analysis.getFdl() * 100 : 0.0);
            analysis.setFdcydl(prodatas.stream().map(Analysissubprojectpvcan::getFdcydl).reduce(DoubleUtils::sum).get());
            analysis.setFdcydll(analysis.getFdl() != 0.0 ? analysis.getFdcydl() / analysis.getFdl() * 100 : 0.0);
            analysis.setLyxs(zjrl != 0.0 ? analysis.getFdl() / zjrl * 10 : 0.0);
            analysis.setLlfdl(analysis.getFdl() + analysis.getGzdl() + analysis.getJxdl() + analysis.getXddl());
            analysissubstationpvService.updateById(analysis);
        }
    }

    /**
     * 修改统计分析
     *
     * @param tjfxVo
     */
    public void updateTjfx(List<Map<String, Object>> tjfxVo) {
        Map<String, Project> projectMap = CacheContext.projectMap;
        List<Analysissubprojectwindcan> windcans = null;
        Analysissubstationwind windstation = null;
        List<Analysissubprojectpvcan> pvcans = null;
        Analysissubstationpv pvstation = null;

        for (Map<String, Object> stringObjectMap : tjfxVo) {
            String id = (String) stringObjectMap.get("id");
            String wpid = (String) stringObjectMap.get("wpid");
            String date = (String) stringObjectMap.get("date");
            Map<String, Object> map = new HashMap<>();
            map.put("wpid", wpid);
            map.put("recorddate", DateUtils.parseDate(date));
            if (wpid.endsWith("FDC")) {
                if (windcans == null) {
                    windcans = analysissubprojectwindcanService.listByMap(map);
                    windstation = analysissubstationwindService.listByMap(map).stream().findFirst().get();
                }

                for (Analysissubprojectwindcan windcan : windcans) {
                    try {
                        String name = projectMap.get(windcan.getProjectid()).getName() + "_" + projectMap.get(windcan.getProjectid()).getOrdernum();

                        Object value = stringObjectMap.get(name + "当日值(编辑)");
                        Field f = windcan.getClass().getDeclaredField(id);
                        f.setAccessible(true);
                        if (StringUtils.isNotNull(value)) {
                            if (isNumeric(value.toString())) {
                                f.set(windcan, Double.parseDouble(value.toString()));
                            } else {
                                f.set(windcan, value.toString());
                            }
                        }


                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    windcan.setLyxs(windcan.getFdl() / windcan.getZjrl());
                    windcan.setLyxsscada(windcan.getFdlscada() / windcan.getZjrl());
                    windcan.setQfl((windcan.getXddl() + windcan.getFdl()) != 0 ? windcan.getXddl() / (windcan.getXddl() + windcan.getFdl()) * 100 : 0.0);
                    windcan.setLlfdl(windcan.getFdl() + windcan.getFjgzdl() + windcan.getFjjxdl() + windcan.getXddl());  //+can.getXnssdl()
                    windcan.setLlfdlscada(windcan.getFdlscada() + windcan.getFjgzdl() + windcan.getFjjxdl() + windcan.getXddl());//+can.getXnssdl()
                    analysissubprojectwindcanService.updateById(windcan);
                }
            } else {
                if (windcans == null) {
                    pvcans = analysissubprojectpvcanService.listByMap(map);
                    pvstation = analysissubstationpvService.listByMap(map).stream().findFirst().get();
                }

                for (Analysissubprojectpvcan windcan : pvcans) {
                    try {
                        String name = projectMap.get(windcan.getProjectid()).getName() + "_" + projectMap.get(windcan.getProjectid()).getOrdernum();
                        Object value = stringObjectMap.get(name + "当日值(编辑)");
                        Field f = windcan.getClass().getDeclaredField(id);
                        f.setAccessible(true);
                        f.set(windcan, value);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    windcan.setLlfdl(windcan.getFdl() + windcan.getXddl() + windcan.getGzdl() + windcan.getJxdl());
                    analysissubprojectpvcanService.updateById(windcan);
                }
            }
        }
        if (windstation != null) {
            windstation.setCnsldwdl(windcans.stream().map(Analysissubprojectwindcan::getCnsldwdl).reduce(DoubleUtils::sum).get());
            windstation.setCnsldwsj(windcans.stream().map(Analysissubprojectwindcan::getCnsldwsj).reduce(DoubleUtils::sum).get());
            windstation.setCnsljxdl(windcans.stream().map(Analysissubprojectwindcan::getCnsljxdl).reduce(DoubleUtils::sum).get());
            windstation.setCnsljxsj(windcans.stream().map(Analysissubprojectwindcan::getCnsljxsj).reduce(DoubleUtils::sum).get());
            windstation.setCwsldwdl(windcans.stream().map(Analysissubprojectwindcan::getCwsldwdl).reduce(DoubleUtils::sum).get());
            windstation.setCwsldwsj(windcans.stream().map(Analysissubprojectwindcan::getCwsldwsj).reduce(DoubleUtils::sum).get());
            windstation.setCwsljxdl(windcans.stream().map(Analysissubprojectwindcan::getCwsljxdl).reduce(DoubleUtils::sum).get());
            windstation.setCwsljxsj(windcans.stream().map(Analysissubprojectwindcan::getCwsljxsj).reduce(DoubleUtils::sum).get());

            windstation.setZrzhdl(windcans.stream().map(Analysissubprojectwindcan::getZrzhdl).reduce(DoubleUtils::sum).get());
            windstation.setZrzhsj(windcans.stream().map(Analysissubprojectwindcan::getZrzhsj).reduce(DoubleUtils::sum).get());
            windstation.setXddl(windcans.stream().map(Analysissubprojectwindcan::getXddl).reduce(DoubleUtils::sum).get());
            windstation.setXdsj(windcans.stream().map(Analysissubprojectwindcan::getXdsj).reduce(DoubleUtils::sum).get());
            windstation.setFjgzdl(windcans.stream().map(Analysissubprojectwindcan::getFjgzdl).reduce(DoubleUtils::sum).get());
            windstation.setFjgzsj(windcans.stream().map(Analysissubprojectwindcan::getFjgzsj).reduce(DoubleUtils::sum).get());
            windstation.setXnssdl(windcans.stream().map(Analysissubprojectwindcan::getXnssdl).reduce(DoubleUtils::sum).get());

            windstation.setSyzgzdl(windcans.stream().map(Analysissubprojectwindcan::getSyzgzdl).reduce(DoubleUtils::sum).get());
            windstation.setSyzgzsj(windcans.stream().map(Analysissubprojectwindcan::getSyzgzsj).reduce(DoubleUtils::sum).get());
            windstation.setJdxlgzdl(windcans.stream().map(Analysissubprojectwindcan::getJdxlgzdl).reduce(DoubleUtils::sum).get());
            windstation.setJdxlgzsj(windcans.stream().map(Analysissubprojectwindcan::getJdxlgzsj).reduce(DoubleUtils::sum).get());

            windstation.setFjjxdl(windcans.stream().map(Analysissubprojectwindcan::getFjjxdl).reduce(DoubleUtils::sum).get());
            windstation.setFjjxsj(windcans.stream().map(Analysissubprojectwindcan::getFjjxsj).reduce(DoubleUtils::sum).get());

            windstation.setSyzjxdl(windcans.stream().map(Analysissubprojectwindcan::getSyzjxdl).reduce(DoubleUtils::sum).get());
            windstation.setSyzjxsj(windcans.stream().map(Analysissubprojectwindcan::getSyzjxsj).reduce(DoubleUtils::sum).get());
            windstation.setJdxljx(windcans.stream().map(Analysissubprojectwindcan::getJdxljx).reduce(DoubleUtils::sum).get());
            windstation.setJdxljxsj(windcans.stream().map(Analysissubprojectwindcan::getJdxljxsj).reduce(DoubleUtils::sum).get());

            windstation.setGzcs(windcans.stream().map(Analysissubprojectwindcan::getGzcs).reduce(DoubleUtils::sum).get());
            windstation.setQpjfx(windcans.stream().map(Analysissubprojectwindcan::getQpjfx).reduce(DoubleUtils::ave).get());
            windstation.setTq(windcans.get(0).getTq());
            windstation.setDnaqts(windcans.stream().map(Analysissubprojectwindcan::getDnaqts).reduce(DoubleUtils::max).get());
            windstation.setLjaqts(windcans.stream().map(Analysissubprojectwindcan::getLjaqts).reduce(DoubleUtils::max).get());
            windstation.setZdcl(windcans.stream().map(Analysissubprojectwindcan::getZdcl).reduce(DoubleUtils::max).get());
            windstation.setZxcl(windcans.stream().map(Analysissubprojectwindcan::getZxcl).reduce(DoubleUtils::min).get());
            windstation.setFx(windcans.get(0).getFx());
            windstation.setYjhfdl(windcans.stream().map(Analysissubprojectwindcan::getYjhfdl).reduce(DoubleUtils::sum).get());
            windstation.setPjqrfs(windcans.stream().map(Analysissubprojectwindcan::getPjqrfs).reduce(DoubleUtils::ave).get());
            windstation.setEdpjfs(windcans.stream().map(Analysissubprojectwindcan::getEdpjfs).reduce(DoubleUtils::ave).get());
            windstation.setYpjkqmd(windcans.stream().map(Analysissubprojectwindcan::getYpjkqmd).reduce(DoubleUtils::ave).get());
            windstation.setLyxs(windstation.getFdl() / windstation.getZjrl());
            windstation.setLyxsscada(windstation.getFdlscada() / windstation.getZjrl());
            windstation.setLlfdl(windstation.getFdl() + windstation.getFjgzdl() + windstation.getFjjxdl() + windstation.getXddl());
            windstation.setLlfdlscada(windstation.getFdlscada() + windstation.getFjgzdl() + windstation.getFjjxdl() + windstation.getXddl());
            windstation.setQfl((windstation.getFdl() + windstation.getXddl()) != 0.0 ? windstation.getXddl() / (windstation.getFdl() + windstation.getXddl()) * 100 : 0.0);
            analysissubstationwindService.updateById(windstation);
        } else if (pvstation != null) {
            pvstation.setRzdfsqd(pvcans.stream().map(Analysissubprojectpvcan::getRzdfsqd).reduce(DoubleUtils::max).get());
            pvstation.setLjfsl(pvcans.stream().map(Analysissubprojectpvcan::getLjfsl).reduce(DoubleUtils::sum).get());

            pvstation.setXddl(pvcans.stream().map(Analysissubprojectpvcan::getXddl).reduce(DoubleUtils::sum).get());
            pvstation.setXdsj(pvcans.stream().map(Analysissubprojectpvcan::getXdsj).reduce(DoubleUtils::sum).get());

            pvstation.setGzdl(pvcans.stream().map(Analysissubprojectpvcan::getGzdl).reduce(DoubleUtils::sum).get());
            pvstation.setGzsj(pvcans.stream().map(Analysissubprojectpvcan::getGzsj).reduce(DoubleUtils::sum).get());

            pvstation.setJxdl(pvcans.stream().map(Analysissubprojectpvcan::getJxdl).reduce(DoubleUtils::sum).get());
            pvstation.setJxsj(pvcans.stream().map(Analysissubprojectpvcan::getJxsj).reduce(DoubleUtils::sum).get());

            pvstation.setRzxs(pvcans.stream().map(Analysissubprojectpvcan::getRzxs).reduce(DoubleUtils::ave).get());
            pvstation.setTq(pvcans.get(0).getTq());
            pvstation.setWd(pvcans.stream().map(Analysissubprojectpvcan::getWd).reduce(DoubleUtils::ave).get());
            pvstation.setRljfs(pvcans.stream().map(Analysissubprojectpvcan::getRljfs).reduce(DoubleUtils::sum).get());
            pvstation.setZdcl(pvcans.stream().map(Analysissubprojectpvcan::getZdcl).reduce(DoubleUtils::max).get());
            pvstation.setZxcl(pvcans.stream().map(Analysissubprojectpvcan::getZxcl).reduce(DoubleUtils::min).get());
            pvstation.setRzgwd(pvcans.stream().map(Analysissubprojectpvcan::getRzgwd).reduce(DoubleUtils::max).get());
            pvstation.setLxaqts(pvcans.stream().map(Analysissubprojectpvcan::getLxaqts).reduce(DoubleUtils::max).get());
            pvstation.setNljaqts(pvcans.stream().map(Analysissubprojectpvcan::getNljaqts).reduce(DoubleUtils::max).get());
            pvstation.setYjhfdl(pvcans.stream().map(Analysissubprojectpvcan::getYjhfdl).reduce(DoubleUtils::sum).get());
            pvstation.setLlfdl(pvstation.getFdl() + pvstation.getGzdl() + pvstation.getJxdl() + pvstation.getXddl());
            analysissubstationpvService.updateById(pvstation);
        }

    }

    /**
     * 判断是否为数字
     *
     * @param value
     * @return
     */
    private boolean isNumeric(String value) {
        Pattern pattern = Pattern.compile("[0-9]+[.]{0,1}[0-9]*[dD]{0,1}");
        Matcher isNum = pattern.matcher(value);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }
}
