package com.gyee.runeconomy.service.monitor;
/*
@author   谢生杰
@date   2023/3/28-8:49
*/

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.common.contant.ContantXk;
import com.gyee.common.model.PointData;
import com.gyee.common.util.DoubleUtils;
import com.gyee.common.util.SortUtils;
import com.gyee.common.vo.monitor.MatrixLineVo;
import com.gyee.common.vo.monitor.MatrixPowerVo;
import com.gyee.common.vo.monitor.MatrixProVo;
import com.gyee.common.vo.monitor.MatrixVo;
import com.gyee.runeconomy.controller.agc.AiPoints;
import com.gyee.runeconomy.init.CacheContext;
import com.gyee.runeconomy.model.auto.*;
import com.gyee.runeconomy.service.TokenService;
import com.gyee.runeconomy.service.auto.IProBasicPowerPointService;
import com.gyee.runeconomy.service.auto.IProBasicPowerstationPointService;
import com.gyee.runeconomy.service.auto.impl.ProEconManufacturerServiceImpl;
import com.gyee.runeconomy.util.StringUtils;
import com.gyee.runeconomy.util.realtimesource.IEdosUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

@Service
public class MatrixService {
    @Resource
    private IEdosUtil edosUtil;
    @Resource
    private TokenService tokenService;

    @Resource
    private IProBasicPowerPointService powerPointService;

    @Resource
    private IProBasicPowerstationPointService proBasicPowerstationPointService;

    @Resource
    private ProEconManufacturerServiceImpl proEconManufacturerService;

    public Map<String, Object> matrixMX(String company, String type) throws Exception {

        List<ProBasicPowerstation> wpls = CacheContext.wpls;

        Map<String, Double> modelpower = CacheContext.modelpower;

        if (company.endsWith("ZGS")) {
            wpls = wpls.stream().filter(wp -> wp.getCompanyId().equals(company)).collect(Collectors.toList());
        }
        if (type.equals("-1")) {
            wpls = wpls.stream().filter(wp -> wp.getWindType().equals("-1")).collect(Collectors.toList());
        } else if (type.equals("-2")) {
            wpls = wpls.stream().filter(wp -> wp.getWindType().equals("-2")).collect(Collectors.toList());
        }

        Map<String, Map<String, ProBasicPowerstationPoint>> wppointmap = CacheContext.wppointmap;
        Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
        Map<String, List<ProBasicEquipment>> wpwtmap = CacheContext.wpwtmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> subwppointmap = CacheContext.subwppointmap;

        List<ProBasicSubStation> subwpls = CacheContext.subwpls;

        List<MatrixPowerVo> powerVos = new ArrayList<>();
        AtomicInteger jrts = new AtomicInteger();
        AtomicInteger dfts = new AtomicInteger();
        AtomicInteger sdtj = new AtomicInteger();
        AtomicInteger zcyx = new AtomicInteger();
        AtomicInteger jclyx = new AtomicInteger();
        AtomicInteger gztj = new AtomicInteger();
        AtomicInteger gzsl = new AtomicInteger();
        AtomicInteger jxtj = new AtomicInteger();
        AtomicInteger jxsl = new AtomicInteger();
        AtomicInteger xdjcl = new AtomicInteger();
        AtomicInteger xdtj = new AtomicInteger();
        AtomicInteger dwsl = new AtomicInteger();
        AtomicInteger hjsl = new AtomicInteger();
        AtomicInteger lx = new AtomicInteger();
        AtomicInteger wz = new AtomicInteger();
        AtomicReference<Double> qf0 = new AtomicReference<>((double) 0);
        AtomicReference<Double> qf1 = new AtomicReference<>((double) 0);
        AtomicReference<Double> qf2 = new AtomicReference<>((double) 0);
        AtomicReference<Double> qf3 = new AtomicReference<>((double) 0);
        AtomicReference<Double> qf4 = new AtomicReference<>((double) 0);
        wpls.parallelStream().forEach(wp -> {
            List<MatrixVo> volist = new ArrayList<>();
            List<String> wpPoints = new ArrayList<>();
            List<String> wpglPoints = new ArrayList<>();
            List<String> wtPoints = new ArrayList<>();
            List<String> fjztPoints = new ArrayList<>();
            List<String> zktjPoints = new ArrayList<>();
            List<String> xglyxPoints = new ArrayList<>();
            List<String> jlgzPoints = new ArrayList<>();
            List<String> wtmxPoints = new ArrayList<>();
            List<String> wtPoints1 = new ArrayList<>();
            Map<String, ProBasicPowerstationPoint> pointMap = wppointmap.get(wp.getId());
            wpPoints.add(pointMap.get(ContantXk.DJTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.SDTJTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.XNTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.QXJCLTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.GZTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.CNSLGZTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.JXTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.CNSLJXTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.XDTJTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.XDJCLTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.CWSLDWTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.CWSLTQTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.LXTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.TXZDTSMX).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.SSZBZGL).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.SSZNHGLZS).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.SSZGL).getNemCode());
            wpglPoints.add(pointMap.get(ContantXk.SSZLLGL).getNemCode());

            List<ProBasicEquipment> equipments = wpwtmap.get(wp.getId());
            equipments.stream().forEach(wt -> {
                Map<String, ProBasicEquipmentPoint> equipmentPointMap = wtpAimap.get(wt.getId());
                wtPoints.add(equipmentPointMap.get(ContantXk.MXZT).getNemCode());
                wtmxPoints.add(equipmentPointMap.get(ContantXk.MXZT).getNemCode());
                wtPoints.add(equipmentPointMap.get(ContantXk.SSQFZT).getNemCode());
                wtPoints.add(equipmentPointMap.get(ContantXk.RQFDL).getNemCode());

                if (wt.getProjectId().equals("NX_FGS_HAF02_EG")) {
                    fjztPoints.add(equipmentPointMap.get(ContantXk.FJZT).getNemCode());
                    jlgzPoints.add(equipmentPointMap.get(ContantXk.JLGZ).getNemCode());
                    xglyxPoints.add(equipmentPointMap.get(ContantXk.XGLYX).getNemCode());
                    zktjPoints.add(equipmentPointMap.get(ContantXk.ZGTJ).getNemCode());
                }
            });
            equipments.stream().forEach(wt -> {
                Map<String, ProBasicEquipmentPoint> equipmentPointMap = wtpAimap.get(wt.getId());
                wtPoints1.add(equipmentPointMap.get(ContantXk.CJ_SSGL).getNemCode());
                if (wt.getEquipmentCategory() == -1) {
                    wtPoints1.add(equipmentPointMap.get(ContantXk.CJ_SSFS).getNemCode());
                    wtPoints1.add(equipmentPointMap.get(ContantXk.CJ_SSZS).getNemCode());
                } else if (wt.getEquipmentCategory() == -2) {
                    wtPoints1.add(equipmentPointMap.get(ContantXk.JLDL).getNemCode());
                    wtPoints1.add(equipmentPointMap.get(ContantXk.JLDY).getNemCode());
                }

            });
            try {

                List<PointData> wtRealdatas = edosUtil.getRealData(wtPoints);
                List<PointData> wtRealdatas1 = edosUtil.getRealData(wtPoints1);
                List<PointData> wpsfgl = null;
                List<PointData> wpzllgl = null;
                List<AiPoints> laps = getAiPoints(wp.getId());
                for (AiPoints tag : laps) {
                    if ("实发有功".equals(tag.getName())) {
                        List<String> sfgl = new ArrayList<>();
                        sfgl.add(tag.getTag());
                        wpsfgl = edosUtil.getRealData(sfgl);
                    } else if ("理论功率".equals(tag.getName())) {
                        List<String> llgl = new ArrayList<>();
                        llgl.add(tag.getTag());
                        wpzllgl = edosUtil.getRealData(llgl);
                    }
                }

                MatrixPowerVo powerVo = new MatrixPowerVo();
                powerVo.setWpid(wp.getId());
                powerVo.setWpname(wp.getAname());
                powerVo.setOrderNum(wp.getOrderNum());
                if (wp.getWindType().equals("-1")) {
                    powerVo.setCzlx("-1");
                } else if (wp.getWindType().equals("-2")) {
                    powerVo.setCzlx("-2");
                }
                powerVo.setJrts(wp.getJrwindQuantityHs() + wp.getJrwindQuantityLd() + wp.getJrquantityJz() + wp.getJrquantityZc());
                //0 待机
                //1 停机
                //2 发电
                //4 故障
                //6 检修
                //8 限电
                //12 离线
                Double bwts = 0.0;
                Double djts = 0.0;
                Double tjts = 0.0;
                Double gzts = 0.0;
                Double jxts = 0.0;
                Double xdts = 0.0;
                Double lxts = 0.0;
                Double jlts = 0.0;
                Double qdts = 0.0;
//                for (PointData zt : wtmxRealdatas){
//                    if (zt.getPointValueInDouble() == 2.0){
//                        bwts++;
//                    } else if (zt.getPointValueInDouble() == 0.0){
//                        djts++;
//                    } else if (zt.getPointValueInDouble() == 4.0){
//                        gzts++;
//                    } else if (zt.getPointValueInDouble() == 6.0){
//                        jxts++;
//                    } else if (zt.getPointValueInDouble() == 8.0){
//                        xdts++;
//                    } else if (zt.getPointValueInDouble() == 12.0){
//                        lxts++;
//                    } else if (zt.getPointValueInDouble() == 1.0){
//                        tjts++;
//                    }
//                }
//                powerVo.setBwts(bwts);
//                powerVo.setDjts(djts);
//                powerVo.setGzts(gzts);
//                powerVo.setJxts(jxts);
//                powerVo.setXdts(xdts);
//                powerVo.setSlts(tjts);
//                powerVo.setLxts(lxts);
                if (wpzllgl.size()>0) {
                    powerVo.setLlgl(StringUtils.round(wpzllgl.get(0).getPointValueInDouble(),2));
                } else {
                    powerVo.setLlgl(0.0);
                }
                powerVo.setBzgl(0.0);
                if (wpsfgl.size()>0) {
                    powerVo.setSjgl(StringUtils.round(wpsfgl.get(0).getPointValueInDouble() * 1000,2));
                } else {
                    powerVo.setSjgl(0.0);
                }
                if (wp.getWindType().equals("-1")) {
                    PointData speed = edosUtil.getRealData(pointMap.get(ContantXk.SSPJFS).getNemCode());
                    powerVo.setSpped(StringUtils.round(speed.getPointValueInDouble(), 2));
                } else if (wp.getWindType().equals("-2")) {
                    PointData speed = edosUtil.getRealData(pointMap.get(ContantXk.GCGZQD).getNemCode());
                    powerVo.setSpped(StringUtils.round(speed.getPointValueInDouble(), 2));
                }

                AtomicReference<Double> cxgl = new AtomicReference<>((double) 0);
                AtomicReference<Double> agc = new AtomicReference<>((double) 0);
                List<ProBasicSubStation> subStations = subwpls.stream().filter(sub -> sub.getWindpowerstationId().equals(wp.getId())).collect(Collectors.toList());
                subStations.stream().forEach(sub -> {
                    Map<String, ProBasicPowerstationPoint> powerstationPointMap = subwppointmap.get(sub.getId());
                    ProBasicPowerstationPoint cxglPoint = powerstationPointMap.get(ContantXk.TPOINT_WP_CXGL);

                    ProBasicPowerstationPoint agcPoint = powerstationPointMap.get(ContantXk.TPOINT_WP_AGC);


                    cxgl.updateAndGet(v -> {
                        try {
                            return new Double((double) (v + edosUtil.getRealData(cxglPoint).getPointValueInDouble()));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return v;
                    });
                    agc.updateAndGet(v -> {
                        try {
                            return new Double((double) (v + edosUtil.getRealData(agcPoint).getPointValueInDouble()));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return v;
                    });
                });

                QueryWrapper<ProBasicPowerPoint> qw = new QueryWrapper<>();
                List<ProBasicPowerPoint> powerls = new ArrayList<>();
                List<ProBasicPowerPoint> qyls = null;
                List<ProBasicProject> qcls = null;
                powerls = powerPointService.getBaseMapper().selectList(qw);

                qyls = powerls.stream().filter(c -> c.getWindpowerstationId().equals(wp.getId())).collect(Collectors.toList());

                if (qyls.isEmpty() || qyls.size() <= 0) {
                    qcls = CacheContext.pjls.stream().filter(p -> wp.getId().equals(p.getWindpowerstationId())).collect(Collectors.toList());
                    for (ProBasicProject p : qcls) {
                        for (ProBasicPowerPoint a : powerls) {
                            if (a.getWindpowerstationId().equals(p.getId())) {
                                qyls.add(a);
                            }
                        }
                    }
                }

                powerVo.setCxgl(cxgl.get());
                powerVo.setAgc(agc.get());
                //                powerVo.setYcgl(ycgl.get());
                jrts.addAndGet(powerVo.getJrts());
                dfts.addAndGet(0);
                sdtj.addAndGet(0);
                zcyx.addAndGet(0);
                jclyx.addAndGet(0);
                gztj.addAndGet(0);
                gzsl.addAndGet(0);
                jxtj.addAndGet(0);
                jxsl.addAndGet(0);
                xdtj.addAndGet(0);
                xdjcl.addAndGet(0);
                dwsl.addAndGet(0);
                hjsl.addAndGet(0);
                lx.addAndGet(0);
                wz.addAndGet(0);
                int index = 3;
                for (int j = 0; j < equipments.size(); j++) {

                    MatrixVo vo = new MatrixVo();
                    vo.setWtid(equipments.get(j).getId());
                    vo.setWtname(equipments.get(j).getAname());
                    vo.setStatus(wtRealdatas.get(j * index).getPointValueInDouble());
                    if (equipments.get(j).getProjectId().equals("NX_FGS_HAF02_EG")) {
                        vo.setPower(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index).getPointValueInDouble() / 1000, 2));
                    } else {
                        vo.setPower(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index).getPointValueInDouble(), 2));
                    }
                    if (equipments.get(j).getEquipmentCategory() == -1) {
                        vo.setSpeed(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index + 1).getPointValueInDouble(), 2));
                        vo.setTransfer(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index + 2).getPointValueInDouble(), 2));
                    } else if (equipments.get(j).getEquipmentCategory() == -2) {
                        vo.setCurrent(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index + 1).getPointValueInDouble(), 2));
                        vo.setVoltage(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index + 2).getPointValueInDouble(), 2));
                    }
                    vo.setSsqfzt(DoubleUtils.keepPrecision(wtRealdatas.get(j * index + 1).getPointValueInDouble(), 2));
                    vo.setQfdl(DoubleUtils.keepPrecision(wtRealdatas.get(j * index + 2).getPointValueInDouble(), 2));
                    vo.setRate(DoubleUtils.keepPrecision(modelpower.containsKey(equipments.get(j).getId()) ? vo.getPower() / modelpower.get(equipments.get(j).getId()) * 100 : 0, 2));
                    vo.setProject(equipments.get(j).getProjectId());
                    volist.add(vo);
                }
                for (MatrixVo ztvo: volist){
                    if (ztvo.getProject().equals("NX_FGS_HAF02_EG")){
                        List<String> fjztstream = fjztPoints.stream().filter(c -> c.contains(ztvo.getWtname())).collect(Collectors.toList());
                        List<PointData> ztls = edosUtil.getRealData(fjztstream);
                        List<String> zktjstream = zktjPoints.stream().filter(c -> c.contains(ztvo.getWtname())).collect(Collectors.toList());
                        List<PointData> zktjls = edosUtil.getRealData(zktjstream);
                        List<String> jlgzstream = jlgzPoints.stream().filter(c -> c.contains(ztvo.getWtname())).collect(Collectors.toList());
                        List<PointData> jlls = edosUtil.getRealData(jlgzstream);
                        List<String> xglyxstream = xglyxPoints.stream().filter(c -> c.contains(ztvo.getWtname())).collect(Collectors.toList());
                        List<PointData> xglls = edosUtil.getRealData(xglyxstream);

                        //计算状态 0==待机 1==停机 2==发电 4==故障 6==检修  8==限电  12==离线

                        //集控状态 0==离线 1==故障 2==检修 3==待机 4==启动 5==并网

                        if (xglls.get(0).getPointValue().equals("true")){
                            ztvo.setStatus(8.0);
                        } else if (jlls.get(0).getPointValue().equals("true")) {
                            ztvo.setStatus(3.0);//解缆
                        } else if (zktjls.get(0).getPointValue().equals("true")) {
                            ztvo.setStatus(1.0);
                        } else if (ztls.get(0).getPointValueInDouble() == 0.0) {
                            ztvo.setStatus(12.0);
                        } else if (ztls.get(0).getPointValueInDouble() == 1.0) {
                            ztvo.setStatus(4.0);
                        } else if (ztls.get(0).getPointValueInDouble() == 2.0) {
                            ztvo.setStatus(6.0);
                        } else if (ztls.get(0).getPointValueInDouble() == 3.0) {
                            ztvo.setStatus(0.0);
                        } else if (ztls.get(0).getPointValueInDouble() == 4.0) {
                            ztvo.setStatus(5.0);//启动
                        } else if (ztls.get(0).getPointValueInDouble() == 5.0) {
                            ztvo.setStatus(2.0);
                        }


                    }
                }

                for (MatrixVo zt : volist){
                    if (zt.getStatus() == 2.0){
                        bwts++;
                    } else if (zt.getStatus() == 0.0){
                        djts++;
                    } else if (zt.getStatus() == 4.0){
                        gzts++;
                    } else if (zt.getStatus() == 6.0){
                        jxts++;
                    } else if (zt.getStatus() == 8.0){
                        xdts++;
                    } else if (zt.getStatus() == 12.0){
                        lxts++;
                    } else if (zt.getStatus() == 1.0){
                        tjts++;
                    } else if (zt.getStatus() == 3.0) {
                        jlts++;
                    } else if (zt.getStatus() == 5.0) {
                        qdts++;
                    }
                }
                powerVo.setBwts(bwts);
                powerVo.setDjts(djts);
                powerVo.setGzts(gzts);
                powerVo.setJxts(jxts);
                powerVo.setXdts(xdts);
                powerVo.setSlts(tjts);
                powerVo.setLxts(lxts);
                powerVo.setJlts(jlts);
                powerVo.setQdts(qdts);
                powerVo.setWtlist(volist);
                qf0.updateAndGet(v -> new Double((double) (v + volist.stream().filter(i -> i.getSsqfzt() == 0).mapToDouble(MatrixVo::getQfdl).sum())));
                qf1.updateAndGet(v -> new Double((double) (v + volist.stream().filter(i -> i.getSsqfzt() == 1).mapToDouble(MatrixVo::getQfdl).sum())));
                qf2.updateAndGet(v -> new Double((double) (v + volist.stream().filter(i -> i.getSsqfzt() == 2).mapToDouble(MatrixVo::getQfdl).sum())));
                qf3.updateAndGet(v -> new Double((double) (v + volist.stream().filter(i -> i.getSsqfzt() == 3).mapToDouble(MatrixVo::getQfdl).sum())));
                qf4.updateAndGet(v -> new Double((double) (v + volist.stream().filter(i -> i.getSsqfzt() == 4).mapToDouble(MatrixVo::getQfdl).sum())));
                powerVos.add(powerVo);
            } catch (Exception e) {
                e.printStackTrace();
            }


        });
        SortUtils.sort(powerVos, "orderNum", SortUtils.ASC);
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("jrts", jrts.doubleValue());
        dataMap.put("qf0", DoubleUtils.keepPrecision(qf0.get(), 2));
        dataMap.put("qf1", DoubleUtils.keepPrecision(qf1.get(), 2));
        dataMap.put("qf2", DoubleUtils.keepPrecision(qf2.get(), 2));
        dataMap.put("qf3", DoubleUtils.keepPrecision(qf3.get(), 2));
        dataMap.put("qf4", DoubleUtils.keepPrecision(qf4.get(), 2));
        dataMap.put("powerVos", powerVos);
        return dataMap;
    }


    public Map<String, Object> basic(String company, String type) {

        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        List<ProBasicPowerstation> wpls = tokenService.getWpls(request);


        if (company.endsWith("ZGS")) {
            wpls = wpls.stream().filter(wp -> wp.getCompanyId().equals(company)).collect(Collectors.toList());
        }
        if (type.equals("-1")) {
            wpls = wpls.stream().filter(wp -> wp.getWindType().equals("-1")).collect(Collectors.toList());
        } else if (type.equals("-2")) {
            wpls = wpls.stream().filter(wp -> wp.getWindType().equals("-2")).collect(Collectors.toList());
        }

        Map<String, Map<String, ProBasicPowerstationPoint>> wppointmap = CacheContext.wppointmap;
        Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
        Map<String, List<ProBasicEquipment>> wpwtmap = CacheContext.wpwtmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> subwppointmap = CacheContext.subwppointmap;


        List<ProBasicSubStation> subwpls = tokenService.getSubwpls(request);

        List<MatrixPowerVo> powerVos = new ArrayList<>();
        AtomicInteger jrts = new AtomicInteger();
        AtomicInteger djts = new AtomicInteger();
        AtomicInteger bwts = new AtomicInteger();
        AtomicInteger gzts = new AtomicInteger();
        AtomicInteger jxts = new AtomicInteger();
        AtomicInteger xdts = new AtomicInteger();
        AtomicInteger slts = new AtomicInteger();
        AtomicInteger lxts = new AtomicInteger();
        AtomicInteger gfjrts = new AtomicInteger();
        AtomicInteger gfdjts = new AtomicInteger();
        AtomicInteger gfbwts = new AtomicInteger();
        AtomicInteger gfgzts = new AtomicInteger();
        AtomicInteger gfjxts = new AtomicInteger();
        AtomicInteger gfxdts = new AtomicInteger();
        AtomicInteger gfslts = new AtomicInteger();
        AtomicInteger gflxts = new AtomicInteger();

        wpls.stream().forEach(wp -> {
            List<MatrixVo> volist = new ArrayList<>();
            List<String> wpPoints = new ArrayList<>();
            List<String> wtPoints = new ArrayList<>();
            Map<String, ProBasicPowerstationPoint> pointMap = wppointmap.get(wp.getId());
            wpPoints.add(pointMap.get(ContantXk.DJTS).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.YXTS).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.GZTJTS).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.JXTJTS).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.XDTS).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.SLTS).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.TXZDTS).getNemCode());


            wpPoints.add(pointMap.get(ContantXk.SSZBZGL).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.SSZNHGLZS).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.SSZGL).getNemCode());
            wpPoints.add(pointMap.get(ContantXk.ZYCGL).getNemCode());
            List<ProBasicEquipment> equipments = wpwtmap.get(wp.getId());
            equipments.stream().forEach(wt -> {
                Map<String, ProBasicEquipmentPoint> equipmentPointMap = wtpAimap.get(wt.getId());
                wtPoints.add(equipmentPointMap.get(ContantXk.SBZT).getNemCode());

            });
            try {
                List<PointData> wpRealdatas = edosUtil.getRealData(wpPoints);
                List<PointData> wtRealdatas = edosUtil.getRealData(wtPoints);
                MatrixPowerVo powerVo = new MatrixPowerVo();
                powerVo.setWpid(wp.getId());
                powerVo.setWpname(wp.getAname());
                if (wp.getWindType().equals("-1")) {
                    powerVo.setCzlx("-1");
                } else if (wp.getWindType().equals("-2")) {
                    powerVo.setCzlx("-2");
                }
                powerVo.setJrts(wp.getJrwindQuantityHs() + wp.getJrwindQuantityLd() + wp.getJrquantityJz() + wp.getJrquantityZc());
                powerVo.setDjts(wpRealdatas.get(0).getPointValueInDouble());
                powerVo.setBwts(wpRealdatas.get(1).getPointValueInDouble());
                powerVo.setGzts(wpRealdatas.get(2).getPointValueInDouble());
                powerVo.setJxts(wpRealdatas.get(3).getPointValueInDouble());
                powerVo.setXdts(wpRealdatas.get(4).getPointValueInDouble());
                powerVo.setSlts(wpRealdatas.get(5).getPointValueInDouble());
                powerVo.setLxts(wpRealdatas.get(6).getPointValueInDouble());

                powerVo.setBzgl(wpRealdatas.get(7).getPointValueInDouble());
                powerVo.setLlgl(wpRealdatas.get(8).getPointValueInDouble());
                powerVo.setSjgl(wpRealdatas.get(9).getPointValueInDouble());


                if (wp.getWindType().equals("-1")) {
                    PointData wpReal = edosUtil.getRealData(pointMap.get(ContantXk.SSPJFS).getNemCode());
                    powerVo.setSpped(wpReal.getPointValueInDouble());
                } else if (wp.getWindType().equals("-2")) {
                    PointData wpReal = edosUtil.getRealData(pointMap.get(ContantXk.GCGZQD).getNemCode());
                    powerVo.setSpped(wpReal.getPointValueInDouble());
                }
                //                powerVo.setYcgl(wpRealdatas.get(11).getPointValueInDouble());
                AtomicReference<Double> cxgl = new AtomicReference<>((double) 0);
                AtomicReference<Double> agc = new AtomicReference<>((double) 0);
                AtomicReference<Double> ycgl = new AtomicReference<>((double) 0);
                List<ProBasicSubStation> subStations = subwpls.stream().filter(sub -> sub.getWindpowerstationId().equals(wp.getId())).collect(Collectors.toList());
                subStations.stream().forEach(sub -> {
                    Map<String, ProBasicPowerstationPoint> powerstationPointMap = subwppointmap.get(sub.getId());
                    ProBasicPowerstationPoint cxglPoint = powerstationPointMap.get(ContantXk.TPOINT_WP_CXGL);

                    ProBasicPowerstationPoint agcPoint = powerstationPointMap.get(ContantXk.TPOINT_WP_AGC);
                    ProBasicPowerstationPoint ycglPoint = powerstationPointMap.get(ContantXk.TPOINT_WP_YCGL);
                    cxgl.updateAndGet(v -> {
                        try {
                            return new Double((double) (v + edosUtil.getRealData(cxglPoint).getPointValueInDouble()));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return v;
                    });
                    agc.updateAndGet(v -> {
                        try {
                            return new Double((double) (v + edosUtil.getRealData(agcPoint).getPointValueInDouble()));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return v;
                    });
                    ycgl.updateAndGet(v -> {
                        try {
                            return new Double((double) (v + edosUtil.getHistMatrix(ycglPoint.getNemCode(), new Date().getTime() / 1000).getPointValueInDouble()));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return v;
                    });
                });
                powerVo.setCxgl(cxgl.get());
                powerVo.setAgc(agc.get());
                powerVo.setYcgl(ycgl.get());

                if (wp.getId().contains("_FDC_")) {
                    jrts.addAndGet(powerVo.getJrts());
                    djts.addAndGet((int) wpRealdatas.get(0).getPointValueInDouble());
                    bwts.addAndGet((int) wpRealdatas.get(1).getPointValueInDouble());
                    gzts.addAndGet((int) wpRealdatas.get(2).getPointValueInDouble());
                    jxts.addAndGet((int) wpRealdatas.get(3).getPointValueInDouble());
                    xdts.addAndGet((int) wpRealdatas.get(4).getPointValueInDouble());
                    slts.addAndGet((int) wpRealdatas.get(5).getPointValueInDouble());
                    lxts.addAndGet((int) wpRealdatas.get(6).getPointValueInDouble());
                } else if (wp.getId().contains("_GDC_")) {
                    gfjrts.addAndGet(powerVo.getJrts());
                    gfdjts.addAndGet((int) wpRealdatas.get(0).getPointValueInDouble());
                    gfbwts.addAndGet((int) wpRealdatas.get(1).getPointValueInDouble());
                    gfgzts.addAndGet((int) wpRealdatas.get(2).getPointValueInDouble());
                    gfjxts.addAndGet((int) wpRealdatas.get(3).getPointValueInDouble());
                    gfxdts.addAndGet((int) wpRealdatas.get(4).getPointValueInDouble());
                    gfslts.addAndGet((int) wpRealdatas.get(5).getPointValueInDouble());
                    gflxts.addAndGet((int) wpRealdatas.get(6).getPointValueInDouble());
                }
                for (int j = 0; j < equipments.size(); j++) {
                    MatrixVo vo = new MatrixVo();
                    vo.setWtid(equipments.get(j).getId());
                    vo.setWtname(equipments.get(j).getAname());
                    vo.setStatus(wtRealdatas.get(j).getPointValueInDouble());

                    volist.add(vo);
                }
                powerVo.setWtlist(volist);

                powerVos.add(powerVo);
            } catch (Exception e) {
                e.printStackTrace();
            }


        });
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("jrts", jrts.doubleValue());
        dataMap.put("djts", djts.doubleValue());
        dataMap.put("bwts", bwts.doubleValue());
        dataMap.put("gzts", gzts.doubleValue());
        dataMap.put("jxts", jxts.doubleValue());
        dataMap.put("xdts", xdts.doubleValue());
        dataMap.put("slts", slts.doubleValue());
        dataMap.put("lxts", lxts.doubleValue());
        dataMap.put("gfjrts", gfjrts.doubleValue());
        dataMap.put("gfdjts", gfdjts.doubleValue());
        dataMap.put("gfbwts", gfbwts.doubleValue());
        dataMap.put("gfgzts", gfgzts.doubleValue());
        dataMap.put("gfjxts", gfjxts.doubleValue());
        dataMap.put("gfxdts", gfxdts.doubleValue());
        dataMap.put("gfslts", gfslts.doubleValue());
        dataMap.put("gflxts", gflxts.doubleValue());

        dataMap.put("powerVos", powerVos);
        return dataMap;

    }

    public Map<String, Object> single(String wpid) throws Exception {
        Map<String, Object> resultMap = new HashMap<>();
        Map<String, Map<String, ProBasicPowerstationPoint>> wppointmap = CacheContext.wppointmap;
        Map<String, ProBasicPowerstation> wpmap = CacheContext.wpmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> subwppointmap = CacheContext.subwppointmap;
        HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
        List<ProBasicSubStation> subwpls = tokenService.getSubwpls(request);
        Map<String, ProBasicPowerstationPoint> pointMap = wppointmap.get(wpid);
        ProBasicPowerstation powerstation = wpmap.get(wpid);
        List<String> wpPoints = new ArrayList<>();
        List<String> wpPoints1 = new ArrayList<>();

        wpPoints.add(pointMap.get(ContantXk.DJTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.SDTJTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.XNTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.QXJCLTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.GZTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.CNSLGZTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.JXTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.CNSLJXTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.XDTJTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.XDJCLTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.CWSLDWTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.CWSLTQTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.LXTSMX).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.TXZDTSMX).getNemCode());
        if (powerstation.getWindType().equals("-1")) {
            wpPoints.add(pointMap.get(ContantXk.SSPJFS).getNemCode());
        } else if (powerstation.getWindType().equals("-2")) {
            wpPoints.add(pointMap.get(ContantXk.SSPJGZD).getNemCode());
            wpPoints1.add(pointMap.get(ContantXk.GCGZQD).getNemCode());
        }
        wpPoints.add(pointMap.get(ContantXk.SSZBZGL).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.SSZNHGLZS).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.SSZGL).getNemCode());
        wpPoints.add(pointMap.get(ContantXk.ZYCGL).getNemCode());

        List<PointData> realData = edosUtil.getRealData(wpPoints);
        List<PointData> realData1 = edosUtil.getRealData(wpPoints1);


        //预测功率取值
        //        List<ProBasicPowerstation> collect = CacheContext.wpls.stream().filter(cc -> wpId.equals(cc.getId())).collect(Collectors.toList());
        QueryWrapper<ProBasicPowerPoint> qw1 = new QueryWrapper<>();
        List<ProBasicPowerPoint> powerls = new ArrayList<>();
        List<ProBasicPowerPoint> qyls = null;
        List<ProBasicProject> qcls = null;
        powerls = powerPointService.getBaseMapper().selectList(qw1);

        qyls = powerls.stream().filter(c -> c.getWindpowerstationId().equals(powerstation.getId())).collect(Collectors.toList());

        if (qyls.isEmpty() || qyls.size() <= 0) {
            qcls = CacheContext.pjls.stream().filter(p -> powerstation.getId().equals(p.getWindpowerstationId())).collect(Collectors.toList());
            for (ProBasicProject p : qcls) {
                for (ProBasicPowerPoint a : powerls) {
                    if (a.getWindpowerstationId().equals(p.getId())) {
                        qyls.add(a);
                    }
                }
            }
        }

        ProBasicPowerstationPoint ycglcd = null;
        double ycgl = 0.0;
        double sum = 0.0;
        for (ProBasicPowerPoint pp : qyls) {

            if (powerstation.getId().contains("MLJ_FDC_STA")) continue;
            ycglcd = proBasicPowerstationPointService.getPowerstationPoint(pp.getWindpowerstationId(), ContantXk.GLYC);

            double aDouble = 0.0;
            try {
                aDouble = edosUtil.getHistMatrix(ycglcd.getNemCode(), new Date().getTime() / 1000).getPointValueInDouble();
                ycgl = (aDouble + sum);
                sum += aDouble;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }


        resultMap.put("wpid", powerstation.getId());
        resultMap.put("wpname", powerstation.getAname());
        resultMap.put("jrts", powerstation.getJrquantityJz() + powerstation.getJrquantityZc() + powerstation.getJrwindQuantityLd() + powerstation.getJrwindQuantityHs());
        resultMap.put("dfts", realData.get(0).getPointValueInDouble());
        resultMap.put("sdtjts", realData.get(1).getPointValueInDouble());
        resultMap.put("djts", realData.get(0).getPointValueInDouble() + realData.get(1).getPointValueInDouble());

        resultMap.put("zcyxts", realData.get(2).getPointValueInDouble());
        resultMap.put("jclyxts", realData.get(3).getPointValueInDouble());
        resultMap.put("bwts", realData.get(2).getPointValueInDouble() + realData.get(3).getPointValueInDouble());

        resultMap.put("gztjts", realData.get(4).getPointValueInDouble());
        resultMap.put("gzslts", realData.get(5).getPointValueInDouble());
        resultMap.put("gzts", realData.get(4).getPointValueInDouble() + realData.get(5).getPointValueInDouble());

        resultMap.put("jxtjts", realData.get(6).getPointValueInDouble());
        resultMap.put("jxslts", realData.get(7).getPointValueInDouble());
        resultMap.put("jxts", realData.get(6).getPointValueInDouble() + realData.get(7).getPointValueInDouble());

        resultMap.put("xdtjts", realData.get(8).getPointValueInDouble());
        resultMap.put("xdjclts", realData.get(9).getPointValueInDouble());
        resultMap.put("xdts", realData.get(8).getPointValueInDouble() + realData.get(9).getPointValueInDouble());

        resultMap.put("dwslts", realData.get(10).getPointValueInDouble());
        resultMap.put("hjslts", realData.get(11).getPointValueInDouble());
        resultMap.put("slts", realData.get(10).getPointValueInDouble() + realData.get(11).getPointValueInDouble());

        resultMap.put("lxts", realData.get(12).getPointValueInDouble());
        resultMap.put("wzts", realData.get(13).getPointValueInDouble());
        resultMap.put("lxzts", realData.get(12).getPointValueInDouble() + realData.get(13).getPointValueInDouble());
        if (wpid.contains("FDC_STA")) {
            resultMap.put("speed", realData.get(14).getPointValueInDouble());
        } else {
            resultMap.put("speed", realData1.get(0).getPointValueInDouble());
        }
        resultMap.put("bzgl", realData.get(15).getPointValueInDouble());
        resultMap.put("llgl", realData.get(16).getPointValueInDouble());
        resultMap.put("sjgl", realData.get(17).getPointValueInDouble() / 1000);
        resultMap.put("ycgl", ycgl);
        AtomicReference<Double> cxgl = new AtomicReference<>((double) 0);
        AtomicReference<Double> agc = new AtomicReference<>((double) 0);
        List<ProBasicSubStation> subStations = subwpls.stream().filter(sub -> sub.getWindpowerstationId().equals(powerstation.getId())).collect(Collectors.toList());
        subStations.stream().forEach(sub -> {
            Map<String, ProBasicPowerstationPoint> powerstationPointMap = subwppointmap.get(sub.getId());
            ProBasicPowerstationPoint cxglPoint = powerstationPointMap.get(ContantXk.TPOINT_WP_CXGL);

            ProBasicPowerstationPoint agcPoint = powerstationPointMap.get(ContantXk.TPOINT_WP_AGC);
            cxgl.updateAndGet(v -> {
                try {
                    return new Double((double) (v + edosUtil.getRealData(cxglPoint).getPointValueInDouble()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return v;
            });
            agc.updateAndGet(v -> {
                try {
                    return new Double((double) (v + edosUtil.getRealData(agcPoint).getPointValueInDouble()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return v;
            });
        });
        resultMap.put("cxgl", cxgl.get());
        resultMap.put("agc", agc.get());

        //期次
        Map<String, List<ProBasicProject>> wppromap = CacheContext.wppromap;
        List<ProBasicProject> projects = wppromap.get(wpid);
        Map<String, Map<String, ProBasicPowerstationPoint>> propointmap = CacheContext.propointmap;
        Map<String, Map<String, ProBasicPowerstationPoint>> propointmap1 = CacheContext.wppointmap;
        Map<String, Map<String, Object>> wpdatamap = new HashMap<>();
        List<MatrixProVo> proVos = new ArrayList<>();
        projects.stream().forEach(p -> {
            Map<String, Object> proMap = new HashMap<>();
            MatrixProVo provo = new MatrixProVo();
            List<String> procodes = new ArrayList<>();
            List<String> procodes1 = new ArrayList<>();
            Map<String, ProBasicPowerstationPoint> powerstationPointMap = propointmap.get(p.getId());
            procodes.add(powerstationPointMap.get(ContantXk.DJTS).getNemCode());
            procodes.add(powerstationPointMap.get(ContantXk.YXTS).getNemCode());
            procodes.add(powerstationPointMap.get(ContantXk.GZTJTS).getNemCode());
            procodes.add(powerstationPointMap.get(ContantXk.JXTJTS).getNemCode());
            procodes.add(powerstationPointMap.get(ContantXk.XDTS).getNemCode());
            procodes.add(powerstationPointMap.get(ContantXk.SLTS).getNemCode());
            procodes.add(powerstationPointMap.get(ContantXk.TXZDTS).getNemCode());
            if (powerstation.getWindType().equals("-1")) {
                procodes.add(powerstationPointMap.get(ContantXk.SSPJFS).getNemCode());
            } else if (powerstation.getWindType().equals("-2")) {
                Map<String, ProBasicPowerstationPoint> powerstationPointMap1 = propointmap1.get(p.getWindpowerstationId());
                procodes1.add(powerstationPointMap1.get(ContantXk.GCGZQD).getNemCode());
                procodes.add(powerstationPointMap.get(ContantXk.SSPJGZD).getNemCode());
            }
            procodes.add(powerstationPointMap.get(ContantXk.SSZBZGL).getNemCode());
            procodes.add(powerstationPointMap.get(ContantXk.SSZNHGLZS).getNemCode());
            procodes.add(powerstationPointMap.get(ContantXk.SSZGL).getNemCode());
            List<PointData> prodatas = null;
            List<PointData> prodatas1 = null;
            try {
                prodatas = edosUtil.getRealData(procodes);
            } catch (Exception e) {
                e.printStackTrace();
            }

            try {
                prodatas1 = edosUtil.getRealData(procodes1);
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (StringUtils.isNotEmpty(prodatas)) {
                provo.setDjts((int) prodatas.get(0).getPointValueInDouble());
                provo.setBwts((int) prodatas.get(1).getPointValueInDouble());
                provo.setGzts((int) prodatas.get(2).getPointValueInDouble());
                provo.setJxts((int) prodatas.get(3).getPointValueInDouble());
                provo.setXdts((int) prodatas.get(4).getPointValueInDouble());
                provo.setSlts((int) prodatas.get(5).getPointValueInDouble());
                provo.setLxts((int) prodatas.get(6).getPointValueInDouble());
                if (wpid.contains("FDC_STA")) {
                    provo.setSpeed(prodatas.get(7).getPointValueInDouble());
                } else {
                    provo.setSpeed(prodatas1.get(0).getPointValueInDouble());
                }
                provo.setBzgl(prodatas.get(8).getPointValueInDouble());
                provo.setLlgl(prodatas.get(9).getPointValueInDouble());
                provo.setSjgl(prodatas.get(10).getPointValueInDouble());

            }

            //线路
            Map<String, List<ProBasicLine>> prolinemap = CacheContext.prolinemap;
            Map<String, List<ProBasicEquipment>> lnwtmap = CacheContext.lnwtmap;
            Map<String, Map<String, ProBasicEquipmentPoint>> wtpAimap = CacheContext.wtpAimap;
            Map<String, Double> modelpower = CacheContext.modelpower;
            List<ProBasicLine> lines = prolinemap.get(p.getId());
            Map<String, Map<String, Object>> lineresultMap = new HashMap<>();
            List<MatrixLineVo> lineVos = new ArrayList<>();
            lines.stream().forEach(line -> {
                MatrixLineVo linevo = new MatrixLineVo();
                List<ProBasicEquipment> equipments = lnwtmap.get(line.getId());
                List<String> wtPoints = new ArrayList<>();
                List<String> wtPoints1 = new ArrayList<>();
                equipments.stream().forEach(wt -> {
                    Map<String, ProBasicEquipmentPoint> equipmentPointMap = wtpAimap.get(wt.getId());
                    wtPoints.add(equipmentPointMap.get(ContantXk.MXZT).getNemCode());
                    wtPoints1.add(equipmentPointMap.get(ContantXk.CJ_SSGL).getNemCode());
                    if (wt.getEquipmentCategory() == -1) {
                        wtPoints1.add(equipmentPointMap.get(ContantXk.CJ_SSFS).getNemCode());
                        wtPoints1.add(equipmentPointMap.get(ContantXk.CJ_SSZS).getNemCode());
                    } else if (wt.getEquipmentCategory() == -2) {
                        wtPoints1.add(equipmentPointMap.get(ContantXk.JLDL).getNemCode());
                        wtPoints1.add(equipmentPointMap.get(ContantXk.JLDY).getNemCode());
                    }
                    wtPoints.add(equipmentPointMap.get(ContantXk.SSQFZT).getNemCode());
                    wtPoints.add(equipmentPointMap.get(ContantXk.RQFDL).getNemCode());
                });
                List<PointData> wtRealdatas = null;
                List<PointData> wtRealdatas1 = null;
                try {
                    wtRealdatas = edosUtil.getRealData(wtPoints);
                    wtRealdatas1 = edosUtil.getRealData(wtPoints1);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                List<MatrixVo> volist = new ArrayList<>();
                if (StringUtils.isNotEmpty(wtRealdatas)) {
                    int index = 3;
                    for (int j = 0; j < equipments.size(); j++) {
                        MatrixVo vo = new MatrixVo();
                        vo.setWtid(equipments.get(j).getId());
                        vo.setWtname(equipments.get(j).getAname());
                        vo.setStatus(wtRealdatas.get(j * index).getPointValueInDouble());
                        vo.setSsqfzt(DoubleUtils.keepPrecision(wtRealdatas.get(j * index + 1).getPointValueInDouble(), 2));
                        vo.setQfdl(DoubleUtils.keepPrecision(wtRealdatas.get(j * index + 2).getPointValueInDouble(), 2));


                        vo.setPower(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index).getPointValueInDouble(), 2));

                        if (equipments.get(j).getEquipmentCategory() == -1) {
                            vo.setSpeed(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index + 1).getPointValueInDouble(), 2));
                            vo.setTransfer(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index + 2).getPointValueInDouble(), 2));
                        } else if (equipments.get(j).getEquipmentCategory() == -2) {
                            vo.setCurrent(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index + 1).getPointValueInDouble(), 2));
                            vo.setVoltage(DoubleUtils.keepPrecision(wtRealdatas1.get(j * index + 2).getPointValueInDouble(), 2));
                        }

                        vo.setRate(modelpower.containsKey(equipments.get(j).getId()) ? DoubleUtils.keepPrecision(vo.getPower() / modelpower.get(equipments.get(j).getId()) * 100, 2) : 0);
                        volist.add(vo);
                    }
                }
                linevo.setId(line.getId());
                linevo.setName(line.getAname());
                linevo.setWtDataList(volist);
                lineVos.add(linevo);
            });
            provo.setLineVos(lineVos);
            provo.setId(p.getId());
            provo.setName(p.getName());
            proVos.add(provo);
        });
        resultMap.put("wpDatas", proVos);

        return resultMap;
    }


    public Map<String, String> equipment(String wtid) throws Exception {

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

        if (wtid != null && !wtid.isEmpty()) {
            List<ProBasicEquipment> collect = CacheContext.wtls.stream().filter(w -> wtid.equals(w.getId())).collect(Collectors.toList());
            List<ProEconEquipmentmodel> cs = CacheContext.equipmentmodels.stream().filter(m -> collect.get(0).getModelId().equals(m.getId())).collect(Collectors.toList());

            QueryWrapper<ProEconManufacturer> eq = new QueryWrapper<>();
            eq.lambda().eq(ProEconManufacturer::getId, cs.get(0).getWindturbineManufacturerId());
            List<ProEconManufacturer> list = proEconManufacturerService.getBaseMapper().selectList(eq);


            List<ProBasicSquare> squares = CacheContext.sqls.stream().filter(s -> collect.get(0).getSquareId().equals(s.getId())).collect(Collectors.toList());
            if (wtid.contains("F_WT")) {
                map.put("model", cs.get(0).getId());
                map.put("manufacturer", list.get(0).getName());
            }
            if (wtid.contains("G_IN")) {
                map.put("model", cs.get(0).getId());
                map.put("manufacturer", list.get(0).getName());
                map.put("squareid", squares.get(0).getTypes());
            }
        }
        return map;
    }

    /**
     * 根据ID获取agc配置信息
     *
     * @param id 场站ID
     * @return 配置信息
     */
    private List<AiPoints> getAiPoints(String id) {
        if (!CacheContext.agcDeviateConfigMap.containsKey(id)) {
            return null;
        }
        AiPoints[] aiPoints = CacheContext.agcDeviateConfigMap.get(id).getAiPoints();
        return Arrays.stream(aiPoints).filter(ap -> ap.getName().contains("功") || ap.getName().contains("风") && !ap.getName().contains("预测")).collect(Collectors.toList());
    }
}
