package com.gyee.runeconomy.service.Forecast;

import com.gyee.common.contant.ContantXk;
import com.gyee.common.model.PointData;
import com.gyee.common.util.DateUtils;
import com.gyee.common.util.SortUtils;
import com.gyee.runeconomy.dto.ForecastVo;
import com.gyee.runeconomy.init.CacheContext;
import com.gyee.runeconomy.model.auto.ProBasicPowerstation;
import com.gyee.runeconomy.model.auto.ProBasicPowerstationPoint;
import com.gyee.runeconomy.model.auto.ProBasicProject;
import com.gyee.runeconomy.service.TokenService;
import com.gyee.runeconomy.service.auto.IProBasicPowerstationPointService;
import com.gyee.runeconomy.util.MathUtil;
import com.gyee.runeconomy.util.StringUtils;
import com.gyee.runeconomy.util.realtimesource.IEdosUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

@Service
public class ForecastService {

    @Resource
    private IEdosUtil edosUtil;
    @Resource
    private TokenService tokenService;
    @Resource
    private IProBasicPowerstationPointService proBasicPowerstationPointService;

    public Map<String, Object> getcockpit(String wpId, String beginDate, String endDate) throws Exception {

        Date starttime = DateUtils.parseDate(beginDate);
        Date endtime = DateUtils.parseDate(endDate);
        Date currentDate = new Date();
        List<ProBasicPowerstation> station = new ArrayList<>();
        for (ProBasicPowerstation wp1 : CacheContext.wpls) {
            if (wpId.equals(wp1.getId())) {
                station.add(wp1);
            }
        }

        List<ProBasicProject> pjls = CacheContext.pjls;

        List<ProBasicProject> pjllist = new ArrayList<>();

        for (ProBasicProject pj : pjls) {
            if (wpId.equals(pj.getWindpowerstationId())) {
                pjllist.add(pj);
            }
        }

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

        if (wpId.contains("PTZ") | wpId.contains("NJL") | wpId.contains("SY")) {
            for (ProBasicProject wp : pjllist) {
                vos = new ArrayList<>();
                if (wpId.endsWith("FDC_STA")) {
                    pjfs = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSPJFS);
                    ycgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GLYC);
                    sjgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZGL);
                    llgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZLLGL);
                    fsyc = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.FSYC);
                }
                if (wpId.endsWith("GDC_STA")) {
                    pjfs = proBasicPowerstationPointService.getPowerstationPoint(wp.getWindpowerstationId(), ContantXk.GCGZQD);
                    fsyc = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GZYC);
                    ycgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GLYC);
                    sjgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZGL);
                    llgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZLLGL);
                }
                List<PointData> pjfsls = edosUtil.getHistoryDatasSnap(pjfs, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                List<PointData> fsycls = edosUtil.getHistoryDatasSnap(fsyc, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                List<PointData> ycglls = edosUtil.getHistoryDatasSnap(ycgl, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                List<PointData> sjglls = edosUtil.getHistoryDatasSnap(sjgl, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                List<PointData> llglls = edosUtil.getHistoryDatasSnap(llgl, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                double temp1 = 0;
                double temp2 = 0;
                double temp3 = 0;
                double temp4 = 0;
                double temp5 = 0;
                for (int i = 0; i < fsycls.size(); i++) {

                    ForecastVo vo = new ForecastVo();
                    //                    vo.setPjfs(0.0); //平均风速
                    vo.setYcfs(0.0); //预测风速
                    //                    vo.setSjgl(0.0); //实际功率
                    vo.setYcgl(0.0); //功率预测
                    //                    vo.setLlgl(0.0); //理论功率
                    vo.setHours(2023L);  //时间戳
                    vo.setName(wpId);

                    if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                        temp1 = pjfsls.get(i).getPointValueInDouble();
                        vo.setPjfs(StringUtils.round(temp1, 2));
                    }

                    if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                        temp2 = fsycls.get(i).getPointValueInDouble();
                        vo.setYcfs(StringUtils.round(temp2, 2));
                    }
                    if (ycglls != null && !ycglls.isEmpty() && ycglls.get(0).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));
                    }
                    if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                        temp5 = llglls.get(i).getPointValueInDouble();
                        vo.setLlgl(StringUtils.round(temp5 / 1000, 2));
                    }
                    vo.setHours(fsycls.get(i).getPointTime());

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

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


        } else if (wpId.contains("GJY") | wpId.contains("TZ")) {
            for (ProBasicProject wp : pjllist) {
                List<ForecastVo> vos1 = new ArrayList<>();
                List<ForecastVo> vos2 = new ArrayList<>();
                if (wpId.endsWith("FDC_STA")) {
                    pjfs = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSPJFS);
                    ycgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GLYC);
                    sjgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZGL);
                    llgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZLLGL);
                    fsyc = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.FSYC);
                }
                if (wpId.endsWith("GDC_STA")) {
                    pjfs = proBasicPowerstationPointService.getPowerstationPoint(wp.getWindpowerstationId(), ContantXk.GCGZQD);
                    fsyc = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GZYC);
                    ycgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GLYC);
                    sjgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZGL);
                    llgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZLLGL);
                }
                List<PointData> pjfsls = edosUtil.getHistoryDatasSnap(pjfs, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                List<PointData> fsycls = edosUtil.getHistoryDatasSnap(fsyc, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                List<PointData> ycglls = edosUtil.getHistoryDatasSnap(ycgl, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                List<PointData> sjglls = edosUtil.getHistoryDatasSnap(sjgl, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                List<PointData> llglls = edosUtil.getHistoryDatasSnap(llgl, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);


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

                //不包含高家堰三期和天镇五期进入此循环（方便进行后续累加）
                if (!wp.getId().equals("SXJ_KGDL_GJYF03_EG") && !wp.getId().equals("SXJ_KGDL_TZG05_EG") && wp.getId().contains("01")) {

                    for (int i = 0; i < fsycls.size(); i++) {
                        ForecastVo vo = new ForecastVo();
                        //                        vo.setPjfs(0.0); //平均风速
                        vo.setYcfs(0.0); //预测风速
                        //                        vo.setSjgl(0.0); //实际功率
                        vo.setYcgl(0.0); //功率预测
                        //                        vo.setLlgl(0.0); //理论功率
                        vo.setHours(2023L);  //时间戳
                        vo.setName(wpId);

                        vo.setHours(fsycls.get(i).getPointTime());
                        if (wpId.contains("GJY")) {
                            vo.setName("平鲁高家堰一期项目");
                        } else if (wpId.contains("TZ")) {
                            vo.setName("天镇一期项目");
                        }
                        vo.setId(wpId);

                        if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                            temp1 = pjfsls.get(i).getPointValueInDouble();
                            vo.setPjfs(StringUtils.round(temp1, 2));
                        }

                        if (ycglls != null && !ycglls.isEmpty() && ycglls.get(0).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));
                        }

                        if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                            temp5 = llglls.get(i).getPointValueInDouble();
                            vo.setLlgl(StringUtils.round(temp5 / 1000, 2));
                        }
                        if (fsycls.size() == ycglls.size()) {
                            if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                temp2 = fsycls.get(i).getPointValueInDouble();
                                vo.setYcfs(StringUtils.round(temp2, 2));
                            }
                        }

                        vos1.add(vo);
                    }
                } else if (wp.getId().equals("SXJ_KGDL_GJYF03_EG") || wp.getId().equals("SXJ_KGDL_TZG05_EG")) {
                    for (int i = 0; i < fsycls.size(); i++) {

                        ForecastVo vo1 = new ForecastVo();
                        //                        vo1.setPjfs(0.0); //平均风速
                        vo1.setYcfs(0.0); //预测风速
                        //                        vo1.setSjgl(0.0); //实际功率
                        vo1.setYcgl(0.0); //功率预测
                        //                        vo1.setLlgl(0.0); //理论功率
                        vo1.setHours(2023L);  //时间戳
                        vo1.setName(wpId);

                        vo1.setHours(fsycls.get(i).getPointTime());
                        vo1.setName(wp.getAname());
                        vo1.setId(wpId);

                        if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                            temp1 = pjfsls.get(i).getPointValueInDouble();
                            vo1.setPjfs(StringUtils.round(temp1, 2));
                        }

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

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

                        if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                            temp5 = llglls.get(i).getPointValueInDouble();
                            vo1.setLlgl(StringUtils.round(temp5 / 1000, 2));
                        }
                        if (fsycls.size() == ycglls.size()) {
                            if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                temp2 = fsycls.get(i).getPointValueInDouble();
                                vo1.setYcfs(StringUtils.round(temp2, 2));
                            }
                        }
                        vos2.add(vo1);
                    }
                } else {
                    for (int i = 0; i < pjfsls.size(); i++) {
                        ForecastVo vo = new ForecastVo();
                        //                        vo.setPjfs(0.0); //平均风速
                        vo.setYcfs(0.0); //预测风速
                        //                        vo.setSjgl(0.0); //实际功率
                        vo.setYcgl(0.0); //功率预测
                        //                        vo.setLlgl(0.0); //理论功率
                        vo.setHours(2023L);  //时间戳
                        vo.setName(wpId);

                        vo.setHours(pjfsls.get(i).getPointTime());
                        if (wpId.contains("GJY")) {
                            vo.setName("平鲁高家堰一期项目");
                        } else if (wpId.contains("TZ")) {
                            vo.setName("天镇一期项目");
                        }
                        vo.setId(wpId);

                        if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                            temp1 = pjfsls.get(i).getPointValueInDouble();
                            vo.setPjfs(StringUtils.round(temp1, 2));
                        }

                        if (ycglls != null && !ycglls.isEmpty() && ycglls.get(0).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));
                        }

                        if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                            temp5 = llglls.get(i).getPointValueInDouble();
                            vo.setLlgl(StringUtils.round(temp5 / 1000, 2));
                        }
                        if (fsycls.size() == ycglls.size()) {
                            if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                temp2 = fsycls.get(i).getPointValueInDouble();
                                vo.setYcfs(StringUtils.round(temp2, 2));
                            }
                        }

                        vos1.add(vo);
                    }
                }


                if (wpId.contains("GJY")) {
                    if (map.containsKey("SXJ_KGDL_GJYF01_EG") && !wp.getId().equals("SXJ_KGDL_GJYF03_EG")) {
                        List<ForecastVo> previousVos1 = (List<ForecastVo>) map.get("SXJ_KGDL_GJYF01_EG");
                        List<ForecastVo> mergedVos1 = new ArrayList<>();  // 用于保存合并后的数据
                        int minLength = Math.min(previousVos1.size(), vos1.size());
                        for (int i = 0; i < minLength; i++) {
                            ForecastVo previousVo1 = previousVos1.get(i);
                            ForecastVo currentVo1 = vos1.get(i);
                            if (previousVo1.getHours() == currentVo1.getHours()) {
                                ForecastVo mergedVo = new ForecastVo();
                                mergedVo.setHours(previousVo1.getHours());
                                mergedVo.setPjfs(MathUtil.twoBit(previousVo1.getPjfs() + currentVo1.getPjfs() / 2));
                                mergedVo.setYcfs(MathUtil.twoBit(previousVo1.getYcfs() + currentVo1.getYcfs()));
                                mergedVo.setSjgl(MathUtil.twoBit(previousVo1.getSjgl() + currentVo1.getSjgl()));
                                mergedVo.setYcgl(MathUtil.twoBit(previousVo1.getYcgl() + currentVo1.getYcgl()));
                                mergedVo.setLlgl(MathUtil.twoBit(previousVo1.getLlgl() + currentVo1.getLlgl()));
                                mergedVos1.add(mergedVo);
                            }
                        }
                        // 将previousVos1中剩余的元素添加到mergedVos1中
                        for (int i = minLength; i < previousVos1.size(); i++) {
                            mergedVos1.add(previousVos1.get(i));
                        }
                        vos1 = previousVos1;
                    }
                } else if (wpId.contains("TZ")) {
                    if (map.containsKey("SXJ_KGDL_TZG01_EG") && !wp.getId().equals("SXJ_KGDL_TZG05_EG")) {
                        List<ForecastVo> previousVos1 = (List<ForecastVo>) map.get("SXJ_KGDL_TZG01_EG");
                        List<ForecastVo> mergedVos1 = new ArrayList<>();  // 用于保存合并后的数据
                        int minLength = Math.min(previousVos1.size(), vos1.size());
                        for (int i = 0; i < minLength; i++) {
                            ForecastVo previousVo1 = previousVos1.get(i);
                            ForecastVo currentVo1 = vos1.get(i);
                            if (previousVo1.getHours() == currentVo1.getHours()) {
                                ForecastVo mergedVo = new ForecastVo();
                                mergedVo.setHours(previousVo1.getHours());
                                mergedVo.setPjfs(MathUtil.twoBit(previousVo1.getPjfs() + currentVo1.getPjfs() / 2));
                                mergedVo.setYcfs(MathUtil.twoBit(previousVo1.getYcfs() + currentVo1.getYcfs()));
                                mergedVo.setSjgl(MathUtil.twoBit(previousVo1.getSjgl() + currentVo1.getSjgl()));
                                mergedVo.setYcgl(MathUtil.twoBit(previousVo1.getYcgl() + currentVo1.getYcgl()));
                                mergedVo.setLlgl(MathUtil.twoBit(previousVo1.getLlgl() + currentVo1.getLlgl()));
                                mergedVos1.add(mergedVo);
                            }
                        }
                        // 将previousVos1中剩余的元素添加到mergedVos1中
                        for (int i = minLength; i < previousVos1.size(); i++) {
                            mergedVos1.add(previousVos1.get(i));
                        }
                        vos1 = previousVos1;
                    }
                }
                if (wpId.contains("GJY")) {
                    if (!wp.getId().equals("SXJ_KGDL_GJYF03_EG")) {
                        map.put("SXJ_KGDL_GJYF01_EG", vos1);
                    }
                }

                if (wpId.contains("TZ")) {
                    if (!wp.getId().equals("SXJ_KGDL_TZG05_EG")) {
                        map.put("SXJ_KGDL_TZG01_EG", vos1);
                    }
                }

                if (wp.getId().equals("SXJ_KGDL_GJYF03_EG") | wp.getId().equals("SXJ_KGDL_TZG05_EG")) {
                    map.put(wp.getId(), vos2);
                }
            }

        } else {
            for (ProBasicPowerstation wp : station) {
                vos = new ArrayList<>();
                if (wpId.endsWith("FDC_STA")) {
                    pjfs = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSPJFS);
                    fsyc = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.FSYC);
                    ycgl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.GLYC);
                    sjgl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZGL);
                    llgl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZLLGL);
                }
                if (wpId.endsWith("GDC_STA")) {
                    pjfs = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.GCGZQD);
                    fsyc = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.GZYC);
                    ycgl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.GLYC);
                    sjgl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZGL);
                    llgl = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZLLGL);
                }
                List<PointData> pjfsls = edosUtil.getHistoryDatasSnap(pjfs, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                List<PointData> fsycls = edosUtil.getHistoryDatasSnap(fsyc, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                List<PointData> ycglls = edosUtil.getHistoryDatasSnap(ycgl, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                List<PointData> sjglls = edosUtil.getHistoryDatasSnap(sjgl, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                List<PointData> llglls = edosUtil.getHistoryDatasSnap(llgl, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                double temp1 = 0;
                double temp2 = 0;
                double temp3 = 0;
                double temp4 = 0;
                double temp5 = 0;
                for (int i = 0; i < fsycls.size(); i++) {

                    ForecastVo vo = new ForecastVo();
                    //                    vo.setPjfs(0.0); //平均风速
                    vo.setYcfs(0.0); //平均风速
                    //                    vo.setSjgl(0.0); //实际功率
                    vo.setYcgl(0.0); //功率预测
                    //                    vo.setLlgl(0.0); //超短期功率预测
                    vo.setHours(2023L);  //时间戳
                    vo.setName(wpId);

                    if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                        temp1 = pjfsls.get(i).getPointValueInDouble();
                        vo.setPjfs(StringUtils.round(temp1, 2));
                    }
                    if (fsycls.size() == ycglls.size()) {
                        if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                            temp2 = fsycls.get(i).getPointValueInDouble();
                            vo.setYcfs(StringUtils.round(temp2, 2));
                        }
                    }

                    if (ycglls != null && !ycglls.isEmpty() && ycglls.get(0).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));
                    }

                    if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                        temp5 = llglls.get(i).getPointValueInDouble();
                        vo.setLlgl(StringUtils.round(temp5 / 1000, 2));
                    }
                    vo.setHours(fsycls.get(i).getPointTime());

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

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


        return map;

    }


    public Map<String, Object> getcockpittype(String beginDate, String endDate, String type) throws Exception {

        Date starttime = DateUtils.parseDate(beginDate);
        Date endtime = DateUtils.parseDate(endDate);
        Date currentDate = new Date();
        String wpId = null;

        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        List<ProBasicProject> pjls = tokenService.gePjls(request);
        //        List<ProBasicProject> pjls = CacheContext.pjls;

        List<ProBasicProject> pjllist = null;

        //        List<ProBasicPowerstation> wplLs = CacheContext.wpls;

        //        List<ProBasicPowerstation> wplLs = tokenService.getWpls(request);
        List<ProBasicPowerstation> wplLs = CacheContext.wpls;

        SortUtils.sort(wplLs, "orderNum", SortUtils.ASC);

        List<ForecastVo> vos = null;
        Map<String, Object> map = new LinkedHashMap<>();
        ProBasicPowerstationPoint pjfs = null;
        ProBasicPowerstationPoint fsyc = null;
        ProBasicPowerstationPoint ycgl = null;
        ProBasicPowerstationPoint sjgl = null;
        ProBasicPowerstationPoint llgl = 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) {
                    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
                    pjfs = null;
                    fsyc = null;
                    ycgl = null;
                    sjgl = null;
                    llgl = null;

                    if (wpId.endsWith("FDC_STA") && type.equals("F")) {
                        pjfs = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSPJFS);
                        ycgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GLYC);
                        sjgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZGL);
                        llgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZLLGL);
                        fsyc = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.FSYC);
                    }
                    if (wpId.endsWith("GDC_STA") && type.equals("G")) {
                        pjfs = proBasicPowerstationPointService.getPowerstationPoint(wp.getWindpowerstationId(), ContantXk.GCGZQD);
                        fsyc = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GZYC);
                        ycgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.GLYC);
                        sjgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZGL);
                        llgl = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.SSZLLGL);
                    }

                    if (pjfs != null && sjgl != null) {
                        List<PointData> pjfsls = edosUtil.getHistoryDatasSnap(pjfs, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                        List<PointData> fsycls = edosUtil.getHistoryDatasSnap(fsyc, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                        List<PointData> ycglls = edosUtil.getHistoryDatasSnap(ycgl, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                        List<PointData> sjglls = edosUtil.getHistoryDatasSnap(sjgl, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                        List<PointData> llglls = edosUtil.getHistoryDatasSnap(llgl, starttime.getTime() / 1000, currentDate.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 < fsycls.size(); i++) {
                                ForecastVo vo = new ForecastVo();
                                //                                vo.setPjfs(0.0); //平均风速
                                vo.setYcfs(0.0); //预测风速
                                //                                vo.setSjgl(0.0); //实际功率
                                vo.setYcgl(0.0); //功率预测
                                //                                vo.setLlgl(0.0); //理论功率
                                vo.setHours(2023L);  //时间戳
                                vo.setName(wpId);

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

                                vo.setId(wpId);

                                if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                                    temp1 = pjfsls.get(i).getPointValueInDouble();
                                    vo.setPjfs(StringUtils.round(temp1, 2));
                                }
                                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));
                                }
                                if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                                    temp5 = llglls.get(i).getPointValueInDouble();
                                    vo.setLlgl(StringUtils.round(temp5 / 1000, 2));
                                }
                                if (fsycls.size() == ycglls.size()) {
                                    if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                        temp2 = fsycls.get(i).getPointValueInDouble();
                                        vo.setYcfs(StringUtils.round(temp2, 2));
                                    }
                                }

                                vos1.add(vo);
                            }
                        } else if (wp.getId().contains("SXJ_KGDL_GJYF02_EG")) {
                            for (int i = 0; i < pjfsls.size(); i++) {
                                ForecastVo vo = new ForecastVo();
                                //                                vo.setPjfs(0.0); //平均风速
                                vo.setYcfs(0.0); //预测风速
                                //                                vo.setSjgl(0.0); //实际功率
                                vo.setYcgl(0.0); //功率预测
                                //                                vo.setLlgl(0.0); //理论功率
                                vo.setHours(2023L);  //时间戳
                                vo.setName(wpId);

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

                                vo.setId(wpId);

                                if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                                    temp1 = pjfsls.get(i).getPointValueInDouble();
                                    vo.setPjfs(StringUtils.round(temp1, 2));
                                }
                                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));
                                }
                                if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                                    temp5 = llglls.get(i).getPointValueInDouble();
                                    vo.setLlgl(StringUtils.round(temp5 / 1000, 2));
                                }
                                if (fsycls.size() == ycglls.size()) {
                                    if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                        temp2 = fsycls.get(i).getPointValueInDouble();
                                        vo.setYcfs(StringUtils.round(temp2, 2));
                                    }
                                }

                                vos1.add(vo);
                            }
                        }

                        if (wp.getId().contains("SXJ_KGDL_TZG01_EG") || wp.getId().contains("SXJ_KGDL_TZG05_EG")) {
                            for (int i = 0; i < fsycls.size(); i++) {
                                ForecastVo vo2 = new ForecastVo();
                                //                                vo2.setPjfs(0.0); //平均风速
                                vo2.setYcfs(0.0); //预测风速
                                //                                vo2.setSjgl(0.0); //实际功率
                                vo2.setYcgl(0.0); //功率预测
                                //                                vo2.setLlgl(0.0); //理论功率
                                vo2.setHours(2023L);  //时间戳
                                vo2.setName(wpId);

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

                                if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                                    temp1 = pjfsls.get(i).getPointValueInDouble();
                                    vo2.setPjfs(StringUtils.round(temp1, 2));
                                }
                                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));
                                }

                                if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                                    temp5 = llglls.get(i).getPointValueInDouble();
                                    vo2.setLlgl(StringUtils.round(temp5 / 1000, 2));
                                }
                                if (fsycls.size() == ycglls.size()) {
                                    if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                        temp2 = fsycls.get(i).getPointValueInDouble();
                                        vo2.setYcfs(StringUtils.round(temp2, 2));
                                    }
                                }

                                vos2.add(vo2);
                            }
                        } else if (wpId.contains("TZ_GDC_STA")) {
                            for (int i = 0; i < pjfsls.size(); i++) {
                                ForecastVo vo2 = new ForecastVo();
                                //                                vo2.setPjfs(0.0); //平均风速
                                vo2.setYcfs(0.0); //预测风速
                                //                                vo2.setSjgl(0.0); //实际功率
                                vo2.setYcgl(0.0); //功率预测
                                //                                vo2.setLlgl(0.0); //理论功率
                                vo2.setHours(2023L);  //时间戳
                                vo2.setName(wpId);

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

                                if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                                    temp1 = pjfsls.get(i).getPointValueInDouble();
                                    vo2.setPjfs(StringUtils.round(temp1, 2));
                                }
                                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));
                                }

                                if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                                    temp5 = llglls.get(i).getPointValueInDouble();
                                    vo2.setLlgl(StringUtils.round(temp5 / 1000, 2));
                                }
                                if (fsycls.size() == ycglls.size()) {
                                    if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                        temp2 = fsycls.get(i).getPointValueInDouble();
                                        vo2.setYcfs(StringUtils.round(temp2, 2));
                                    }
                                }

                                vos2.add(vo2);
                            }
                        }

                        if (wpId.contains("PTZ_FDC_STA")) {
                            for (int i = 0; i < fsycls.size(); i++) {
                                ForecastVo vo3 = new ForecastVo();
                                //                                vo3.setPjfs(0.0); //平均风速
                                vo3.setYcfs(0.0); //预测风速
                                //                                vo3.setSjgl(0.0); //实际功率
                                vo3.setYcgl(0.0); //功率预测
                                //                                vo3.setLlgl(0.0); //理论功率
                                vo3.setHours(2023L);  //时间戳
                                vo3.setName(wpId);

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

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

                                vo3.setId(wpId);

                                if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                                    temp1 = pjfsls.get(i).getPointValueInDouble();
                                    vo3.setPjfs(StringUtils.round(temp1, 2));
                                }

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

                                if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                                    temp5 = llglls.get(i).getPointValueInDouble();
                                    vo3.setLlgl(StringUtils.round(temp5 / 1000, 2));
                                }
                                if (fsycls.size() == ycglls.size()) {
                                    if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                        temp2 = fsycls.get(i).getPointValueInDouble();
                                        vo3.setYcfs(StringUtils.round(temp2, 2));
                                    }
                                }

                                vos3.add(vo3);
                            }
                        }

                        if (wpId.contains("NJL")) {
                            for (int i = 0; i < fsycls.size(); i++) {
                                ForecastVo vo4 = new ForecastVo();
                                //                                vo4.setPjfs(0.0); //平均风速
                                vo4.setYcfs(0.0); //预测风速
                                //                                vo4.setSjgl(0.0); //实际功率
                                vo4.setYcgl(0.0); //功率预测
                                //                                vo4.setLlgl(0.0); //理论功率
                                vo4.setHours(2023L);  //时间戳
                                vo4.setName(wpId);

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

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

                                vo4.setId(wpId);

                                if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                                    temp1 = pjfsls.get(i).getPointValueInDouble();
                                    vo4.setPjfs(StringUtils.round(temp1, 2));
                                }

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

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

                                if (fsycls.size() == ycglls.size()) {
                                    if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                        temp2 = fsycls.get(i).getPointValueInDouble();
                                        vo4.setYcfs(StringUtils.round(temp2, 2));
                                    }
                                }

                                vos4.add(vo4);
                            }
                        }

                        if (wpId.contains("SY")) {
                            for (int i = 0; i < fsycls.size(); i++) {
                                ForecastVo vo5 = new ForecastVo();
                                //                                vo5.setPjfs(0.0); //平均风速
                                vo5.setYcfs(0.0); //预测风速
                                //                                vo5.setSjgl(0.0); //实际功率
                                vo5.setYcgl(0.0); //功率预测
                                //                                vo5.setLlgl(0.0); //理论功率
                                vo5.setHours(2023L);  //时间戳
                                vo5.setName(wpId);

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

                                if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                                    temp1 = pjfsls.get(i).getPointValueInDouble();
                                    vo5.setPjfs(StringUtils.round(temp1, 2));
                                }

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

                                if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                                    temp5 = llglls.get(i).getPointValueInDouble();
                                    vo5.setLlgl(StringUtils.round(temp5 / 1000, 2));
                                }
                                if (fsycls.size() == ycglls.size()) {
                                    if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                        temp2 = fsycls.get(i).getPointValueInDouble();
                                        vo5.setYcfs(StringUtils.round(temp2, 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.getPjfs() != null && currentVo1.getPjfs() != null) {
                                            currentVo1.setPjfs(MathUtil.twoBit((previousVo1.getPjfs() + currentVo1.getPjfs()) / 2));
                                        }
                                        if (previousVo1.getYcfs() != null && currentVo1.getYcfs() != null) {
                                            currentVo1.setYcfs(MathUtil.twoBit((previousVo1.getYcfs() + currentVo1.getYcfs()) / 2));
                                        }
                                        if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                            currentVo1.setSjgl(MathUtil.twoBit(previousVo1.getSjgl() + currentVo1.getSjgl()));
                                        }
                                        if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                            currentVo1.setYcgl(MathUtil.twoBit(previousVo1.getYcgl() + currentVo1.getYcgl()));
                                        }
                                        if (previousVo1.getLlgl() != null && currentVo1.getLlgl() != null) {
                                            currentVo1.setLlgl(MathUtil.twoBit(previousVo1.getLlgl() + currentVo1.getLlgl()));
                                        }
                                    }
                                }
                            }
                        } 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.getPjfs() != null && currentVo1.getPjfs() != null) {
                                            currentVo1.setPjfs(MathUtil.twoBit((previousVo1.getPjfs() + currentVo1.getPjfs()) / 2));
                                        }
                                        if (previousVo1.getYcfs() != null && currentVo1.getYcfs() != null) {
                                            currentVo1.setYcfs(MathUtil.twoBit((previousVo1.getYcfs() + currentVo1.getYcfs()) / 2));
                                        }
                                        if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                            currentVo1.setSjgl(MathUtil.twoBit(previousVo1.getSjgl() + currentVo1.getSjgl()));
                                        }
                                        if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                            currentVo1.setYcgl(MathUtil.twoBit(previousVo1.getYcgl() + currentVo1.getYcgl()));
                                        }
                                        if (previousVo1.getLlgl() != null && currentVo1.getLlgl() != null) {
                                            currentVo1.setLlgl(MathUtil.twoBit(previousVo1.getLlgl() + currentVo1.getLlgl()));
                                        }
                                    }
                                }
                            }
                        } 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.getPjfs() != null && currentVo1.getPjfs() != null) {
                                            currentVo1.setPjfs(MathUtil.twoBit((previousVo1.getPjfs() + currentVo1.getPjfs()) / 2));
                                        }
                                        if (previousVo1.getYcfs() != null && currentVo1.getYcfs() != null) {
                                            currentVo1.setYcfs(MathUtil.twoBit((previousVo1.getYcfs() + currentVo1.getYcfs()) / 2));
                                        }
                                        if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                            currentVo1.setSjgl(MathUtil.twoBit(previousVo1.getSjgl() + currentVo1.getSjgl()));
                                        }
                                        if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                            currentVo1.setYcgl(MathUtil.twoBit(previousVo1.getYcgl() + currentVo1.getYcgl()));
                                        }
                                        if (previousVo1.getLlgl() != null && currentVo1.getLlgl() != null) {
                                            currentVo1.setLlgl(MathUtil.twoBit(previousVo1.getLlgl() + currentVo1.getLlgl()));
                                        }
                                    }
                                }
                            }
                        } 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.getPjfs() != null && currentVo1.getPjfs() != null) {
                                            currentVo1.setPjfs(MathUtil.twoBit((previousVo1.getPjfs() + currentVo1.getPjfs()) / 2));
                                        }
                                        if (previousVo1.getYcfs() != null && currentVo1.getYcfs() != null) {
                                            currentVo1.setYcfs(MathUtil.twoBit((previousVo1.getYcfs() + currentVo1.getYcfs()) / 2));
                                        }
                                        if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                            currentVo1.setSjgl(MathUtil.twoBit(previousVo1.getSjgl() + currentVo1.getSjgl()));
                                        }
                                        if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                            currentVo1.setYcgl(MathUtil.twoBit(previousVo1.getYcgl() + currentVo1.getYcgl()));
                                        }
                                        if (previousVo1.getLlgl() != null && currentVo1.getLlgl() != null) {
                                            currentVo1.setLlgl(MathUtil.twoBit(previousVo1.getLlgl() + currentVo1.getLlgl()));
                                        }
                                    }
                                }
                            }
                        } 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.getPjfs() != null && currentVo1.getPjfs() != null) {
                                            currentVo1.setPjfs(MathUtil.twoBit((previousVo1.getPjfs() + currentVo1.getPjfs()) / 2));
                                        }
                                        if (previousVo1.getYcfs() != null && currentVo1.getYcfs() != null) {
                                            currentVo1.setYcfs(MathUtil.twoBit((previousVo1.getYcfs() + currentVo1.getYcfs()) / 2));
                                        }
                                        if (previousVo1.getSjgl() != null && currentVo1.getSjgl() != null) {
                                            currentVo1.setSjgl(MathUtil.twoBit(previousVo1.getSjgl() + currentVo1.getSjgl()));
                                        }
                                        if (previousVo1.getYcgl() != null && currentVo1.getYcgl() != null) {
                                            currentVo1.setYcgl(MathUtil.twoBit(previousVo1.getYcgl() + currentVo1.getYcgl()));
                                        }
                                        if (previousVo1.getLlgl() != null && currentVo1.getLlgl() != null) {
                                            currentVo1.setLlgl(MathUtil.twoBit(previousVo1.getLlgl() + currentVo1.getLlgl()));
                                        }
                                    }
                                }
                            }
                        }

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

                    ProBasicPowerstationPoint pjfs1 = null;
                    ProBasicPowerstationPoint fsyc1 = null;
                    ProBasicPowerstationPoint ycgl1 = null;
                    ProBasicPowerstationPoint sjgl1 = null;
                    ProBasicPowerstationPoint llgl1 = null;

                    if (wpId.endsWith("FDC_STA") && type.equals("F")) {
                        pjfs1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSPJFS);
                        fsyc1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.FSYC);
                        ycgl1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.GLYC);
                        sjgl1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZGL);
                        llgl1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZLLGL);
                    }
                    if (wpId.endsWith("GDC_STA") && type.equals("G")) {
                        pjfs1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.GCGZQD);
                        fsyc1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.GZYC);
                        ycgl1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.GLYC);
                        sjgl1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZGL);
                        llgl1 = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.SSZLLGL);
                    }
                    if (pjfs1 != null && sjgl1 != null) {
                        List<PointData> pjfsls = edosUtil.getHistoryDatasSnap(pjfs1, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                        List<PointData> fsycls = edosUtil.getHistoryDatasSnap(fsyc1, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                        List<PointData> ycglls = edosUtil.getHistoryDatasSnap(ycgl1, starttime.getTime() / 1000, endtime.getTime() / 1000, null, 900L);
                        List<PointData> sjglls = edosUtil.getHistoryDatasSnap(sjgl1, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                        List<PointData> llglls = edosUtil.getHistoryDatasSnap(llgl1, starttime.getTime() / 1000, currentDate.getTime() / 1000, null, 900L);
                        double temp1 = 0;
                        double temp2 = 0;
                        double temp3 = 0;
                        double temp4 = 0;
                        double temp5 = 0;
                        for (int i = 0; i < fsycls.size(); i++) {

                            ForecastVo vo = new ForecastVo();
                            //                            vo.setPjfs(0.0); //平均风速
                            vo.setYcfs(0.0); //平均风速
                            //                            vo.setSjgl(0.0); //实际功率
                            vo.setYcgl(0.0); //功率预测
                            //                            vo.setLlgl(0.0); //超短期功率预测
                            vo.setHours(2023L);  //时间戳
                            vo.setName(wpId);

                            if (pjfsls != null && !pjfsls.isEmpty() && i < pjfsls.size() && pjfsls.get(i).getPointName() != null) {
                                temp1 = pjfsls.get(i).getPointValueInDouble();
                                vo.setPjfs(StringUtils.round(temp1, 2));
                            }
                            if (fsycls.size() == ycglls.size()) {
                                if (fsycls != null && !fsycls.isEmpty() && fsycls.get(0).getPointName() != null) {
                                    temp2 = fsycls.get(i).getPointValueInDouble();
                                    vo.setYcfs(StringUtils.round(temp2, 2));
                                }
                            }

                            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));
                            }
                            if (llglls != null && !llglls.isEmpty() && i < llglls.size() && llglls.get(i).getPointName() != null) {
                                temp5 = llglls.get(i).getPointValueInDouble();
                                vo.setLlgl(StringUtils.round(temp5 / 1000, 2));
                            }
                            vo.setHours(fsycls.get(i).getPointTime());

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

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

                    }
                }
            }
        }
        return map;
    }

}
