package com.gyee.generation.service.StationPower;

import com.gyee.common.contant.ContantXk;
import com.gyee.common.model.PointData;
import com.gyee.common.model.StringUtils;
import com.gyee.common.util.SortUtils;
import com.gyee.generation.init.CacheContext;
import com.gyee.generation.model.auto.ProBasicPowerstation;
import com.gyee.generation.model.auto.ProBasicPowerstationPoint;
import com.gyee.generation.model.auto.ProBasicProject;
import com.gyee.generation.model.auto.ProEconStationPower;
import com.gyee.generation.service.auto.impl.ProEconStationPowerServiceImpl;
import com.gyee.generation.util.DateUtils;
import com.gyee.generation.util.math.PowerCalculator;
import com.gyee.generation.util.math.PowerIntegration;
import com.gyee.generation.util.math.ShortTermPowerPredictionAccuracyCalculator;
import com.gyee.generation.util.realtimesource.IEdosUtil;
import com.gyee.generation.util.realtimesource.timeseries.ForecastVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;

@Service
public class StationPowerService {

    @Resource
    private IEdosUtil edosUtil;

    @Resource
    private ShortTermPowerPredictionAccuracyCalculator shortTermPowerPredictionAccuracyCalculator;

    @Resource
    private PowerIntegration powerIntegration;
    @Resource
    private PowerCalculator powerCalculator;
    @Resource
    private ProEconStationPowerServiceImpl powerService;

    public void predictedPower() throws Exception {

        String type = "F";
        Map<String, Map<String, ProBasicPowerstationPoint>> linepointmap = CacheContext.linepointmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> propointmap = CacheContext.propointmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> wppointmap = CacheContext.wppointmap;

        // 获取当前日期
        Date currentDate = new Date();

        // 创建 Calendar 对象，并设置为当前日期
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(currentDate);

        // 将时间设为0点
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        // 设置 beginDate 为前一天的0点
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        Date beginDate = calendar.getTime();

        // 设置 endDate 为当天的0点
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        Date endDate = calendar.getTime();

        String wpId = null;

        for (int g = 0; g <= 3; g++) {

            List<ProBasicProject> pjls = CacheContext.pjls;

            List<ProBasicProject> pjllist = null;

            List<ProBasicPowerstation> wplLs = CacheContext.wpls;
            SortUtils.sort(wplLs, "orderNum", SortUtils.ASC);

            List<ForecastVo> vos = null;
            Map<String, Object> map = new LinkedHashMap<>();
            ProBasicPowerstationPoint ycgl = null;
            ProBasicPowerstationPoint sjgl = null;

            for (ProBasicPowerstation Wp : wplLs) {
                if (Wp.getId().contains("MLJ")) continue;
                wpId = Wp.getId();
                pjllist = new ArrayList();
                //得到此循环场站期次
                for (ProBasicProject pj : pjls) {
                    if (wpId.equals(pj.getWindpowerstationId())) {
                        pjllist.add(pj);
                    }
                }

                List<ProBasicPowerstation> station = new ArrayList<>();
                for (ProBasicPowerstation wp1 : CacheContext.wpls) {
                    if (wpId.equals(wp1.getId())) {
                        station.add(wp1);
                    }
                }

                if (wpId.contains("GJY") | wpId.contains("TZ_GDC_STA") | wpId.contains("PTZ_FDC_STA") | wpId.contains("NJL") | wpId.contains("SY")) {
                    for (ProBasicProject wp : pjllist) {
                        Map<String, ProBasicPowerstationPoint> propointMap = propointmap.get(wp.getId());
                        List<ForecastVo> vos1 = new ArrayList<>();
                        List<ForecastVo> vos2 = new ArrayList<>();
                        List<ForecastVo> vos3 = new ArrayList<>();
                        List<ForecastVo> vos4 = new ArrayList<>();
                        List<ForecastVo> vos5 = new ArrayList<>();

                        // 在每次循环开始前将变量置为null
                        ycgl = null;
                        sjgl = null;

                        if (wpId.endsWith("FDC_STA") && type.equals("F")) {
                            ycgl = propointMap.get(ContantXk.GLYC);
                            sjgl = propointMap.get(ContantXk.SSZGL);
                        }
                        if (wpId.endsWith("GDC_STA") && type.equals("G")) {
                            ycgl = propointMap.get(ContantXk.GLYC);
                            sjgl = propointMap.get(ContantXk.SSZGL);
                        }

                        if (ycgl != null && sjgl != null) {

                            List<PointData> ycglls = edosUtil.getHistoryDatasSnap(ycgl, beginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L);
                            List<PointData> sjglls = edosUtil.getHistoryDatasSnap(sjgl, beginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L);


                            double temp1 = 0;
                            double temp2 = 0;
                            double temp3 = 0;
                            double temp4 = 0;
                            double temp5 = 0;

                            if (wp.getId().contains("SXJ_KGDL_GJYF01_EG") || wp.getId().equals("SXJ_KGDL_GJYF03_EG")) {
                                for (int i = 0; i < ycglls.size(); i++) {
                                    ForecastVo vo = new ForecastVo();
                                    //
                                    vo.setSjgl(0.0); //实际功率
                                    vo.setYcgl(0.0); //功率预测
                                    //
                                    vo.setHours(2023L);  //时间戳
                                    vo.setName(wpId);

                                    vo.setHours(ycglls.get(i).getPointTime());
                                    vo.setName("平鲁高家堰风电场");

                                    vo.setId(wpId);

                                    if (ycglls != null && !ycglls.isEmpty() && i < ycglls.size() && ycglls.get(i).getPointName() != null) {
                                        temp3 = ycglls.get(i).getPointValueInDouble();
                                        vo.setYcgl(StringUtils.round(temp3, 2));
                                    }
                                    if (sjglls != null && !sjglls.isEmpty() && i < sjglls.size() && sjglls.get(i).getPointName() != null) {
                                        temp4 = sjglls.get(i).getPointValueInDouble();
                                        vo.setSjgl(StringUtils.round(temp4 / 1000, 2));
                                    }

                                    vos1.add(vo);
                                }
                            } else if (wp.getId().contains("SXJ_KGDL_GJYF02_EG")) {
                                for (int i = 0; i < ycglls.size(); i++) {
                                    ForecastVo vo = new ForecastVo();

                                    vo.setSjgl(0.0); //实际功率
                                    vo.setYcgl(0.0); //功率预测
                                    vo.setHours(2023L);  //时间戳
                                    vo.setName(wpId);

                                    vo.setHours(ycglls.get(i).getPointTime());
                                    vo.setName("平鲁高家堰风电场");

                                    vo.setId(wpId);


                                    if (ycglls != null && !ycglls.isEmpty() && i < ycglls.size() && ycglls.get(i).getPointName() != null) {
                                        temp3 = ycglls.get(i).getPointValueInDouble();
                                        vo.setYcgl(StringUtils.round(temp3, 2));
                                    }
                                    if (sjglls != null && !sjglls.isEmpty() && i < sjglls.size() && sjglls.get(i).getPointName() != null) {
                                        temp4 = sjglls.get(i).getPointValueInDouble();
                                        vo.setSjgl(StringUtils.round(temp4 / 1000, 2));
                                    }

                                    vos1.add(vo);
                                }
                            }

                            if (wp.getId().contains("SXJ_KGDL_TZG01_EG") || wp.getId().contains("SXJ_KGDL_TZG05_EG")) {
                                for (int i = 0; i < ycglls.size(); i++) {
                                    ForecastVo vo2 = new ForecastVo();

                                    vo2.setSjgl(0.0); //实际功率
                                    vo2.setYcgl(0.0); //功率预测

                                    vo2.setHours(2023L);  //时间戳
                                    vo2.setName(wpId);

                                    vo2.setHours(ycglls.get(i).getPointTime());
                                    vo2.setName("天镇电站");
                                    vo2.setId(wpId);


                                    if (ycglls != null && !ycglls.isEmpty() && i < ycglls.size() && ycglls.get(i).getPointName() != null) {
                                        temp3 = ycglls.get(i).getPointValueInDouble();
                                        vo2.setYcgl(StringUtils.round(temp3, 2));
                                    }

                                    if (sjglls != null && !sjglls.isEmpty() && i < sjglls.size() && sjglls.get(i).getPointName() != null) {
                                        temp4 = sjglls.get(i).getPointValueInDouble();
                                        vo2.setSjgl(StringUtils.round(temp4 / 1000, 2));
                                    }


                                    vos2.add(vo2);
                                }
                            } else if (wpId.contains("TZ_GDC_STA")) {
                                for (int i = 0; i < ycglls.size(); i++) {
                                    ForecastVo vo2 = new ForecastVo();

                                    vo2.setSjgl(0.0); //实际功率
                                    vo2.setYcgl(0.0); //功率预测
                                    vo2.setHours(2023L);  //时间戳
                                    vo2.setName(wpId);

                                    vo2.setHours(ycglls.get(i).getPointTime());
                                    vo2.setName("天镇电站");
                                    vo2.setId(wpId);


                                    if (ycglls != null && !ycglls.isEmpty() && i < ycglls.size() && ycglls.get(i).getPointName() != null) {
                                        temp3 = ycglls.get(i).getPointValueInDouble();
                                        vo2.setYcgl(StringUtils.round(temp3, 2));
                                    }

                                    if (sjglls != null && !sjglls.isEmpty() && i < sjglls.size() && sjglls.get(i).getPointName() != null) {
                                        temp4 = sjglls.get(i).getPointValueInDouble();
                                        vo2.setSjgl(StringUtils.round(temp4 / 1000, 2));
                                    }


                                    vos2.add(vo2);
                                }
                            }

                            if (wpId.contains("PTZ_FDC_STA")) {
                                for (int i = 0; i < ycglls.size(); i++) {
                                    ForecastVo vo3 = new ForecastVo();

                                    vo3.setSjgl(0.0); //实际功率
                                    vo3.setYcgl(0.0); //功率预测
                                    vo3.setHours(2023L);  //时间戳
                                    vo3.setName(wpId);

                                    vo3.setHours(ycglls.get(i).getPointTime());

                                    vo3.setName("寿阳平头镇风电场");

                                    vo3.setId(wpId);


                                    if (ycglls != null && !ycglls.isEmpty() && i < ycglls.size() && ycglls.get(i).getPointName() != null) {
                                        temp3 = ycglls.get(i).getPointValueInDouble();
                                        vo3.setYcgl(StringUtils.round(temp3, 2));
                                    }
                                    if (sjglls != null && !sjglls.isEmpty() && i < sjglls.size() && sjglls.get(i).getPointName() != null) {
                                        temp4 = sjglls.get(i).getPointValueInDouble();
                                        vo3.setSjgl(StringUtils.round(temp4 / 1000, 2));
                                    }

                                    vos3.add(vo3);
                                }
                            }

                            if (wpId.contains("NJL")) {
                                for (int i = 0; i < ycglls.size(); i++) {
                                    ForecastVo vo4 = new ForecastVo();

                                    vo4.setSjgl(0.0); //实际功率
                                    vo4.setYcgl(0.0); //功率预测
                                    vo4.setHours(2023L);  //时间戳
                                    vo4.setName(wpId);

                                    vo4.setHours(ycglls.get(i).getPointTime());

                                    vo4.setName("朔城牛家岭风电场");

                                    vo4.setId(wpId);

                                    if (ycglls != null && !ycglls.isEmpty() && i < ycglls.size() && ycglls.get(i).getPointName() != null) {
                                        temp3 = ycglls.get(i).getPointValueInDouble();
                                        vo4.setYcgl(StringUtils.round(temp3, 2));
                                    }

                                    if (sjglls != null && !sjglls.isEmpty() && i < sjglls.size() && sjglls.get(i).getPointName() != null) {
                                        temp4 = sjglls.get(i).getPointValueInDouble();
                                        vo4.setSjgl(StringUtils.round(temp4 / 1000, 2));
                                    }


                                    vos4.add(vo4);
                                }
                            }

                            if (wpId.contains("SY")) {
                                for (int i = 0; i < ycglls.size(); i++) {
                                    ForecastVo vo5 = new ForecastVo();

                                    vo5.setSjgl(0.0); //实际功率
                                    vo5.setYcgl(0.0); //功率预测
                                    vo5.setHours(2023L);  //时间戳
                                    vo5.setName(wpId);

                                    vo5.setHours(ycglls.get(i).getPointTime());
                                    vo5.setName("山阴电站");
                                    vo5.setId(wpId);

                                    if (ycglls != null && !ycglls.isEmpty() && i < ycglls.size() && ycglls.get(i).getPointName() != null) {
                                        temp3 = ycglls.get(i).getPointValueInDouble();
                                        vo5.setYcgl(StringUtils.round(temp3, 2));
                                    }
                                    if (sjglls != null && !sjglls.isEmpty() && i < sjglls.size() && sjglls.get(i).getPointName() != null) {
                                        temp4 = sjglls.get(i).getPointValueInDouble();
                                        vo5.setSjgl(StringUtils.round(temp4 / 1000, 2));
                                    }

                                    vos5.add(vo5);
                                }
                            }


                            if (wpId.contains("GJY")) {
                                if (map.containsKey("SXJ_KGDL_GJY_FDC_STA")) {
                                    List<ForecastVo> previousVos1 = (List<ForecastVo>) map.get("SXJ_KGDL_GJY_FDC_STA");
                                    List<ForecastVo> currentVos1 = vos1; // 新建一个currentVos1列表来保存当前数据

                                    if (previousVos1.size() != currentVos1.size()) {
                                        int sizeDiff = Math.abs(previousVos1.size() - currentVos1.size());
                                        if (previousVos1.size() > currentVos1.size()) {
                                            // 如果previousVos1.size()大于currentVos1.size()
                                            // 添加缺失的currentVo1对象到currentVos1列表中
                                            for (int i = 0; i < sizeDiff; i++) {
                                                currentVos1.add(null);
                                            }
                                        } else {
                                            // 如果previousVos1.size()小于currentVos1.size()
                                            // 添加缺失的previousVo1对象到previousVos1列表中
                                            for (int i = 0; i < sizeDiff; i++) {
                                                previousVos1.add(null);
                                            }
                                        }
                                    }

                                    for (int i = 0; i < previousVos1.size(); i++) {
                                        ForecastVo previousVo1 = previousVos1.get(i);
                                        ForecastVo currentVo1 = currentVos1.get(i);
                                        if (previousVo1 != null && currentVo1 != null) {
                                            if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                                currentVo1.setSjgl(StringUtils.round(previousVo1.getSjgl() + currentVo1.getSjgl(), 2));
                                            }
                                            if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                                currentVo1.setYcgl(StringUtils.round(previousVo1.getYcgl() + currentVo1.getYcgl(), 2));
                                            }
                                        }
                                    }
                                }
                            } else if (wpId.contains("TZ_GDC_STA")) {
                                if (map.containsKey("SXJ_KGDL_TZ_GDC_STA")) {
                                    List<ForecastVo> previousVos1 = (List<ForecastVo>) map.get("SXJ_KGDL_TZ_GDC_STA");
                                    List<ForecastVo> currentVos1 = vos2; // 新建一个currentVos1列表来保存当前数据

                                    if (previousVos1.size() != currentVos1.size()) {
                                        int sizeDiff = Math.abs(previousVos1.size() - currentVos1.size());
                                        if (previousVos1.size() > currentVos1.size()) {
                                            // 如果previousVos1.size()大于currentVos1.size()
                                            // 添加缺失的currentVo1对象到currentVos1列表中
                                            for (int i = 0; i < sizeDiff; i++) {
                                                currentVos1.add(null);
                                            }
                                        } else {
                                            // 如果previousVos1.size()小于currentVos1.size()
                                            // 添加缺失的previousVo1对象到previousVos1列表中
                                            for (int i = 0; i < sizeDiff; i++) {
                                                previousVos1.add(null);
                                            }
                                        }
                                    }

                                    for (int i = 0; i < previousVos1.size(); i++) {
                                        ForecastVo previousVo1 = previousVos1.get(i);
                                        ForecastVo currentVo1 = currentVos1.get(i);
                                        if (previousVo1 != null && currentVo1 != null) {

                                            if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                                currentVo1.setSjgl(StringUtils.round(previousVo1.getSjgl() + currentVo1.getSjgl(), 2));
                                            }
                                            if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                                currentVo1.setYcgl(StringUtils.round(previousVo1.getYcgl() + currentVo1.getYcgl(), 2));
                                            }

                                        }
                                    }
                                }
                            } else if (wpId.contains("SY")) {
                                if (map.containsKey("SXJ_KGDL_SY_GDC_STA")) {
                                    List<ForecastVo> previousVos1 = (List<ForecastVo>) map.get("SXJ_KGDL_SY_GDC_STA");
                                    for (int i = 0; i < vos5.size(); i++) {
                                        ForecastVo previousVo1 = previousVos1.get(i);
                                        ForecastVo currentVo1 = vos5.get(i);
                                        if (previousVo1 != null && currentVo1 != null) {

                                            if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                                currentVo1.setSjgl(StringUtils.round(previousVo1.getSjgl() + currentVo1.getSjgl(), 2));
                                            }
                                            if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                                currentVo1.setYcgl(StringUtils.round(previousVo1.getYcgl() + currentVo1.getYcgl(), 2));
                                            }

                                        }
                                    }
                                }
                            } else if (wpId.contains("NJL")) {
                                if (map.containsKey("SXJ_KGDL_NJL_FDC_STA")) {
                                    List<ForecastVo> previousVos1 = (List<ForecastVo>) map.get("SXJ_KGDL_NJL_FDC_STA");
                                    for (int i = 0; i < vos4.size(); i++) {
                                        ForecastVo previousVo1 = previousVos1.get(i);
                                        ForecastVo currentVo1 = vos4.get(i);
                                        if (previousVo1 != null && currentVo1 != null) {

                                            if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                                currentVo1.setSjgl(StringUtils.round(previousVo1.getSjgl() + currentVo1.getSjgl(), 2));
                                            }
                                            if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                                currentVo1.setYcgl(StringUtils.round(previousVo1.getYcgl() + currentVo1.getYcgl(), 2));
                                            }

                                        }
                                    }
                                }
                            } else if (wpId.contains("PTZ_FDC_STA")) {
                                if (map.containsKey("SXJ_KGDL_PTZ_FDC_STA")) {
                                    List<ForecastVo> previousVos1 = (List<ForecastVo>) map.get("SXJ_KGDL_PTZ_FDC_STA");
                                    for (int i = 0; i < vos3.size(); i++) {
                                        ForecastVo previousVo1 = previousVos1.get(i);
                                        ForecastVo currentVo1 = vos3.get(i);
                                        if (previousVo1 != null && currentVo1 != null) {
                                            if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                                currentVo1.setSjgl(StringUtils.round(previousVo1.getSjgl() + currentVo1.getSjgl(), 2));
                                            }
                                            if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                                currentVo1.setYcgl(StringUtils.round(previousVo1.getYcgl() + currentVo1.getYcgl(), 2));
                                            }

                                        }
                                    }
                                }
                            }

                            if (wpId.contains("GJY")) {
                                map.put("SXJ_KGDL_GJY_FDC_STA", vos1);

                            }
                            if (wpId.contains("NJL")) {
                                map.put("SXJ_KGDL_NJL_FDC_STA", vos4);

                            }
                            if (wpId.contains("PTZ_FDC_STA")) {
                                map.put("SXJ_KGDL_PTZ_FDC_STA", vos3);

                            }

                            if (wpId.contains("TZ_GDC_STA")) {
                                map.put("SXJ_KGDL_TZ_GDC_STA", vos2);
                            }

                            if (wpId.contains("SY")) {
                                map.put("SXJ_KGDL_SY_GDC_STA", vos5);
                            }

                        }
                    }

                } else {
                    for (ProBasicPowerstation wp : station) {
                        vos = new ArrayList<>();

                        Map<String, ProBasicPowerstationPoint> proBasicWppointMap = wppointmap.get(wp.getId());
                        ProBasicPowerstationPoint ycgl1 = null;
                        ProBasicPowerstationPoint sjgl1 = null;

                        if (wpId.endsWith("FDC_STA") && type.equals("F")) {
                            ycgl1 = proBasicWppointMap.get(ContantXk.GLYC);
                            sjgl1 = proBasicWppointMap.get(ContantXk.SSZGL);
                        }
                        if (wpId.endsWith("GDC_STA") && type.equals("G")) {
                            ycgl1 = proBasicWppointMap.get(ContantXk.GLYC);
                            sjgl1 = proBasicWppointMap.get(ContantXk.SSZGL);
                        }
                        if (ycgl1 != null && sjgl1 != null) {

                            List<PointData> ycglls = edosUtil.getHistoryDatasSnap(ycgl1, beginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L);
                            List<PointData> sjglls = edosUtil.getHistoryDatasSnap(sjgl1, beginDate.getTime() / 1000, endDate.getTime() / 1000, null, 900L);
                            double temp1 = 0;
                            double temp2 = 0;
                            double temp3 = 0;
                            double temp4 = 0;
                            double temp5 = 0;
                            for (int i = 0; i < ycglls.size(); i++) {

                                ForecastVo vo = new ForecastVo();
                                vo.setSjgl(0.0); //实际功率
                                vo.setYcgl(0.0); //功率预测

                                vo.setHours(2023L);  //时间戳
                                vo.setName(wpId);


                                if (ycglls != null && !ycglls.isEmpty() && i < ycglls.size() && ycglls.get(i).getPointName() != null) {
                                    temp3 = ycglls.get(i).getPointValueInDouble();
                                    vo.setYcgl(StringUtils.round(temp3, 2));
                                }
                                if (sjglls != null && !sjglls.isEmpty() && i < sjglls.size() && sjglls.get(i).getPointName() != null) {
                                    temp4 = sjglls.get(i).getPointValueInDouble();
                                    vo.setSjgl(StringUtils.round(temp4 / 1000, 2));
                                }
                                vo.setHours(ycglls.get(i).getPointTime());

                                vo.setName(wp.getAname());
                                vo.setId(wpId);

                                vos.add(vo);
                            }
                            map.put(wp.getId(), vos);

                        }
                    }
                }
            }

            List<ProEconStationPower> stringList = new ArrayList<>();

            for (Map.Entry<String, Object> entry : map.entrySet()) {
                String key = entry.getKey();

                List<ProBasicPowerstation> powerstations = CacheContext.wpls;
                for (ProBasicPowerstation p1 : powerstations) {
                    if (key.equals(p1.getId())) {
                        ArrayList<ForecastVo> forecastVos = (ArrayList<ForecastVo>) entry.getValue();

                        //                        Map<Integer,Double> gl = new TreeMap<>();
                        List<Double> gl = new ArrayList<>();
                        double[] sjglarr = new double[forecastVos.size()];
                        double[] ycglarr = new double[forecastVos.size()];
                        double dlycTotal = 0.0; // 累加的总值
                        for (int i = 0; i < forecastVos.size(); i++) {
                            ForecastVo forecastVo = forecastVos.get(i);
                            sjglarr[i] = forecastVo.getSjgl();
                            ycglarr[i] = forecastVo.getYcgl();

                            gl.add(i, forecastVo.getYcgl());
                            double dlyc = 24.0 * forecastVo.getYcgl() / forecastVos.size(); // 每次循环的值
                            dlycTotal += dlyc; // 累加每次循环的值
                        }
                        double Capacity = p1.getJrwindCapacity();
                        double Capacity1 = p1.getJrwindCapacity() / 1000;
                        double maxgl = Capacity * 1.5 / 1000;
                        //                        double energy = powerIntegration.calculateEnergy(gl, 0.25);
                        double energy = powerCalculator.updateTheoryGeneration(gl, 24, maxgl);


                        double accuracy = shortTermPowerPredictionAccuracyCalculator.calculateAccuracy(ycglarr, sjglarr, Capacity1);

                        ProEconStationPower power = new ProEconStationPower();
                        power.setId(StringUtils.getUUID());
                        power.setPowerAccuracy(BigDecimal.valueOf(accuracy));
                        power.setWindpowerstationId(p1.getId());
                        power.setRecordDate(beginDate);
                        power.setDayPowerForecast(BigDecimal.valueOf(energy * 1000));
                        stringList.add(power);
                        powerService.batchAdd(stringList);
                    }
                }
            }
            beginDate = DateUtils.addDays(beginDate, +1);
            calendar.add(Calendar.DAY_OF_MONTH, +1);
            endDate = calendar.getTime();
        }
    }
}
