package com.gyee.runeconomy.service.monitor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.common.util.DateUtils;
import com.gyee.runeconomy.init.CacheContext;
import com.gyee.runeconomy.model.auto.*;
import com.gyee.runeconomy.service.TokenService;
import com.gyee.runeconomy.service.auto.*;
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.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class MonitorprojectplanService {

    @Resource
    private IProBasicProjectPlanService proBasicProjectPlanService;
    @Resource
    private IProBasicPowerstationPointService proBasicPowerstationPointService;
    @Resource
    private IProBasicEquipmentPointService proBasicEquipmentPointService;
    @Resource
    private IProBasicCompanyService proBasicCompanyService;
    @Resource
    private IProEconTargetdataService proEconTargetdataService;
    @Resource
    private IProEconTargetdataFristService proEconTargetdataFristService;

    @Resource
    private IProBasicPowerPointService powerPointService;

    @Resource
    private IProEconPowerstationInfoDay5Service proEconPowerstationInfoDay5Service;

    private final String QS = "0";
    private final String FD = "-1";
    private final String GF = "-2";

    @Resource
    private IEdosUtil edosUtil;
    Map<String, Object> map = new HashMap<>();
    @Resource
    private TokenService tokenService;

    public Map plan(String wpId) throws Exception {

        Map<String, Object> map = new HashMap<>();

        if (wpId.endsWith(QS) || wpId.endsWith(FD) || wpId.endsWith(GF) || CacheContext.wpmapls.containsKey(wpId)) {

            List<ProBasicPowerstation> wplist = new ArrayList<>();
            if (CacheContext.wpmapls.containsKey(wpId)) {
                wplist = CacheContext.wpmapls.get(wpId);
            }
            //            HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
            //            List<ProBasicPowerstation> wplsToken = tokenService.getWpls(request);
            List<ProBasicPowerstation> wplsToken = wplist;
            for (ProBasicPowerstation wp : wplsToken) {
                if (wpId.contains(FD)) {
                    if (wp.getId().endsWith("FDC_STA")) {
                        wplist.add(wp);
                    }
                } else if (wpId.contains(GF)) {
                    if (wp.getId().endsWith("GDC_STA")) {
                        wplist.add(wp);
                    }
                } else if (wpId.contains(QS)) {
                    wplist.add(wp);
                }
            }
            List<ProBasicPowerstation> rglist = new ArrayList<>();
            List<ProBasicRegion> rgls = CacheContext.rgls;

            for (ProBasicPowerstation wp1 : wplsToken) {
                for (ProBasicRegion rg : rgls) {
                    if (wpId.contains(rg.getId()) && wpId.contains(wp1.getRegionId())) {
                        rglist.add(wp1);
                        wplist = rglist;
                    }
                }
            }
            Calendar cal = Calendar.getInstance();
            cal.setTime(new Date());
            int year = cal.get(Calendar.YEAR);

            int month2 = DateUtils.getMonth(new Date());

            double fd_r_jhdl = 0;
            double fd_y_jhdl = 0;
            double fd_n_jhdl = 0;
            double gf_r_jhdl = 0;
            double gf_y_jhdl = 0;
            double gf_n_jhdl = 0;

            double fd_r_sjdl = 0;
            double fd_y_sjdl = 0;
            double fd_n_sjdl = 0;
            double gf_r_sjdl = 0;
            double gf_y_sjdl = 0;
            double gf_n_sjdl = 0;

            BigDecimal fd_r_sjdl1 = BigDecimal.valueOf(0);
            BigDecimal fd_y_sjdl1 = BigDecimal.valueOf(0);
            BigDecimal fd_n_sjdl1 = BigDecimal.valueOf(0);
            BigDecimal gf_r_sjdl1 = BigDecimal.valueOf(0);
            BigDecimal gf_y_sjdl1 = BigDecimal.valueOf(0);
            BigDecimal gf_n_sjdl1 = BigDecimal.valueOf(0);

            BigDecimal fdrf = BigDecimal.valueOf(0);
            BigDecimal fdnf = BigDecimal.valueOf(0);
            BigDecimal fdyf = BigDecimal.valueOf(0);
            BigDecimal gfrf = BigDecimal.valueOf(0);
            BigDecimal gfnf = BigDecimal.valueOf(0);
            BigDecimal gfyf = BigDecimal.valueOf(0);

            // 获取当前日期 暂时
            Date currentDate5 = new Date();

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

            // 设置 beginDate 为前一天的早上六点
            calendar5.add(Calendar.DAY_OF_MONTH, -1);
            calendar5.set(Calendar.HOUR_OF_DAY, 6);
            calendar5.set(Calendar.MINUTE, 0);
            calendar5.set(Calendar.SECOND, 0);
            calendar5.set(Calendar.MILLISECOND, 0);
            Date beginDate = calendar5.getTime();

            // 设置 endDate 为当天的23点59分59秒
            calendar5.set(Calendar.HOUR_OF_DAY, 23);
            calendar5.set(Calendar.MINUTE, 59);
            calendar5.set(Calendar.SECOND, 59);
            calendar5.set(Calendar.MILLISECOND, 999);
            Date endDate = calendar5.getTime();

            // 设置 beginDate 为前一天的早上六点
            calendar5.add(Calendar.DAY_OF_MONTH, 1);
            calendar5.set(Calendar.HOUR_OF_DAY, 6);
            calendar5.set(Calendar.MINUTE, 0);
            calendar5.set(Calendar.SECOND, 0);
            calendar5.set(Calendar.MILLISECOND, 0);
            Date beginDate1 = calendar5.getTime();

            // 设置 endDate 为当天的23点59分59秒
            calendar5.set(Calendar.HOUR_OF_DAY, 23);
            calendar5.set(Calendar.MINUTE, 59);
            calendar5.set(Calendar.SECOND, 59);
            calendar5.set(Calendar.MILLISECOND, 999);
            Date endDate1 = calendar5.getTime();

            List<ProEconPowerstationInfoDay5> qwt3 = null;

            QueryWrapper<ProEconPowerstationInfoDay5> qw3 = new QueryWrapper<>();

            qw3.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, wpId);
            qw3.lambda().between(ProEconPowerstationInfoDay5::getRecordDate, beginDate, endDate);
            qwt3 = proEconPowerstationInfoDay5Service.list(qw3);

            QueryWrapper<ProEconPowerstationInfoDay5> qw2 = new QueryWrapper<>();
            List<ProEconPowerstationInfoDay5> qwt2 = null;
            if (wpId.equals("KGDL_FGS0")) {
                qw2.lambda().in(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_KGDL_GFFD_ZGS0", "SXJ_KGDL_FLFD_ZGS0");
            } else if (wpId.equals("KGDL_FGS-1")) {
                qw2.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_KGDL_FLFD_ZGS0");
            } else if (wpId.equals("KGDL_FGS-2")) {
                qw2.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_KGDL_GFFD_ZGS0");
            } else if (wpId.equals("SXJ_RGN0")) {
                qw2.lambda().in(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_RGN-1", "SXJ_RGN-2");
            } else if (wpId.equals("SXJ_RGN-1")) {
                qw2.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_RGN-1");
            } else if (wpId.equals("SXJ_RGN-2")) {
                qw2.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_RGN-2");
            } else {
                qw2.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, wpId);
            }
            qw2.lambda().between(ProEconPowerstationInfoDay5::getRecordDate, beginDate1, endDate1);

            qwt2 = proEconPowerstationInfoDay5Service.list(qw2);

            if (wpId.endsWith(QS) || wpId.endsWith(FD) || wpId.endsWith(GF)) {

                //                double rfdlsj = 0.0;
                //                double yfdlsj = 0.0;
                //                double nfdlsj = 0.0;
                //
                //                double gfrfdlsj = 0.0;
                //                double gfyfdlsj = 0.0;
                //                double gfnfdlsj = 0.0;
                //
                //                String fdstr = null;
                //                String gfstr = null;
                //
                //                String str = wpId;

                Date current = com.gyee.common.util.DateUtils.getCurrentDate();
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(current);
                calendar.add(Calendar.DAY_OF_MONTH, -1);
                Date previousDay = calendar.getTime();
                List<ProEconTargetdataFrist> qwt = null;
                List<ProEconPowerstationInfoDay5> qwt1 = null;

                //
                //                double gfrlr = 0.0;
                //                double gfylr = 0.0;
                //                double gfnlr = 0.0;
                //
                //                double fdrlr = 0.0;
                //                double fdylr = 0.0;
                //                double fdnlr = 0.0;

                //                QueryWrapper<ProEconTargetdataFrist> qw = new QueryWrapper<>();
                //                qw.eq("record_date", previousDay);
                //                qwt = proEconTargetdataFristService.list(qw);


                QueryWrapper<ProEconPowerstationInfoDay5> qw1 = new QueryWrapper<>();

                if (wpId.equals("KGDL_FGS0")) {
                    qw1.lambda().in(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_KGDL_GFFD_ZGS-2", "SXJ_KGDL_FLFD_ZGS-1");
                } else if (wpId.equals("KGDL_FGS-1")) {
                    qw1.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_KGDL_FLFD_ZGS-1");
                } else if (wpId.equals("KGDL_FGS-2")) {
                    qw1.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_KGDL_GFFD_ZGS-2");
                } else if (wpId.equals("SXJ_RGN0")) {
                    qw1.lambda().in(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_RGN-1", "SXJ_RGN-2");
                } else if (wpId.equals("SXJ_RGN-1")) {
                    qw1.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_RGN-1");
                } else if (wpId.equals("SXJ_RGN-2")) {
                    qw1.lambda().eq(ProEconPowerstationInfoDay5::getForeignKeyId, "SXJ_RGN-2");
                }
                qw1.lambda().between(ProEconPowerstationInfoDay5::getRecordDate, beginDate, endDate);

                qwt1 = proEconPowerstationInfoDay5Service.list(qw1);


                //                if (qwt != null) {
                //                    gfrlr = qwt.stream()
                //                            .filter(gf -> gf != null && gf.getType() != null && gf.getType().endsWith("GF"))
                //                            .mapToDouble(gf -> gf != null && gf.getRfdl() != null ? gf.getRfdl() : 0)
                //                            .sum();
                //                    fdrlr = qwt.stream()
                //                            .filter(gf -> gf != null && gf.getType() != null && gf.getType().endsWith("FD"))
                //                            .mapToDouble(gf -> gf != null && gf.getRfdl() != null ? gf.getRfdl() : 0)
                //                            .sum();
                //                    gfylr = qwt.stream()
                //                            .filter(gf -> gf != null && gf.getType() != null && gf.getType().endsWith("GF"))
                //                            .mapToDouble(gf -> gf != null && gf.getYfdl() != null ? gf.getYfdl() : 0)
                //                            .sum();
                //                    fdylr = qwt.stream()
                //                            .filter(gf -> gf != null && gf.getType() != null && gf.getType().endsWith("FD"))
                //                            .mapToDouble(gf -> gf != null && gf.getYfdl() != null ? gf.getYfdl() : 0)
                //                            .sum();
                //                    gfnlr = qwt.stream()
                //                            .filter(gf -> gf != null && gf.getType() != null && gf.getType().endsWith("GF"))
                //                            .mapToDouble(gf -> gf != null && gf.getNfdl() != null ? gf.getNfdl() : 0)
                //                            .sum();
                //                    fdnlr = qwt.stream()
                //                            .filter(gf -> gf != null && gf.getType() != null && gf.getType().endsWith("FD"))
                //                            .mapToDouble(gf -> gf != null && gf.getNfdl() != null ? gf.getNfdl() : 0)
                //                            .sum();
                //                }

                //                if (wpId.endsWith(QS)) {
                //                    fdstr = str.substring(0, str.indexOf("0")) + "-1";
                //                    gfstr = str.substring(0, str.indexOf("0")) + "-2";
                //                    ProBasicPowerstationPoint rfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(fdstr, ContantXk.RFDL);
                //                    rfdlsj = edosUtil.getRealData(rfdlvalue).getPointValueInDouble();
                //                    //月发电量
                //                    ProBasicPowerstationPoint yfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(fdstr, ContantXk.YFDL);
                //                    yfdlsj = edosUtil.getRealData(yfdlvalue).getPointValueInDouble();
                //                    //年发电量
                //                    ProBasicPowerstationPoint nfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(fdstr, ContantXk.NFDL);
                //                    nfdlsj = edosUtil.getRealData(nfdlvalue).getPointValueInDouble();
                //
                //                    ProBasicPowerstationPoint gfrfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(gfstr, ContantXk.RFDL);
                //                    gfrfdlsj = edosUtil.getRealData(gfrfdlvalue).getPointValueInDouble();
                //                    //月发电量
                //                    ProBasicPowerstationPoint gfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(gfstr, ContantXk.YFDL);
                //                    gfyfdlsj = edosUtil.getRealData(gfdlvalue).getPointValueInDouble();
                //                    //年发电量
                //                    ProBasicPowerstationPoint gfnfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(gfstr, ContantXk.NFDL);
                //                    gfnfdlsj = edosUtil.getRealData(gfnfdlvalue).getPointValueInDouble();

                //                    if (fdrlr != 0 && fdylr != 0 && fdnlr != 0 && gfrlr != 0 && gfylr != 0 && gfnlr != 0) {
                //                        fd_r_sjdl = fd_r_sjdl + fdrlr * 10000;
                //                        fd_y_sjdl = fd_y_sjdl + fdylr * 10000;
                //                        fd_n_sjdl = fd_n_sjdl + fdnlr * 10000;
                //
                //                        gf_r_sjdl = gf_r_sjdl + gfrlr * 10000;
                //                        gf_y_sjdl = gf_y_sjdl + gfylr * 10000;
                //                        gf_n_sjdl = gf_n_sjdl + gfnlr * 10000;

                //                    } else {
                //                        fd_r_sjdl = fd_r_sjdl + rfdlsj;
                //                        fd_y_sjdl = fd_y_sjdl + yfdlsj;
                //                        fd_n_sjdl = fd_n_sjdl + nfdlsj;

                //                        gf_r_sjdl = gf_r_sjdl + gfrfdlsj;
                //                        gf_y_sjdl = gf_y_sjdl + gfyfdlsj;
                //                        gf_n_sjdl = gf_n_sjdl + gfnfdlsj;

                //                    }


                //                    fd_r_sjdl1 = BigDecimal.valueOf(rfdlsj);
                //                    gf_r_sjdl1 = BigDecimal.valueOf(gfrfdlsj);
                //                } else if (wpId.endsWith(FD) || wpId.endsWith(GF)) {
                //                    ProBasicPowerstationPoint rfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.RFDL);
                //
                //                    rfdlsj = edosUtil.getRealData(rfdlvalue).getPointValueInDouble();
                //
                //                    //月发电量
                //                    ProBasicPowerstationPoint yfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.YFDL);
                //
                //                    yfdlsj = edosUtil.getRealData(yfdlvalue).getPointValueInDouble();
                //
                //
                //                    //年发电量
                //                    ProBasicPowerstationPoint nfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wpId, ContantXk.NFDL);
                //
                //                    nfdlsj = edosUtil.getRealData(nfdlvalue).getPointValueInDouble();

                //                    if (fdrlr != 0 && fdylr != 0 && fdnlr != 0 && gfrlr != 0 && gfylr != 0 && gfnlr != 0) {
                //                        fd_r_sjdl = fd_r_sjdl + fdrlr * 10000;
                //                        fd_y_sjdl = fd_y_sjdl + fdylr * 10000;
                //                        fd_n_sjdl = fd_n_sjdl + fdnlr * 10000;
                //
                //                        gf_r_sjdl = gf_r_sjdl + gfrlr * 10000;
                //                        gf_y_sjdl = gf_y_sjdl + gfylr * 10000;
                //                        gf_n_sjdl = gf_n_sjdl + gfnlr * 10000;
                //                    } else {
                //                        fd_r_sjdl = fd_r_sjdl + rfdlsj;
                //                        fd_y_sjdl = fd_y_sjdl + yfdlsj;
                //                        fd_n_sjdl = fd_n_sjdl + nfdlsj;
                //
                //                        gf_r_sjdl = gf_r_sjdl + rfdlsj;
                //                        gf_y_sjdl = gf_y_sjdl + yfdlsj;
                //                        gf_n_sjdl = gf_n_sjdl + nfdlsj;

                //                    }


                //                    fd_r_sjdl1 = BigDecimal.valueOf(rfdlsj);
                //                    gf_r_sjdl1 = BigDecimal.valueOf(rfdlsj);
                //                }

                for (ProEconPowerstationInfoDay5 fdsj : qwt1) {
                    if (fdsj.getForeignKeyId().equals("SXJ_KGDL_FLFD_ZGS0")) {
                        fdnf = fdsj.getNfdldb();
                        fdyf = fdsj.getYfdldb();
                    } else if (fdsj.getForeignKeyId().equals("SXJ_KGDL_GFFD_ZGS0")) {
                        gfnf = fdsj.getNfdldb();
                        gfyf = fdsj.getYfdldb();
                    } else if (fdsj.getForeignKeyId().equals("SXJ_RGN-2")) {
                        gfnf = fdsj.getNfdldb();
                        gfyf = fdsj.getYfdldb();
                    } else if (fdsj.getForeignKeyId().equals("SXJ_RGN-1")) {
                        fdnf = fdsj.getNfdldb();
                        fdyf = fdsj.getYfdldb();
                    }
                }

                //                if (wpId.endsWith("-1") && fdnf == null && fdyf == null){
                //                    fdnf = BigDecimal.valueOf(100);
                //                    fdyf = BigDecimal.valueOf(100);
                //                }else if (wpId.endsWith("-2") && gfnf == null && gfyf == null){
                //                    gfnf = BigDecimal.valueOf(100);
                //                    gfyf = BigDecimal.valueOf(100);
                //                } else if (wpId.endsWith("0") && fdnf == null && fdyf == null && gfnf == null && gfyf == null ) {
                //                    fdnf = BigDecimal.valueOf(100);
                //                    fdyf = BigDecimal.valueOf(100);
                //                    gfnf = BigDecimal.valueOf(100);
                //                    gfyf = BigDecimal.valueOf(100);
                //                }
                for (ProEconPowerstationInfoDay5 fdsj : qwt2) {
                    if (fdsj.getForeignKeyId().equals("SXJ_KGDL_FLFD_ZGS0")) {
                        fdrf = fdsj.getRfdldb();
                    } else if (fdsj.getForeignKeyId().equals("SXJ_KGDL_GFFD_ZGS0")) {
                        gfrf = fdsj.getRfdldb();
                    } else if (fdsj.getForeignKeyId().equals("SXJ_RGN-2")) {
                        gfrf = fdsj.getRfdldb();
                    } else if (fdsj.getForeignKeyId().equals("SXJ_RGN-1")) {
                        fdrf = fdsj.getRfdldb();
                    }
                }
                if (wpId.endsWith("0") || wpId.endsWith("-1")) {
                    fd_r_sjdl1 = fdrf;
                    //                    fd_y_sjdl1 = fdyf.add(fd_r_sjdl1);
                    //                    fd_n_sjdl1 = fdnf.add(fd_r_sjdl1);
                    fd_y_sjdl1 = fdyf;
                    fd_n_sjdl1 = fdnf;
                }

                if (wpId.endsWith("0") || wpId.endsWith("-2")) {
                    gf_r_sjdl1 = gfrf;
                    //                    gf_y_sjdl1 = gfyf.add(gf_r_sjdl1);
                    //                    gf_n_sjdl1 = gfnf.add(gf_r_sjdl1);
                    gf_y_sjdl1 = gfyf;
                    gf_n_sjdl1 = gfnf;
                }
            }

            List<ProBasicProjectPlan> currentls = proBasicProjectPlanService.getList(String.valueOf(year));
            List<ProBasicProjectPlan> monthls = proBasicProjectPlanService.getmonthList(String.valueOf(month2));

            for (ProBasicPowerstation wp : wplist) {

                List<ProBasicProjectPlan> currentjh = currentls.stream().filter(wp1 -> wp1.getWindpowerstationId().equals(wp.getId())).collect(Collectors.toList());
                List<ProBasicProjectPlan> monthjh = monthls.stream().filter(wp1 -> wp1.getWindpowerstationId().equals(wp.getId())).collect(Collectors.toList());


                double yfdljh = 0.0;
                double rfdlsj = 0.0;
                double yfdlsj = 0.0;
                double nfdljh = 0.0;
                double nfdlsj = 0.0;
                yfdljh = monthjh.stream().mapToDouble(ProBasicProjectPlan::getGeneratingCapacity).sum();
                nfdljh = currentjh.stream().mapToDouble(ProBasicProjectPlan::getGeneratingCapacity).sum();

                if (wp.getId().indexOf("FDC_STA") >= 0) {

                    if (wpId.endsWith("STA")) {
                        //日发电量
                        //                        ProBasicPowerstationPoint rfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.RFDL);
                        //                        rfdlsj = edosUtil.getRealData(rfdlvalue).getPointValueInDouble();
                        //                        //月发电量
                        //                        ProBasicPowerstationPoint yfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.YFDL);
                        //                        yfdlsj = edosUtil.getRealData(yfdlvalue).getPointValueInDouble();
                        //                        //年发电量
                        //                        ProBasicPowerstationPoint nfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.NFDL);
                        //                        nfdlsj = edosUtil.getRealData(nfdlvalue).getPointValueInDouble();


                        BigDecimal yfdl2 = null;
                        BigDecimal rfdl2 = null;
                        BigDecimal nfdl2 = null;
                        for (ProEconPowerstationInfoDay5 dla : qwt3) {
                            yfdl2 = dla.getYfdldb();
                            nfdl2 = dla.getNfdldb();
                        }

                        for (ProEconPowerstationInfoDay5 dla : qwt2) {
                            rfdl2 = dla.getRfdldb();
                        }

                        //                        fd_r_sjdl1 = BigDecimal.valueOf(rfdlsj);
                        //                        fd_y_sjdl1 = yfdl2.add(BigDecimal.valueOf(rfdlsj));
                        //                        fd_n_sjdl1 = nfdl2.add(BigDecimal.valueOf(rfdlsj));
                        fd_y_sjdl1 = yfdl2;
                        fd_r_sjdl1 = rfdl2;
                        fd_n_sjdl1 = nfdl2;

                        //                        fd_r_sjdl1 = BigDecimal.valueOf(rfdlsj);
                        //                        fd_y_sjdl1 = BigDecimal.valueOf(yfdlsj);
                        //                        fd_n_sjdl1 = BigDecimal.valueOf(nfdlsj);
                    }
                    fd_r_jhdl = fd_r_jhdl + yfdljh / 30;
                    fd_y_jhdl = fd_y_jhdl + yfdljh;
                    fd_n_jhdl = fd_n_jhdl + nfdljh;


                } else {

                    if (wpId.endsWith("STA")) {
                        //日发电量
                        //                        ProBasicPowerstationPoint rfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.RFDL);
                        //                        rfdlsj = edosUtil.getRealData(rfdlvalue).getPointValueInDouble();
                        //                        //月发电量
                        //                        ProBasicPowerstationPoint yfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.YFDL);
                        //                        yfdlsj = edosUtil.getRealData(yfdlvalue).getPointValueInDouble();
                        //
                        //                        //年发电量
                        //                        ProBasicPowerstationPoint nfdlvalue = proBasicPowerstationPointService.getPowerstationPoint(wp.getId(), ContantXk.NFDL);
                        //                        nfdlsj = edosUtil.getRealData(nfdlvalue).getPointValueInDouble();
                        //
                        //                        gf_r_sjdl1 = BigDecimal.valueOf(rfdlsj);
                        //                        gf_y_sjdl1 = BigDecimal.valueOf(yfdlsj);
                        //                        gf_n_sjdl1 = BigDecimal.valueOf(nfdlsj);

                        BigDecimal yfdl2 = null;
                        BigDecimal rfdl2 = null;
                        BigDecimal nfdl2 = null;
                        for (ProEconPowerstationInfoDay5 dla : qwt3) {
                            yfdl2 = dla.getYfdldb();
                            nfdl2 = dla.getNfdldb();
                        }
                        for (ProEconPowerstationInfoDay5 dla : qwt2) {
                            rfdl2 = dla.getRfdldb();
                        }
                        //                        gf_r_sjdl1 = BigDecimal.valueOf(rfdlsj);
                        //                        gf_y_sjdl1 = yfdl2.add(BigDecimal.valueOf(rfdlsj));
                        //                        gf_n_sjdl1 = nfdl2.add(BigDecimal.valueOf(rfdlsj));
                        gf_y_sjdl1 = yfdl2;
                        gf_r_sjdl1 = rfdl2;
                        gf_n_sjdl1 = nfdl2;
                    }
                    gf_r_jhdl = gf_r_jhdl + yfdljh / 30;
                    gf_y_jhdl = gf_y_jhdl + yfdljh;
                    gf_n_jhdl = gf_n_jhdl + nfdljh;

                }

            }


            if (wpId.contains("FL")) {
                gf_r_jhdl = 0;
                gf_y_jhdl = 0;
                gf_n_jhdl = 0;
                gf_r_sjdl = 0;
                gf_y_sjdl = 0;
                gf_n_sjdl = 0;
            } else if (wpId.contains("GF")) {
                fd_r_jhdl = 0;
                fd_y_jhdl = 0;
                fd_n_jhdl = 0;
                fd_r_sjdl = 0;
                fd_y_sjdl = 0;
                fd_n_sjdl = 0;
            }

            if (wpId.endsWith("-2") || wpId.contains("GDC")) {
                fd_r_sjdl1 = BigDecimal.valueOf(0);
                fd_y_sjdl1 = BigDecimal.valueOf(0);
                fd_n_sjdl1 = BigDecimal.valueOf(0);
            }

            if (wpId.endsWith("-1") || wpId.contains("FDC")) {
                gf_r_sjdl1 = BigDecimal.valueOf(0);
                gf_y_sjdl1 = BigDecimal.valueOf(0);
                gf_n_sjdl1 = BigDecimal.valueOf(0);
            }

            Map<String, Double> proplanmap = new HashMap<>();

            proplanmap.put("fd_r_jhdl", StringUtils.round(fd_r_jhdl, 0));
            proplanmap.put("fd_y_jhdl", StringUtils.round(fd_y_jhdl, 0));
            proplanmap.put("fd_n_jhdl", StringUtils.round(fd_n_jhdl, 0));
            proplanmap.put("fd_r_sjdl", StringUtils.round(fd_r_sjdl1 != null ? fd_r_sjdl1.doubleValue() : 0.0, 2));
            proplanmap.put("fd_y_sjdl", StringUtils.round(fd_y_sjdl1 != null ? fd_y_sjdl1.doubleValue() : 0.0, 2));
            proplanmap.put("fd_n_sjdl", StringUtils.round(fd_n_sjdl1 != null ? fd_n_sjdl1.doubleValue() : 0.0, 2));

            proplanmap.put("gf_r_jhdl", StringUtils.round(gf_r_jhdl, 0));
            proplanmap.put("gf_y_jhdl", StringUtils.round(gf_y_jhdl, 0));
            proplanmap.put("gf_n_jhdl", StringUtils.round(gf_n_jhdl, 0));

            proplanmap.put("gf_r_sjdl", StringUtils.round(gf_r_sjdl1 != null ? gf_r_sjdl1.doubleValue() : 0.0, 2));
            proplanmap.put("gf_y_sjdl", StringUtils.round(gf_y_sjdl1 != null ? gf_y_sjdl1.doubleValue() : 0.0, 2));
            proplanmap.put("gf_n_sjdl", StringUtils.round(gf_n_sjdl1 != null ? gf_n_sjdl1.doubleValue() : 0.0, 2));

            proplanmap.put("qy_r_jhdl", StringUtils.round(fd_r_jhdl + gf_r_jhdl, 0));
            proplanmap.put("qy_y_jhdl", StringUtils.round(fd_y_jhdl + gf_y_jhdl, 0));
            proplanmap.put("qy_n_jhdl", StringUtils.round(fd_n_jhdl + gf_n_jhdl, 0));
            proplanmap.put("qy_r_sjdl", StringUtils.round((fd_r_sjdl1 != null ? fd_r_sjdl1.doubleValue() : 0.0) + (gf_r_sjdl1 != null ? gf_r_sjdl1.doubleValue() : 0.0), 2));
            proplanmap.put("qy_y_sjdl", StringUtils.round((fd_y_sjdl1 != null ? fd_y_sjdl1.doubleValue() : 0.0) + (gf_y_sjdl1 != null ? gf_y_sjdl1.doubleValue() : 0.0), 2));
            proplanmap.put("qy_n_sjdl", StringUtils.round((fd_n_sjdl1 != null ? fd_n_sjdl1.doubleValue() : 0.0) + (gf_n_sjdl1 != null ? gf_n_sjdl1.doubleValue() : 0.0), 2));


            map.put("proplanmap", proplanmap);
        }
        return map;
    }

}
