package com.gyee.frame.service.websocket;

import com.gyee.frame.common.spring.Constant;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.model.agc.AgcVo;
import com.gyee.frame.model.auto.WindPowerStationTestingPoint;
import com.gyee.frame.model.auto.Windpowerstation;
import com.gyee.frame.model.custom.PointData;
import com.gyee.frame.service.WindPowerstationTestingPoint2Service;
import com.gyee.frame.util.DateUtils;
import com.gyee.frame.util.IRealTimeDataBaseUtil;
import com.gyee.frame.util.MathUtil;
import com.gyee.frame.util.StringUtils;
import com.gyee.frame.util.golden.EdosUtil;
import org.springframework.stereotype.Service;

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

/**
 * @ClassName : AgcService
 * @Author : xieshengjie
 * @Date: 2021/5/29 11:47
 * @Description : AGCservice
 */
@Service
public class AgcService {

    private IRealTimeDataBaseUtil ednaApiUtil = new EdosUtil();
    @Resource
    private WindPowerstationTestingPoint2Service windPowerstationTestingPoint2Service;
    String[] ycPoints1 = Constant.TPOINT_WP_FGLYC.split(",");

    public List<Map<String, Object>> getAgcValues() throws Exception {
        List<Map<String, Object>> vos=new ArrayList<>();

        Map<String, Object> objmap=getAgcVals();


        Map<String, Object> linemap=getAgcLine();

        for (Windpowerstation wp : InitialRunner.wpallls) {
            if (wp.getId().equals("MCH_GDC")) {
                continue;
            }

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

            if(objmap.containsKey(wp.getId()))
            {
                map.put("jcxx",objmap.get(wp.getId()));
            }

            if(linemap.containsKey(wp.getId()))
            {
                map.put("tb",linemap.get(wp.getId()));
            }

            vos.add(map);
            if(wp.getId().equals("QS_FDC"))
            {

                Map<String, Object> tempmap=new HashMap<>();
                if(objmap.containsKey("QS_FDC02"))
                {
                    tempmap.put("jcxx",objmap.get("QS_FDC02"));
                }

                if(linemap.containsKey("QS_FDC02"))
                {
                    tempmap.put("tb",linemap.get("QS_FDC02"));
                }

                vos.add(tempmap);
            }else if(wp.getId().equals("SBQ_FDC"))
            {
                Map<String, Object> tempmap=new HashMap<>();
                if(objmap.containsKey("SBQ_FDC02"))
                {
                    tempmap.put("jcxx",objmap.get("SBQ_FDC02"));
                }

                if(linemap.containsKey("SBQ_FDC02"))
                {
                    tempmap.put("tb",linemap.get("SBQ_FDC02"));
                }

                vos.add(tempmap);
            }

        }
        return vos;
    }

    /**
     * 获取agc页面点实时数据
     * @return
     * @throws Exception
     */
    public Map<String, Object> getAgcVals() throws Exception {

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

        List<Windpowerstation> wpList = InitialRunner.wpallls;
        for (Windpowerstation wp : wpList) {
            if (wp.getId().equals("MCH_GDC")) {
                continue;
            }
            Map<String, Object> resultmap = new HashMap<String, Object>();
            String[] agcPoints = Constant.TPOINT_WP_AGC;

            Map<String, WindPowerStationTestingPoint> map = InitialRunner.wpPointmap.get(wp.getId());

            for (int i = 0; i < agcPoints.length; i++) {
                String ai;
                if (map.get(agcPoints[i])!=null) {
                    ai = map.get(agcPoints[i]).getCode();
                    if (ai != null) {
                        PointData data;
                        try {
                            data = ednaApiUtil.getRealData(ai);
                            if (data != null) {

                                if(i==0) {
                                    if (wp.getId().equals("MHS_FDC") || wp.getId().equals("NSS_FDC") || wp.getId().equals("XS_FDC")){
                                        double  llgl = new BigDecimal(data.getPointValueInDouble()).divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP).doubleValue();
                                        resultmap.put( agcPoints[i],llgl);
                                    }else{
                                        resultmap.put( agcPoints[i],
                                                MathUtil.decimal(data.getPointValueInDouble(), 2));
                                    }
                                }else if(i==2){
                                    if (wp.getId().equals("SBQ_FDC")){
                                        double  llgl = new BigDecimal(data.getPointValueInDouble()).divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP).doubleValue();
                                        resultmap.put( agcPoints[i],llgl);
                                    }else{
                                        resultmap.put( agcPoints[i],
                                                MathUtil.decimal(data.getPointValueInDouble(), 2));
                                    }
                                }else if(i==4){
                                    if (wp.getId().equals("MHS_FDC")){
                                        double  llgl = new BigDecimal(data.getPointValueInDouble()).divide(new BigDecimal(10), 2, RoundingMode.HALF_UP).doubleValue();
                                        resultmap.put( agcPoints[i],llgl);
                                    }else if(wp.getId().equals("NSS_FDC")){
                                        double  llgl = new BigDecimal(data.getPointValueInDouble()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).doubleValue();
                                        resultmap.put( agcPoints[i],llgl);
                                    }else{
                                        resultmap.put( agcPoints[i],
                                                MathUtil.decimal(data.getPointValueInDouble(), 2));
                                    }
                                }
                                else if(i==5){
                                    if (wp.getId().equals("MHS_FDC")){
                                        double  llgl = new BigDecimal(data.getPointValueInDouble()).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP).doubleValue();
                                        resultmap.put( agcPoints[i],llgl);
                                    }else if(wp.getId().equals("NSS_FDC")){
                                        double  llgl = new BigDecimal(data.getPointValueInDouble()).divide(new BigDecimal(10), 2, RoundingMode.HALF_UP).doubleValue();
                                        resultmap.put( agcPoints[i],llgl);
                                    }else{
                                        resultmap.put( agcPoints[i],
                                                MathUtil.decimal(data.getPointValueInDouble(), 2));
                                    }
                                }
                                else {
                                    resultmap.put( agcPoints[i],
                                            MathUtil.decimal(data.getPointValueInDouble(), 2));


                                }


                            }else{
                                resultmap.put(agcPoints[i],0.0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }

            }

            PointData data = ednaApiUtil.getRealData(windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), ycPoints1[0]));
            resultmap.put("ycgl",MathUtil.decimal(data.getPointValueInDouble(), 2));
            data = ednaApiUtil.getRealData(windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2(wp.getId(), Constant.FJZT));
            double zt=data.getPointValueInDouble();
            if(zt==5)
            {
                resultmap.put("zt",0);
            }else
            {
                resultmap.put("zt",1);
            }

            resultmap.put("name",wp.getName());

            if(wp.getId().equals("SBQ_FDC"))
            {
                resultmap.put("ddmc","星能第六风电场");
            }else  if(wp.getId().equals("MHS_FDC")){
                resultmap.put("ddmc","麻黄山第二风电场");
            }else  if(wp.getId().equals("NSS_FDC")){
                resultmap.put("ddmc","牛首山第二风电场");
            }else  if(wp.getId().equals("QS_FDC")){
                resultmap.put("ddmc","麻黄山第六风电场");
            }else  if(wp.getId().equals("XS_FDC")){
                resultmap.put("ddmc","香山第五风电场");
            }else  {
                resultmap.put("ddmc",wp.getName());
            }

            objmap.put(wp.getId(),resultmap);
            if (wp.getId().equals("SBQ_FDC")){

                Map<String, Object> tempmap = new HashMap<String, Object>();
                /*牛五*/
                double nwllgl = ednaApiUtil.getRealData("SBQFCJSFW.NX_GD_SBQF_FJ_P2_XXX_XXX_CI0192").getPointValueInDouble()
                        +ednaApiUtil.getRealData("SBQFCJSFW.NX_GD_SBQF_FJ_P3_XXX_XXX_CI0192").getPointValueInDouble()
                        +ednaApiUtil.getRealData("SBQFCJSFW.NX_GD_SBQF_FJ_P4_XXX_XXX_CI0192").getPointValueInDouble();
                double nwcxgl = ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_AI0817").getPointValueInDouble();
                double nwxdzl = ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_AI0818").getPointValueInDouble();
                double nwygsx = ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_AI0819").getPointValueInDouble();
                double nwygxx = ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_AI0820").getPointValueInDouble();
                double nwyf =  ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_DI3832").getPointValueInDouble();
                double nwtt =  ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_DI3831").getPointValueInDouble();
                double nwjbs =ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_DI3834").getPointValueInDouble();
                double nwzbs = ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_DI3833").getPointValueInDouble();
                double nwzzttzt = ednaApiUtil.getRealData("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_DI2253").getPointValueInDouble();
                double xlllgl = ednaApiUtil.getRealData("SBQFCJSFW.NX_GD_SBQF_FJ_P1_XXX_XXX_CI0192").getPointValueInDouble();

                double sjgl = ednaApiUtil.getRealData("SBQFCJSFW.NX_GD_SBQF_FJ_P4_XXX_XXX_CI0134").getPointValueInDouble();
                Map<String, Object> tempmap2=(Map<String, Object>)objmap.get(wp.getId());
                tempmap2.put("ZZSGL", MathUtil.decimal(xlllgl/1000,2));

                tempmap.put("SSZGL", MathUtil.decimal(sjgl,2));
                tempmap.put("ZZSGL", MathUtil.decimal(nwllgl/1000,2));
                tempmap.put("AGC001", MathUtil.decimal(nwcxgl,2));
                tempmap.put("AGC002", MathUtil.decimal(nwxdzl,2));
                tempmap.put("AGC003", MathUtil.decimal(nwygsx,2));
                tempmap.put("AGC004", MathUtil.decimal(nwygxx,2));
                tempmap.put("AGC005", MathUtil.decimal(nwyf,2));
                tempmap.put("AGC006", MathUtil.decimal(nwtt,2));
                tempmap.put("AGC007", MathUtil.decimal(nwjbs,2));
                tempmap.put("AGC008", MathUtil.decimal(nwzbs,2));
                tempmap.put("AVC005", MathUtil.decimal(nwzzttzt,2));

                tempmap.put("ycgl",0.0);
                tempmap.put("name",wp.getName());
                tempmap.put("ddmc","牛首山第五风电场");

                data = ednaApiUtil.getRealData(windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2("SBQ04_GC", Constant.FJZT));
                zt=data.getPointValueInDouble();
                if(zt==5)
                {
                    tempmap.put("zt",0);
                }else
                {
                    tempmap.put("zt",1);
                }
                objmap.put("SBQ_FDC02",tempmap);
            }else if(wp.getId().equals("QS_FDC")){
                /*宋六*/
                Map<String, Object> tempmap = new HashMap<String, Object>();
                double slllgl = ednaApiUtil.getRealData("QSFCJSFW.NX_GD_QSF_FJ_P3_XXX_XXX_CI0192").getPointValueInDouble();
                double slcxgl = ednaApiUtil.getRealData("SLDQ.NX_GD_QSF_DQ_P1_L1_001_AI0013").getPointValueInDouble()/1000;
                double slxdzl = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_AI0052").getPointValueInDouble();
                double slygsx = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_AI0053").getPointValueInDouble();
                double slygxx = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_AI0054").getPointValueInDouble();
                double slyf =  ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0143").getPointValueInDouble();
                double sltt =  ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0142").getPointValueInDouble();
                double sljbs =ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0163").getPointValueInDouble();
                double slzbs = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0162").getPointValueInDouble();

//                double mxdysj = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_AI0025").getPointValueInDouble();
//                double mxdytk = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_AI0026").getPointValueInDouble();
//                double mxkjwg = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_AI0022").getPointValueInDouble();
                double qsllgl = ednaApiUtil.getRealData("QSFCJSFW.NX_GD_QSF_FJ_P1_XXX_XXX_CI0192").getPointValueInDouble()
                        + ednaApiUtil.getRealData("QSFCJSFW.NX_GD_QSF_FJ_P2_XXX_XXX_CI0192").getPointValueInDouble();
//                double mxkzwg = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_AI0021").getPointValueInDouble();
//                double zztt = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0170").getPointValueInDouble();
//                double zzyx = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0171") .getPointValueInDouble();
//                double jwgbs = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0133").getPointValueInDouble();
//                double zwgbs = ednaApiUtil.getRealData("SLAGC.NX_GD_QSF_DQ_P1_L1_001_DI0114").getPointValueInDouble();

                Map<String, Object> tempmap2=(Map<String, Object>)objmap.get(wp.getId());
                tempmap2.put("ZZSGL", MathUtil.decimal(qsllgl / 1000, 2));

                double sjgl = ednaApiUtil.getRealData("QSFCJSFW.NX_GD_QSF_FJ_P3_XXX_XXX_CI0134").getPointValueInDouble();
                tempmap.put("SSZGL", MathUtil.decimal(sjgl,2));

                tempmap.put("ZZSGL", MathUtil.decimal(slllgl/1000, 2));
                tempmap.put("AGC001", MathUtil.decimal(slcxgl, 2));
                tempmap.put("AGC002", MathUtil.decimal(slxdzl, 2));
                tempmap.put("AGC003", MathUtil.decimal(slygsx, 2));
                tempmap.put("AGC004", MathUtil.decimal(slygxx, 2));
                tempmap.put("AGC005", MathUtil.decimal(slyf, 2));
                tempmap.put("AGC006", MathUtil.decimal(sltt, 2));
                tempmap.put("AGC007", MathUtil.decimal(sljbs, 2));
                tempmap.put("AGC008", MathUtil.decimal(slzbs, 2));

//                tempmap.put("QS_FDC02_AVC001", MathUtil.decimal(mxdysj, 2));
//                tempmap.put("QS_FDC02_AVC002", MathUtil.decimal(mxdytk, 2));
//                tempmap.put("QS_FDC02_AVC003", MathUtil.decimal(mxkjwg, 2));
//                tempmap.put("QS_FDC02_AVC004", MathUtil.decimal(mxkzwg, 2));
//                tempmap.put("QS_FDC02_AVC005", MathUtil.decimal(zztt, 2));
//                tempmap.put("QS_FDC02_AVC006", MathUtil.decimal(zzyx, 2));
//                tempmap.put("QS_FDC02_AVC007", MathUtil.decimal(jwgbs, 2));
//                tempmap.put("QS_FDC02_AVC008", MathUtil.decimal(zwgbs, 2));
                tempmap.put("ycgl",0.0);
                tempmap.put("name",wp.getName());
                tempmap.put("ddmc","宋堡第六风电场");
                data = ednaApiUtil.getRealData(windPowerstationTestingPoint2Service.getWindPowerStationTestingPoint2("QS03_GC", Constant.FJZT));
                zt=data.getPointValueInDouble();
                if(zt==5)
                {
                    tempmap.put("zt",0);
                }else
                {
                    tempmap.put("zt",1);
                }
                objmap.put("QS_FDC02",tempmap);

            }
        }
        return objmap;
    }

    /**
     * agc页面曲线
     * @return
     * @throws Exception
     */
    public Map<String, Object> getAgcLine() throws Exception {
        Map<String, Object> resultmap = new HashMap<String, Object>();

        List<Windpowerstation> wpList = InitialRunner.wpallls;
        Calendar cal = Calendar.getInstance();
        cal.setTime(DateUtils.now());
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);

        Date beginDate = cal.getTime();

        Date endDate = DateUtils.getCurrHourTime(DateUtils.now());

        long num = DateUtils.hoursDiff(beginDate, endDate) * 2 + 1;
        if (cal.getInstance().get(Calendar.MINUTE) > 30) {
            num++;
        }
        String[] agcPoints = Constant.TPOINT_WP_AGC;
        String[] ycPoints = Constant.TPOINT_WP_FGLYC.split(",");
        String[] ycPointsSB = Constant.TPOINT_WP_FGLYCSB.split(",");
        String[] ycPoints2 = Constant.TPOINT_WP_FGLYC2.split(",");
        String[] ycPoints2SB = Constant.TPOINT_WP_FGLYC2SB.split(",");
        int length = 48;
        for (Windpowerstation wp : wpList) {
            Calendar cal2 = Calendar.getInstance();
            cal2.setTime(beginDate);
            List<AgcVo> vos = new ArrayList<>();
            for (int i = 0; i < length; i++) {
                AgcVo vo = new AgcVo();
//                vo.setSjgl(0.0);
//                vo.setLlgl(0.0);
//                vo.setXdzl(0.0);
                vo.setTime(cal2.getTime().getTime());
                cal2.add(Calendar.MINUTE, 30);
                vos.add(vo);
            }

            Map<String, WindPowerStationTestingPoint> map = InitialRunner.wpPointmap.get(wp.getId());

            WindPowerStationTestingPoint sjgl = map.get(agcPoints[3]);
            if (null != sjgl) {
                List<PointData> sjglls = ednaApiUtil.getHistoryDatasSnap(sjgl, beginDate.getTime() / 1000,
                        endDate.getTime() / 1000, (long) length, 1800L);
                double temp1 = 0;
                for (int i = 0; i < vos.size(); i++) {
                    if (i < sjglls.size() && StringUtils.notEmp(sjglls.get(i).getPointTime())) {
                        if (vos.get(i).getTime() <= new Date().getTime()) {
                            temp1 = sjglls.get(i).getPointValueInDouble();
                            temp1 = new BigDecimal(temp1).divide(new BigDecimal(1), 4, RoundingMode.HALF_EVEN)
                                    .doubleValue();
                            if ("MHS_FDC".equals(wp.getId())) {
                                vos.get(i).setSjgl(
                                        StringUtils.round(temp1, 2));
                            }else if("SBQ_FDC".equals(wp.getId())){
                                vos.get(i).setSjgl(StringUtils.round(temp1/1000, 2));
                            } else if ("DWK_GDC".equals(wp.getId())) {
                                vos.get(i).setSjgl(
                                        StringUtils.round(temp1 / 100, 2));
                            }else{
                                vos.get(i).setSjgl(StringUtils.round(temp1, 2));// 实际功率
                            }
                        } else {
                            vos.get(i).setSjgl(0d);// 实际功率
                        }
                    }
                }


            }
            WindPowerStationTestingPoint llgl = map.get(Constant.TPOINT_WP_ZZSGL);
            if (null != llgl) {
                List<PointData> llglls;
                if (wp.getId().equals("SBQ_FDC")) {
                    llglls= ednaApiUtil.getHistoryDatasSnap("SBQFCJSFW.NX_GD_SBQF_FJ_P1_XXX_XXX_CI0192", beginDate.getTime() / 1000,
                            endDate.getTime() / 1000, (long) length, 1800L);
                } else if (wp.getId().equals("QS_FDC")) {
                    llglls = ednaApiUtil.getHistoryDatasSnap(
                            "QSFCJSFW.NX_GD_QSF_FJ_P1_XXX_XXX_CI0192",
                            beginDate.getTime() / 1000,
                            endDate.getTime() / 1000, (long) length, 1800L);
                    llglls = ednaApiUtil.getHistoryDatasSnap(
                            "QSFCJSFW.NX_GD_QSF_FJ_P2_XXX_XXX_CI0192",
                            beginDate.getTime() / 1000,
                            endDate.getTime() / 1000, (long) length, 1800L);

                } else {
                    llglls= ednaApiUtil.getHistoryDatasSnap(llgl, beginDate.getTime() / 1000,
                            endDate.getTime() / 1000, (long) length, 1800L);
                }
                int count = 0;
                double temp1 = 0;
                for (int i = 0; i < vos.size(); i++) {

                    if (i < llglls.size() && StringUtils.notEmp(llglls.get(i).getPointTime())) {

                        if (vos.get(i).getTime() <= new Date().getTime()) {
                            temp1 = llglls.get(i).getPointValueInDouble() / 1000;
                            vos.get(i).setLlgl(StringUtils.round(temp1, 2));// 理论功率
                        } else {
                            vos.get(i).setLlgl(0d);// 理论功率
                        }
                    }
                }

            }
            WindPowerStationTestingPoint xdgl = map.get(agcPoints[2]);
            if (null != xdgl) {
                List<PointData> xdglls = ednaApiUtil.getHistoryDatasSnap(xdgl, beginDate.getTime() / 1000,
                        endDate.getTime() / 1000, (long) length, 1800L);
                double temp1 = 0;
                for (int i = 0; i < vos.size(); i++) {

                    if (i < xdglls.size() && StringUtils.notEmp(xdglls.get(i).getPointTime())) {

                        if (vos.get(i).getTime() <= new Date().getTime()) {
                            if (wp.getId().equals("SBQ_FDC")){
                                temp1 = xdglls.get(i).getPointValueInDouble()/1000;
                                vos.get(i).setXdzl(StringUtils.round(temp1, 2));// 限电功率
                            }else {
                                temp1 = xdglls.get(i).getPointValueInDouble();
                                vos.get(i).setXdzl(StringUtils.round(temp1, 2));// 限电功率
                            }

                        } else {
                            vos.get(i).setXdzl(0d);// 限电功率
                        }
                    }
                }

            }
            if (wp.getId().equals("SBQ_FDC")) {
                if (map.containsKey(ycPointsSB[0])) {
                    if ("CL_FDC".equals(wp.getId())) {

                    } else {
                        WindPowerStationTestingPoint ycgl1 = map.get(ycPoints[0]);
                        if (num > 0) {
                            List<PointData> datas = new ArrayList<PointData>();
                            datas = ednaApiUtil.getHistoryDatasSnap(ycgl1, beginDate.getTime() / 1000,
                                    endDate.getTime() / 1000, num, 1800L);
                            for (int j = 0; j < datas.size(); j++) {
                                vos.get(j).setYcgl(StringUtils.round(datas.get(j).getPointValueInDouble(), 2));
                            }
                            int subresult = 0;
                            int total = 0;
                            if (length > datas.size()) {
                                subresult = length - datas.size();
                                if (subresult >= 8) {
                                    subresult = 8;
                                }
                                for (int i = 0; i < subresult; i++) {
                                    WindPowerStationTestingPoint ycgl = map.get(ycPoints2SB[i]);
                                    double value = 0.0;
                                    value = ednaApiUtil.getRealData(ycgl).getPointValueInDouble();
                                    vos.get(datas.size() + i).setYcgl(StringUtils.round(value, 2));
                                }
                                total = datas.size() + subresult;
                                subresult = length - (total);
                                if (subresult > 0) {
                                    for (int i = 0; i < subresult; i++) {
                                        cal.add(Calendar.MINUTE, 30);
                                        vos.get(total + i).setYcgl(null);
                                    }
                                }

                            }
                        }
                    } // else结束
                }
            }else{
                if (map.containsKey(ycPoints[0])) {
                    if ("CL_FDC".equals(wp.getId())) {

                    } else {
                        WindPowerStationTestingPoint ycgl1 = map.get(ycPoints[0]);
                        if (num > 0) {
                            List<PointData> datas = new ArrayList<PointData>();
                            datas = ednaApiUtil.getHistoryDatasSnap(ycgl1, beginDate.getTime() / 1000,
                                    endDate.getTime() / 1000, num, 1800L);
                            for (int j = 0; j < datas.size(); j++) {
                                vos.get(j).setYcgl(StringUtils.round(datas.get(j).getPointValueInDouble(), 2));
                            }
                            int subresult = 0;
                            int total = 0;
                            if (length > datas.size()) {
                                subresult = length - datas.size();
                                if (subresult >= 8) {
                                    subresult = 8;
                                } else {
                                    subresult = length - datas.size();
                                }
                                for (int i = 0; i < subresult; i++) {
                                    WindPowerStationTestingPoint ycgl = map
                                            .get(ycPoints2[i]);
                                    WindPowerStationTestingPoint ycgld = map
                                            .get(ycPoints[i]);
                                    double value = 0.0;
                                    int minute = Calendar.getInstance().get(
                                            Calendar.MINUTE);
                                    if ((minute >= 0 && minute < 15)
                                            || (minute >= 30 && minute < 45)) {
                                        value = ednaApiUtil.getRealData(ycgld)
                                                .getPointValueInDouble();
                                    } else {
                                        value = ednaApiUtil.getRealData(ycgl)
                                                .getPointValueInDouble();
                                    }
                                    vos.get(datas.size() + i).setYcgl(
                                            StringUtils.round(value, 2));
                                }
                                total = datas.size() + subresult;
                                subresult = length - (total);
                                if (subresult > 0) {
                                    for (int i = 0; i < subresult; i++) {
                                        cal.add(Calendar.MINUTE, 30);
                                        vos.get(total + i).setYcgl(null);
                                    }
                                }

                            }
                        }
                    } // else结束
                }
            }


            resultmap.put(wp.getId(), vos);
        }

        // 牛五
        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(beginDate);
        List<AgcVo> vos = new ArrayList<>();
        for (int i = 0; i < length; i++) {
            AgcVo vo = new AgcVo();
//            vo.setValue1(0.0);
//            vo.setValue2(0.0);
//            vo.setValue3(0.0);
            vo.setTime(cal2.getTime().getTime());
            cal2.add(Calendar.MINUTE, 30);
            vos.add(vo);
        }
        List<PointData> nwsjglls = ednaApiUtil.getHistoryDatasSnap("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_AI0817",
                beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 1800L);
        double temp1 = 0;
        for (int i = 0; i < vos.size(); i++) {
            if (i < nwsjglls.size() && StringUtils.notEmp(nwsjglls.get(i).getPointTime())) {
                if (vos.get(i).getTime() <= new Date().getTime()) {
                    temp1 = nwsjglls.get(i).getPointValueInDouble();
                    temp1 = new BigDecimal(temp1).divide(new BigDecimal(1), 4, RoundingMode.HALF_EVEN).doubleValue();

                    vos.get(i).setSjgl(StringUtils.round(temp1, 2));// 实际功率
                } else {
                    vos.get(i).setSjgl(0d);// 实际功率
                }
            }

        }

        List<PointData> nwllglly = ednaApiUtil.getHistoryDatasSnap("SBQFCJSFW.NX_GD_SBQF_FJ_P2_XXX_XXX_CI0192",
                beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 1800L);
        List<PointData> nwllglle = ednaApiUtil.getHistoryDatasSnap("SBQFCJSFW.NX_GD_SBQF_FJ_P3_XXX_XXX_CI0192",
                beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 1800L);
        List<PointData> nwllglls = ednaApiUtil.getHistoryDatasSnap("SBQFCJSFW.NX_GD_SBQF_FJ_P4_XXX_XXX_CI0192",
                beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 1800L);

        for (int i = 0; i < vos.size(); i++) {

            if (i < nwllglls.size() && StringUtils.notEmp(nwllglls.get(i).getPointTime())) {

                if (vos.get(i).getTime() <= new Date().getTime()) {
                    temp1 = (nwllglly.get(i).getPointValueInDouble()+nwllglle.get(i).getPointValueInDouble()+nwllglls.get(i).getPointValueInDouble()) / 1000;
                    vos.get(i).setLlgl(StringUtils.round(temp1, 2));// 理论功率
                } else {
                    vos.get(i).setLlgl(0d);// 理论功率
                }
            }
        }

        List<PointData> nwxdglls = ednaApiUtil.getHistoryDatasSnap("SBQNWDQ.NX_GD_SBQF_DQ_P1_L1_001_AI0818",
                beginDate.getTime() / 1000, endDate.getTime() / 1000, (long) length, 1800L);
        for (int i = 0; i < vos.size(); i++) {

            if (i < nwxdglls.size() && StringUtils.notEmp(nwxdglls.get(i).getPointTime())) {

                if (vos.get(i).getTime() <= new Date().getTime()) {
                    temp1 = nwxdglls.get(i).getPointValueInDouble();
                    vos.get(i).setXdzl(StringUtils.round(temp1, 2));// 限电功率
                } else {
                    vos.get(i).setXdzl(0d);// 限电功率
                }
            }
        }

        List<PointData> datas = new ArrayList<PointData>();
        datas = ednaApiUtil.getHistoryDatasSnap("SBQFGL.NX_GD_SBQF_YC_P1_L1_002_DQ0001", beginDate.getTime() / 1000,
                endDate.getTime() / 1000, num, 1800L);
        for (int j = 0; j < datas.size(); j++) {
            vos.get(j).setYcgl(StringUtils.round(datas.get(j).getPointValueInDouble(), 2));
        }
        int subresult = 0;
        int total = 0;
        if (length > datas.size()) {
            subresult = length - datas.size();
            if (subresult >= 8) {
                subresult = 8;
            }
            for (int i = 0; i < subresult; i++) {

                double value = 0.0;
                value = ednaApiUtil.getRealData("SBQFGL.NX_GD_SBQF_YC_P1_L1_002_DQ0001").getPointValueInDouble();
                vos.get(datas.size() + i).setYcgl(StringUtils.round(value, 2));
            }
            total = datas.size() + subresult;
            subresult = length - (total);
            if (subresult > 0) {
                for (int i = 0; i < subresult; i++) {
                    cal.add(Calendar.MINUTE, 30);
                    vos.get(total + i).setYcgl(null);
                }
            }

        }
        resultmap.put("SBQ_FDC02", vos);

        // 宋六
        Calendar cal3 = Calendar.getInstance();
        cal3.setTime(beginDate);
        List<AgcVo> slvos = new ArrayList<>();
        for (int i = 0; i < length; i++) {
            AgcVo vo = new AgcVo();
//            vo.setValue1(0.0);
//            vo.setValue2(0.0);
//            vo.setValue3(0.0);
            vo.setTime(cal3.getTime().getTime());
            cal3.add(Calendar.MINUTE, 30);
            slvos.add(vo);
        }

        List<PointData> slsjglls = ednaApiUtil.getHistoryDatasSnap(
                "QSFCJSFW.NX_GD_QSF_FJ_P3_XXX_XXX_CI0134",
                beginDate.getTime() / 1000, endDate.getTime() / 1000,
                (long) length, 1800L);
        // double temp2 = 0;
        for (int i = 0; i < slvos.size(); i++) {
            if (i < slsjglls.size()
                    && StringUtils.notEmp(slsjglls.get(i).getPointTime())) {
                if (slvos.get(i).getTime() <= new Date().getTime()) {
                    temp1 = slsjglls.get(i).getPointValueInDouble();
                    temp1 = new BigDecimal(temp1).divide(new BigDecimal(1), 4,
                            RoundingMode.HALF_EVEN).doubleValue();

                    slvos.get(i).setSjgl(StringUtils.round(temp1, 2));// 实际功率
                } else {
                    slvos.get(i).setSjgl(0d);// 实际功率
                }
            }

        }
        List<PointData> slllglly = ednaApiUtil.getHistoryDatasSnap(
                "QSFCJSFW.NX_GD_QSF_FJ_P3_XXX_XXX_CI0192",
                beginDate.getTime() / 1000, endDate.getTime() / 1000,
                (long) length, 1800L);

        for (int i = 0; i < slvos.size(); i++) {

            if (i < slllglly.size()
                    && StringUtils.notEmp(slllglly.get(i).getPointTime())) {

                if (slvos.get(i).getTime() <= new Date().getTime()) {
                    temp1 = slllglly.get(i).getPointValueInDouble() / 1000;
                    slvos.get(i).setLlgl(StringUtils.round(temp1, 2));// 理论功率
                } else {
                    slvos.get(i).setLlgl(0d);// 理论功率
                }
            }
        }
        List<PointData> slxdglls = ednaApiUtil.getHistoryDatasSnap(
                "SLAGC.NX_GD_QSF_DQ_P1_L1_001_AI0052",
                beginDate.getTime() / 1000, endDate.getTime() / 1000,
                (long) length, 1800L);
        for (int i = 0; i < slvos.size(); i++) {

            if (i < slxdglls.size()
                    && StringUtils.notEmp(slxdglls.get(i).getPointTime())) {

                if (slvos.get(i).getTime() <= new Date().getTime()) {
                    temp1 = slxdglls.get(i).getPointValueInDouble();
                    slvos.get(i).setXdzl(StringUtils.round(temp1, 2));// 限电功率
                } else {
                    slvos.get(i).setXdzl(0d);// 限电功率
                }
            }
        }
        List<PointData> datas1 = ednaApiUtil.getHistoryDatasSnap(
                "SLFGL.NX_GD_QSF_YC_P1_L1_001_DQ0001",
                beginDate.getTime() / 1000, endDate.getTime() / 1000, num,
                1800L);
        for (int j = 0; j < datas1.size(); j++) {
            slvos.get(j)
                    .setYcgl(
                            StringUtils.round(datas1.get(j)
                                    .getPointValueInDouble(), 2));
        }
        int subresult1 = 0;
        int total1 = 0;
        if (length > datas1.size()) {
            subresult1 = length - datas1.size();
            if (subresult1 >= 8) {
                subresult1 = 8;
            }
            for (int i = 0; i < subresult1; i++) {

                double value = 0.0;
                value = ednaApiUtil.getRealData(
                        "SLFGL.NX_GD_QSF_YC_P1_L1_001_DQ0001")
                        .getPointValueInDouble();
                slvos.get(datas1.size() + i).setYcgl(
                        StringUtils.round(value, 2));
            }
            total1 = datas1.size() + subresult1;
            subresult1 = length - (total1);
            if (subresult1 > 0) {
                for (int i = 0; i < subresult1; i++) {
                    cal.add(Calendar.MINUTE, 30);
                    slvos.get(total1 + i).setYcgl(null);
                }
            }
        }
        resultmap.put("QS_FDC02", slvos);
        return resultmap;
    }







}
