package com.gyee.generation.service.realtimelibrary;
/*
@author   谢生杰
@date   2022/11/4-17:09
*/

import com.gyee.common.contant.ContantXk;
import com.gyee.common.model.PointData;
import com.gyee.common.util.DateUtils;
import com.gyee.common.util.DoubleUtils;
import com.gyee.common.util.algorithm.Underdelivery;
import com.gyee.generation.init.CacheContext;
import com.gyee.generation.model.auto.*;
import com.gyee.generation.util.PointUtil;
import com.gyee.generation.util.realtimesource.IEdosUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;

@Service
public class RealtimeService {
    @Resource
    private IEdosUtil edosUtil;

    /**
     * 存储补风风速实时点,理论保证自算最优可用功率，
     *
     * @throws Exception
     */
    public void savaRealtimeTarget() throws Exception {
        //        Calendar c = Calendar.getInstance();
        //        Date begin=null;
        //        Date end=null;
        //
        //        begin=new Date();
        //        System.out.println("实时指标调度程序执行开始!。。。。。。");
        List<ProBasicEquipment> wtls = CacheContext.wtls;
        List<ProBasicLine> lnls = CacheContext.lnls;
        List<ProBasicProject> pjls = CacheContext.pjls;
        List<ProBasicPowerstation> wpls = CacheContext.wpls;
        Map<String, List<ProBasicEquipment>> lnwtmap = CacheContext.lnwtmap;
        Map<String, List<ProBasicLine>> prolinemap = CacheContext.prolinemap;
        Map<String, List<ProBasicProject>> wppromap = CacheContext.wppromap;
        Map<String, Map<Double, ProBasicModelPowerRd>> theoreticalPowerMap = CacheContext.theoreticalPowerMap; //理论保证功率
        Map<String, Map<Double, ProEconWtCurveFittingMonth>> curveFittingPowerMap = CacheContext.curveFittingMonthMap; //最优自算功率
        Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
        Map<String, Map<String, ProBasicPowerstationPoint>> linepointmap = CacheContext.linepointmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> propointmap = CacheContext.propointmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> wppointmap = CacheContext.wppointmap;
        Date currentDate = DateUtils.getCurrentDate();
        Date minute15begin = DateUtils.addMinutes(currentDate, -15);
        //保存风机点
        List<PointData> wtResultList = new ArrayList<>();


        List<String> pointls = new ArrayList<>();

        List<PointData> pointDatals = new ArrayList<>();

        for (ProBasicEquipment wt : wtls) {

            Map<String, ProBasicEquipmentPoint> equipmentPointMap = wtpAimap.get(wt.getId());

            ProBasicEquipmentPoint mxztPoint = equipmentPointMap.get(ContantXk.MXZT);
            ProBasicEquipmentPoint ssglPoint = equipmentPointMap.get(ContantXk.CJ_SSGL);

            pointls.add(mxztPoint.getNemCode());
            pointls.add(ssglPoint.getNemCode());

            if (pointls.size() >= 1000) {
                List<PointData> templs = edosUtil.getRealData(pointls);
                pointDatals.addAll(templs);
                pointls = new ArrayList<>();
            }
        }
        if (!pointls.isEmpty()) {
            List<PointData> templs = edosUtil.getRealData(pointls);
            pointDatals.addAll(templs);
        }
        //        wtls.stream().forEach(wt -> {
        for (int i = 0; i < wtls.size(); i++) {
            ProBasicEquipment wt = wtls.get(i);
            Map<String, ProBasicEquipmentPoint> equipmentPointMap = wtpAimap.get(wt.getId());
            ProBasicEquipmentPoint speedPoint = equipmentPointMap.get(ContantXk.CJ_SSFS);
            ProBasicEquipmentPoint mxztPoint = equipmentPointMap.get(ContantXk.MXZT);
            ProBasicEquipmentPoint ssbfPoint = null;
            if (wt.getId().contains("_WT_")) {
                ssbfPoint = equipmentPointMap.get(ContantXk.SSBF);
            } else if (wt.getId().contains("_IN_")) {
                ssbfPoint = equipmentPointMap.get(ContantXk.SSBG);
            }
            ProBasicEquipmentPoint ssglPoint = equipmentPointMap.get(ContantXk.CJ_SSGL);
            //理论功率测点
            ProBasicEquipmentPoint llglPoint = equipmentPointMap.get(ContantXk.LLGL);
            //保证功率测点
            ProBasicEquipmentPoint bzglPoint = equipmentPointMap.get(ContantXk.BZGL);
            //自算功率测点
            ProBasicEquipmentPoint zsglPoint = equipmentPointMap.get(ContantXk.ZSGL);
            //最优功率测点
            ProBasicEquipmentPoint zyglPoint = equipmentPointMap.get(ContantXk.ZYGL);
            //可用功率测点
            ProBasicEquipmentPoint kyglPoint = equipmentPointMap.get(ContantXk.KYGL);
            //实时欠发状态
            ProBasicEquipmentPoint ssqfztPoint = equipmentPointMap.get(ContantXk.SSQFZT);
            //历史欠发状态
            ProBasicEquipmentPoint lsqfztPoint = equipmentPointMap.get(ContantXk.LSQFZT);
            double mxzt = 0;
            double speed = 0;
            double ssbf = 0;
            double ssgl = 0;

            Optional<PointData> ssfsOptional = null;

            try {

                double ssztmx = 0;
                try {
                    ssztmx = pointDatals.get(i * 2).getPointValueInDouble();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                if (ssztmx == 12 || ssztmx == 13) {
                    continue;
                }
                //                mxzt = edosUtil.getRealData(mxztPoint).getPointValueInDouble();
                //                speed = edosUtil.getRealData(speedPoint).getPointValueInDouble();
                //                ssgl = edosUtil.getRealData(ssglPoint).getPointValueInDouble();

                mxzt = pointDatals.get(i * 2).getPointValueInDouble();
                ssgl = pointDatals.get(i * 2 + 1).getPointValueInDouble();

                ssfsOptional = edosUtil.getHistStat(speedPoint, minute15begin.getTime() / 1000, currentDate.getTime() / 1000, 1l, 900l, 2).stream().findFirst();
                //                ssglOptional = edosUtil.getHistStat(ssglPoint, minute15begin.getTime() / 1000, currentDate.getTime() / 1000, 1l, 900l, 2).stream().findFirst();
                //                zsglOptional = edosUtil.getHistStat(zsglPoint, minute15begin.getTime() / 1000, currentDate.getTime() / 1000, 1l, 900l, 2).stream().findFirst();

            } catch (Exception e) {
                e.printStackTrace();
            }

            if (ssfsOptional.isPresent()) {
                speed = ssfsOptional.get().getPointValueInDouble();
            }
            PointData ssbfPointDate = null;
            if (mxzt == 12 || mxzt == 13) {
                //补风算法(后续补充)
                ssbf = speed > 12 ? 12 : speed;
                ssbfPointDate = PointUtil.createPointData(currentDate, ssbf, ssbfPoint.getNemCode(), ssbfPoint.getName());
            } else {

                if (wt.getEquipmentCategory().equals("-1")) {
                    ssbf = speed > 12 ? 12 : speed;
                } else {
                    ssbf = speed;
                }
                ssbfPointDate = PointUtil.createPointData(currentDate, ssbf, ssbfPoint.getNemCode(), ssbfPoint.getName());
            }
            wtResultList.add(ssbfPointDate);
            double v = DoubleUtils.keepPrecision(ssbf, 2);
            if (null != theoreticalPowerMap){
                if (theoreticalPowerMap.containsKey(wt.getModelId())) {
                    //                double v = DoubleUtils.keepPrecision(ssbf, 2);
                    if (theoreticalPowerMap.get(wt.getModelId()).containsKey(v)) {
                        ProBasicModelPowerRd basicModelPowerRd = theoreticalPowerMap.get(wt.getModelId()).get(v);
                        wtResultList.add(PointUtil.createPointData(currentDate, basicModelPowerRd.getTheoryPower(), llglPoint.getNemCode(), llglPoint.getName()));
                        wtResultList.add(PointUtil.createPointData(currentDate, basicModelPowerRd.getEnsurePower(), bzglPoint.getNemCode(), bzglPoint.getName()));
                    } else {
                        wtResultList.add(PointUtil.createPointData(currentDate, 0, llglPoint.getNemCode(), llglPoint.getName()));
                        wtResultList.add(PointUtil.createPointData(currentDate, 0, bzglPoint.getNemCode(), bzglPoint.getName()));
                    }
                }
            }
            if (null != curveFittingPowerMap){
                if (curveFittingPowerMap.containsKey(wt.getId())) {
                    if (curveFittingPowerMap.get(wt.getId()).containsKey(v)) {
                        ProEconWtCurveFittingMonth wtPowerCurveFitting = curveFittingPowerMap.get(wt.getId()).get(v);
                        Double actualPower = wtPowerCurveFitting.getActualPower();
                        double[] underissuanceArray = {0, 1, 2, 3, 8, 9, 11};
                        double qfzt = 0;
                        double lsqfzt = 0;
                        double ssgl15 = 0;
                        double zsgl15 = 0;
                        //                    if (ssglOptional.isPresent()) {
                        //                        ssgl15 = ssglOptional.get().getPointValueInDouble();
                        zsgl15 = wtPowerCurveFitting.getActualPower();
                        //                    }
                        if (Arrays.asList(underissuanceArray).contains(mxzt)) {
                            qfzt = Underdelivery.underdeliveryStatusReal(ssgl, actualPower);
                            lsqfzt = Underdelivery.underdeliveryStatusReal(ssgl15, zsgl15);
                        }
                        wtResultList.add(PointUtil.createPointData(currentDate, qfzt, ssqfztPoint.getNemCode(), ssqfztPoint.getName()));
                        wtResultList.add(PointUtil.createPointData(currentDate, lsqfzt, lsqfztPoint.getNemCode(), lsqfztPoint.getName()));

                        wtResultList.add(PointUtil.createPointData(currentDate, wtPowerCurveFitting.getActualPower(), zsglPoint.getNemCode(), zsglPoint.getName()));
                        wtResultList.add(PointUtil.createPointData(currentDate, wtPowerCurveFitting.getOptimalPower(), zyglPoint.getNemCode(), zyglPoint.getName()));
                        //                    if (mxzt == 4 || mxzt == 5 || mxzt == 6 || mxzt == 7) {
                        //                        wtResultList.add(PointUtil.createPointData(currentDate, 0, kyglPoint.getNemCode(), kyglPoint.getName()));
                        //                    } else {
                        //                        wtResultList.add(PointUtil.createPointData(currentDate, wtPowerCurveFitting.getActualPower(), kyglPoint.getNemCode(), kyglPoint.getName()));
                        //                    }
                    } else {
                        wtResultList.add(PointUtil.createPointData(currentDate, 0, ssqfztPoint.getNemCode(), ssqfztPoint.getName()));
                        wtResultList.add(PointUtil.createPointData(currentDate, 0, lsqfztPoint.getNemCode(), lsqfztPoint.getName()));

                        wtResultList.add(PointUtil.createPointData(currentDate, 0, zsglPoint.getNemCode(), zsglPoint.getName()));
                        wtResultList.add(PointUtil.createPointData(currentDate, 0, zyglPoint.getNemCode(), zyglPoint.getName()));
                        //                    wtResultList.add(PointUtil.createPointData(currentDate, 0, kyglPoint.getNemCode(), kyglPoint.getName()));
                    }
                }
            }
            //        });
        }
        edosUtil.sendMultiPoint(wtResultList);

        //        end=new Date();
        //        System.out.println("执行用时"+ DateUtils.millisecondDiff(begin,end) +"秒");
        //        System.out.println("实时计算指标调度程序执行结束!。。。。。。");


    }


    public void savaRealtimeTargetWp() throws Exception {
        Calendar c = Calendar.getInstance();
        Date begin = null;
        Date end = null;

        begin = new Date();
        System.out.println("实时场站指标调度程序执行开始!。。。。。。");
        List<ProBasicEquipment> wtls = CacheContext.wtls;
        List<ProBasicLine> lnls = CacheContext.lnls;
        List<ProBasicProject> pjls = CacheContext.pjls;
        List<ProBasicPowerstation> wpls = CacheContext.wpls;
        Map<String, List<ProBasicEquipment>> lnwtmap = CacheContext.lnwtmap;
        Map<String, List<ProBasicLine>> prolinemap = CacheContext.prolinemap;
        Map<String, List<ProBasicProject>> wppromap = CacheContext.wppromap;
        Map<String, Map<Double, ProBasicModelPowerRd>> theoreticalPowerMap = CacheContext.theoreticalPowerMap; //理论保证功率
        Map<String, Map<Double, ProEconWtPowerCurveFitting>> curveFittingPowerMap = CacheContext.curveFittingPowerMap; //最优自算功率
        Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
        Map<String, Map<String, ProBasicPowerstationPoint>> linepointmap = CacheContext.linepointmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> propointmap = CacheContext.propointmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> wppointmap = CacheContext.wppointmap;
        Date currentDate = DateUtils.getCurrentDate();
        Date minute15begin = DateUtils.addMinutes(currentDate, -15);
        //保存风机点
        List<PointData> wtResultList = new ArrayList<>();


        //保存线路点
        List<PointData> lineResultList = new ArrayList<>();
        lnls.stream().forEach(line -> {
            List<ProBasicEquipment> proBasicWindturbines = lnwtmap.get(line.getId());
            Map<String, ProBasicPowerstationPoint> proBasicWppointMap = linepointmap.get(line.getId());
            AtomicReference<Double> zssbf = new AtomicReference<>((double) 0);
            AtomicReference<Double> zssgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zllgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zbzgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zzsgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zzygl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zkygl = new AtomicReference<>((double) 0);
            ProBasicPowerstationPoint ssfsWpPoint = null;
            if (line.getSpare4().equals("1")) {
                ssfsWpPoint = proBasicWppointMap.get(ContantXk.SSPJFS);
            } else if (line.getSpare4().equals("2")) {
                ssfsWpPoint = proBasicWppointMap.get(ContantXk.SSPJGZD);
            }
            ProBasicPowerstationPoint ssglWpPoint = proBasicWppointMap.get(ContantXk.SSZGL);
            ProBasicPowerstationPoint llglWpPoint = proBasicWppointMap.get(ContantXk.SSZLLGL);
            ProBasicPowerstationPoint bzglWpPoint = proBasicWppointMap.get(ContantXk.SSZBZGL);
            ProBasicPowerstationPoint zsglWpPoint = proBasicWppointMap.get(ContantXk.SSZNHGLZS);
            ProBasicPowerstationPoint zyglWpPoint = proBasicWppointMap.get(ContantXk.SSZZYGL);
            //            ProBasicPowerstationPoint kyglWpPoint = proBasicWppointMap.get(ContantXk.SSZKYGL);

            double ssglsyz = 0;
            if (proBasicWppointMap.containsKey(ContantXk.SSGLSYZ)) {
                ProBasicPowerstationPoint ssglsyzpoint = proBasicWppointMap.get(ContantXk.SSGLSYZ);
                try {
                    ssglsyz = edosUtil.getRealData(ssglsyzpoint).getPointValueInDouble();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            if (proBasicWppointMap.containsKey(ContantXk.SSZGLSYZ)) {
                ProBasicPowerstationPoint sszglsyzpoint = proBasicWppointMap.get(ContantXk.SSZGLSYZ);
                lineResultList.add(PointUtil.createPointData(currentDate, ssglsyz, sszglsyzpoint.getNemCode(), sszglsyzpoint.getName()));
            }

            AtomicInteger wtnumber = new AtomicInteger();
            //            proBasicWindturbines.stream().forEach(wt -> {
            for (ProBasicEquipment wt : proBasicWindturbines) {
                Map<String, ProBasicEquipmentPoint> equipmentPointMap = wtpAimap.get(wt.getId());


                ProBasicEquipmentPoint mxztPoint = equipmentPointMap.get(ContantXk.MXZT);
                double ssztmx = 0;
                try {
                    ssztmx = edosUtil.getRealData(mxztPoint).getPointValueInDouble();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
                if (ssztmx == 12 || ssztmx == 13) {
                    continue;
                }

                ProBasicEquipmentPoint ssbfPoint = null;
                //                if (wt.getId().contains("_WT_")) {
                //                    ssbfPoint = equipmentPointMap.get(ContantXk.SSBF);
                //                } else if (wt.getId().contains("_IN_")) {
                //                    ssbfPoint = equipmentPointMap.get(ContantXk.SSBG);
                //                }

                if (wt.getId().contains("_WT_")) {
                    ssbfPoint = equipmentPointMap.get(ContantXk.CJ_SSFS);
                } else if (wt.getId().contains("_IN_")) {
                    ssbfPoint = equipmentPointMap.get(ContantXk.CJ_SSFS);
                }

                //                ProBasicEquipmentPoint ssbfPoint = equipmentPointMap.get(ContantXk.SSBF);
                ProBasicEquipmentPoint ssglPoint = equipmentPointMap.get(ContantXk.CJ_SSGL);
                //理论功率测点
                ProBasicEquipmentPoint llglPoint = equipmentPointMap.get(ContantXk.LLGL);
                //保证功率测点
                ProBasicEquipmentPoint bzglPoint = equipmentPointMap.get(ContantXk.BZGL);
                //自算功率测点
                ProBasicEquipmentPoint zsglPoint = equipmentPointMap.get(ContantXk.ZSGL);
                //最优功率测点
                ProBasicEquipmentPoint zyglPoint = equipmentPointMap.get(ContantXk.ZYGL);
                //                //可用功率测点
                //                ProBasicEquipmentPoint kyglPoint = equipmentPointMap.get(ContantXk.KYGL);

                ProBasicEquipmentPoint finalSsbfPoint = ssbfPoint;
                zssbf.updateAndGet(v -> {
                    try {
                        if (wt.getId().contains("_F_")) {
                            double speed = edosUtil.getRealData(finalSsbfPoint).getPointValueInDouble();
                            if (speed < 100 && speed > 0) {
                                wtnumber.getAndIncrement();
                                return new Double((double) (v + speed));
                            }
                        } else {
                            wtnumber.getAndIncrement();
                            return new Double((double) (v + edosUtil.getRealData(finalSsbfPoint).getPointValueInDouble()));
                        }


                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zssgl.updateAndGet(v -> {
                    try {
                        double ssgl = edosUtil.getRealData(ssglPoint).getPointValueInDouble();
                        if (CacheContext.modelMap.containsKey(wt.getModelId())) {
                            ProEconEquipmentmodel model = CacheContext.modelMap.get(wt.getModelId());
                            double value = model.getPowerProduction() * 24 * 1.5;
                            if (ssgl > value) {
                                ssgl = value;
                            }
                        }

                        return new Double((double) (v + ssgl));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zllgl.updateAndGet(v -> {
                    try {

                        return new Double((double) (v + edosUtil.getRealData(llglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zbzgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(bzglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zzsgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(zsglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zzygl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(zyglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                //                zkygl.updateAndGet(v -> {
                //                    try {
                //                        return new Double((double) (v + edosUtil.getRealData(kyglPoint).getPointValueInDouble()));
                //                    } catch (Exception e) {
                //                        e.printStackTrace();
                //                    }
                //                    return v;
                //                });
                //            });
            }
            if (wtnumber.get() != 0) {
                lineResultList.add(PointUtil.createPointData(currentDate, zssbf.get() / wtnumber.get(), ssfsWpPoint.getNemCode(), ssfsWpPoint.getName()));
            }

            lineResultList.add(PointUtil.createPointData(currentDate, zssgl.get(), ssglWpPoint.getNemCode(), ssglWpPoint.getName()));
            lineResultList.add(PointUtil.createPointData(currentDate, zllgl.get(), llglWpPoint.getNemCode(), llglWpPoint.getName()));
            lineResultList.add(PointUtil.createPointData(currentDate, zbzgl.get(), bzglWpPoint.getNemCode(), bzglWpPoint.getName()));
            lineResultList.add(PointUtil.createPointData(currentDate, zzsgl.get(), zsglWpPoint.getNemCode(), zsglWpPoint.getName()));
            lineResultList.add(PointUtil.createPointData(currentDate, zzygl.get(), zyglWpPoint.getNemCode(), zyglWpPoint.getName()));
            //            lineResultList.add(PointUtil.createPointData(currentDate, zkygl.get(), kyglWpPoint.getNemCode(), kyglWpPoint.getName()));
        });
        edosUtil.sendMultiPoint(lineResultList);
        //保存期次点
        List<PointData> projectResultList = new ArrayList<>();
        pjls.stream().forEach(project -> {
            List<ProBasicLine> proBasicLines = prolinemap.get(project.getId());
            Map<String, ProBasicPowerstationPoint> proBasicWppointMap = propointmap.get(project.getId());
            AtomicReference<Double> zssbf = new AtomicReference<>((double) 0);
            AtomicReference<Double> zssgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zllgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zbzgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zzsgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zzygl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zkygl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zssglsyz = new AtomicReference<>((double) 0);

            ProBasicPowerstationPoint ssfsWpPoint = null;
            if (null != project.getSpare4()){
                if (project.getSpare4().equals("1")) {
                    ssfsWpPoint = proBasicWppointMap.get(ContantXk.SSPJFS);
                } else if (project.getSpare4().equals("2")) {
                    ssfsWpPoint = proBasicWppointMap.get(ContantXk.SSPJGZD);
                }
            }
            ProBasicPowerstationPoint ssglWpPoint = proBasicWppointMap.get(ContantXk.SSZGL);
            ProBasicPowerstationPoint llglWpPoint = proBasicWppointMap.get(ContantXk.SSZLLGL);
            ProBasicPowerstationPoint bzglWpPoint = proBasicWppointMap.get(ContantXk.SSZBZGL);
            ProBasicPowerstationPoint zsglWpPoint = proBasicWppointMap.get(ContantXk.SSZNHGLZS);
            ProBasicPowerstationPoint zyglWpPoint = proBasicWppointMap.get(ContantXk.SSZZYGL);
            //            ProBasicPowerstationPoint kyglWpPoint = proBasicWppointMap.get(ContantXk.SSZKYGL);
            ProBasicPowerstationPoint ssglsyzWpPoint = proBasicWppointMap.get(ContantXk.SSZGLSYZ);

            proBasicLines.stream().forEach(ln -> {
                Map<String, ProBasicPowerstationPoint> basicWppointMap = linepointmap.get(ln.getId());
                ProBasicPowerstationPoint ssbfPoint = null;
                if (ln.getSpare4().equals("1")) {
                    ssbfPoint = basicWppointMap.get(ContantXk.SSPJFS);
                } else if (ln.getSpare4().equals("2")) {
                    ssbfPoint = basicWppointMap.get(ContantXk.SSPJGZD);
                }

                ProBasicPowerstationPoint ssglPoint = basicWppointMap.get(ContantXk.SSZGL);
                ProBasicPowerstationPoint ssglsyzPoint = basicWppointMap.get(ContantXk.SSZGLSYZ);
                //理论功率测点
                ProBasicPowerstationPoint llglPoint = basicWppointMap.get(ContantXk.SSZLLGL);
                //保证功率测点
                ProBasicPowerstationPoint bzglPoint = basicWppointMap.get(ContantXk.SSZBZGL);
                //自算功率测点
                ProBasicPowerstationPoint zsglPoint = basicWppointMap.get(ContantXk.SSZNHGLZS);
                //最优功率测点
                ProBasicPowerstationPoint zyglPoint = basicWppointMap.get(ContantXk.SSZZYGL);
                //                //可用功率测点
                //                ProBasicPowerstationPoint kyglPoint = basicWppointMap.get(ContantXk.SSZKYGL);

                ProBasicPowerstationPoint finalSsbfPoint = ssbfPoint;
                zssbf.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(finalSsbfPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zssgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(ssglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zssglsyz.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(ssglsyzPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zllgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(llglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zbzgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(bzglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zzsgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(zsglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zzygl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(zyglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                //                zkygl.updateAndGet(v -> {
                //                    try {
                //                        return new Double((double) (v + edosUtil.getRealData(kyglPoint).getPointValueInDouble()));
                //                    } catch (Exception e) {
                //                        e.printStackTrace();
                //                    }
                //                    return v;
                //                });
            });
            if (null != ssfsWpPoint){
                projectResultList.add(PointUtil.createPointData(currentDate, zssbf.get() / proBasicLines.size(), ssfsWpPoint.getNemCode(), ssfsWpPoint.getName()));
            }
            projectResultList.add(PointUtil.createPointData(currentDate, zssgl.get(), ssglWpPoint.getNemCode(), ssglWpPoint.getName()));
            projectResultList.add(PointUtil.createPointData(currentDate, zssglsyz.get(), ssglsyzWpPoint.getNemCode(), ssglsyzWpPoint.getName()));
            projectResultList.add(PointUtil.createPointData(currentDate, zllgl.get(), llglWpPoint.getNemCode(), llglWpPoint.getName()));
            projectResultList.add(PointUtil.createPointData(currentDate, zbzgl.get(), bzglWpPoint.getNemCode(), bzglWpPoint.getName()));
            projectResultList.add(PointUtil.createPointData(currentDate, zzsgl.get(), zsglWpPoint.getNemCode(), zsglWpPoint.getName()));
            projectResultList.add(PointUtil.createPointData(currentDate, zzygl.get(), zyglWpPoint.getNemCode(), zyglWpPoint.getName()));
            //            projectResultList.add(PointUtil.createPointData(currentDate, zkygl.get(), kyglWpPoint.getNemCode(), kyglWpPoint.getName()));
        });
        edosUtil.sendMultiPoint(projectResultList);
        //保存场站点
        List<PointData> wpResultList = new ArrayList<>();
        wpls.stream().forEach(wps -> {
            List<ProBasicProject> proBasicProjects = wppromap.get(wps.getId());
            Map<String, ProBasicPowerstationPoint> proBasicWppointMap = wppointmap.get(wps.getId());
            AtomicReference<Double> zssbf = new AtomicReference<>((double) 0);
            AtomicReference<Double> zssgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zssglsyz = new AtomicReference<>((double) 0);
            AtomicReference<Double> zllgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zbzgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zzsgl = new AtomicReference<>((double) 0);
            AtomicReference<Double> zzygl = new AtomicReference<>((double) 0);
            //            AtomicReference<Double> zkygl = new AtomicReference<>((double) 0);

            ProBasicPowerstationPoint ssfsWpPoint = null;
            if (wps.getWindType().equals("-1")) {
                ssfsWpPoint = proBasicWppointMap.get(ContantXk.SSPJFS);
            } else if (wps.getWindType().equals("-2")) {
                ssfsWpPoint = proBasicWppointMap.get(ContantXk.SSPJGZD);
            }

            ProBasicPowerstationPoint ssglWpPoint = proBasicWppointMap.get(ContantXk.SSZGL);
            ProBasicPowerstationPoint ssglsyzWpPoint = proBasicWppointMap.get(ContantXk.SSZGLSYZ);
            ProBasicPowerstationPoint llglWpPoint = proBasicWppointMap.get(ContantXk.SSZLLGL);
            ProBasicPowerstationPoint bzglWpPoint = proBasicWppointMap.get(ContantXk.SSZBZGL);
            ProBasicPowerstationPoint zsglWpPoint = proBasicWppointMap.get(ContantXk.SSZNHGLZS);
            ProBasicPowerstationPoint zyglWpPoint = proBasicWppointMap.get(ContantXk.SSZZYGL);
            //            ProBasicPowerstationPoint kyglWpPoint = proBasicWppointMap.get(ContantXk.SSZKYGL);

            proBasicProjects.stream().forEach(pj -> {
                Map<String, ProBasicPowerstationPoint> basicWppointMap = propointmap.get(pj.getId());

                ProBasicPowerstationPoint ssbfPoint = null;
                if (null != pj.getSpare4()){
                    if (pj.getSpare4().equals("1")) {
                        ssbfPoint = basicWppointMap.get(ContantXk.SSPJFS);
                    } else if (pj.getSpare4().equals("2")) {
                        ssbfPoint = basicWppointMap.get(ContantXk.SSPJGZD);
                    }
                }
                ProBasicPowerstationPoint ssglPoint = basicWppointMap.get(ContantXk.SSZGL);
                ProBasicPowerstationPoint ssglsyzPoint = basicWppointMap.get(ContantXk.SSZGLSYZ);
                //理论功率测点
                ProBasicPowerstationPoint llglPoint = basicWppointMap.get(ContantXk.SSZLLGL);
                //保证功率测点
                ProBasicPowerstationPoint bzglPoint = basicWppointMap.get(ContantXk.SSZBZGL);
                //自算功率测点
                ProBasicPowerstationPoint zsglPoint = basicWppointMap.get(ContantXk.SSZNHGLZS);
                //最优功率测点
                ProBasicPowerstationPoint zyglPoint = basicWppointMap.get(ContantXk.SSZZYGL);
                //                //可用功率测点
                //                ProBasicPowerstationPoint kyglPoint = basicWppointMap.get(ContantXk.SSZKYGL);

                ProBasicPowerstationPoint finalSsbfPoint = ssbfPoint;
                zssbf.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(finalSsbfPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zssgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(ssglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zssglsyz.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(ssglsyzPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zllgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(llglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zbzgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(bzglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zzsgl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(zsglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                zzygl.updateAndGet(v -> {
                    try {
                        return new Double((double) (v + edosUtil.getRealData(zyglPoint).getPointValueInDouble()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return v;
                });
                //                zkygl.updateAndGet(v -> {
                //                    try {
                //                        return new Double((double) (v + edosUtil.getRealData(kyglPoint).getPointValueInDouble()));
                //                    } catch (Exception e) {
                //                        e.printStackTrace();
                //                    }
                //                    return v;
                //                });
            });
            wpResultList.add(PointUtil.createPointData(currentDate, zssbf.get() / proBasicProjects.size(), ssfsWpPoint.getNemCode(), ssfsWpPoint.getName()));
            wpResultList.add(PointUtil.createPointData(currentDate, zssgl.get(), ssglWpPoint.getNemCode(), ssglWpPoint.getName()));
            wpResultList.add(PointUtil.createPointData(currentDate, zssglsyz.get(), ssglsyzWpPoint.getNemCode(), ssglsyzWpPoint.getName()));
            wpResultList.add(PointUtil.createPointData(currentDate, zllgl.get(), llglWpPoint.getNemCode(), llglWpPoint.getName()));
            wpResultList.add(PointUtil.createPointData(currentDate, zbzgl.get(), bzglWpPoint.getNemCode(), bzglWpPoint.getName()));
            wpResultList.add(PointUtil.createPointData(currentDate, zzsgl.get(), zsglWpPoint.getNemCode(), zsglWpPoint.getName()));
            wpResultList.add(PointUtil.createPointData(currentDate, zzygl.get(), zyglWpPoint.getNemCode(), zyglWpPoint.getName()));
            //            wpResultList.add(PointUtil.createPointData(currentDate, zkygl.get(), kyglWpPoint.getNemCode(), kyglWpPoint.getName()));
        });
        edosUtil.sendMultiPoint(wpResultList);
        end = new Date();
        System.out.println("执行用时" + DateUtils.millisecondDiff(begin, end) + "秒");
        System.out.println("实时场站计算指标调度程序执行结束!。。。。。。");
    }
}
