package com.gyee.frame.service.initialpoint;

import com.gyee.frame.common.file.ExcelExport;
import com.gyee.frame.common.spring.InitialRunner;
import com.gyee.frame.model.auto.*;
import com.gyee.frame.service.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class InitialPointEdosService implements  IinitialPoint{

    @Resource
    private RegionService regionService;
    @Resource
    private CompanysService companysService;
    @Resource
    private WindturbinestandardpointService windturbinestandardpointService;
    @Resource
    private WindpowerstationstandardpointService windpowerstationstandardpointService;

    @Resource
    private ForecaststationtandardpointService forecaststationtandardpointService;
    @Resource
    private WindsubstationService windsubstationService;
    @Resource
    private WindsubstationstandardpointService windsubstationstandardpointService;
    @Resource
    private Windsubstationtestingpoint2Service windsubstationtestingpoint2Service;

    @Resource
    private WindturbinestandardpointsService windturbinestandardpointsService;

    private final  String AI="AI";
    private final  String DI="DI";
    private final  String CI="CI";
    private final String CFT="CFT";

    @Override
    public void initalFc(boolean isGf) throws IOException {



        //   windPowerstationTestingPointService.deleteAll();

        List<Windpowerstationstandardpoint>  stpointls=windpowerstationstandardpointService.findAllList();

        List<Region> regions=regionService.findAllList();

        List<WindPowerStationTestingPoint> allpoints=new ArrayList<>();

        if(!regions.isEmpty())
        {


            for(Region re:regions)
            {
                List<Companys> companys= companysService.getCompanysListByRId(re.getId());
                if(!companys.isEmpty())
                {
                    for(Companys cs:companys)
                    {
                        StringBuilder sba=new StringBuilder();
                        sba.append(re.getCode()).append("_").append(cs.getId()).append("_");
/********************************************区域公司测点**************************************************/
                        List<WindPowerStationTestingPoint> points=new ArrayList<>();
                        for(int i=0;i<stpointls.size();i++)
                        {


                            Windpowerstationstandardpoint stp=stpointls.get(i);
                            StringBuilder sb =new StringBuilder();
                            sb.append(String.valueOf(sba));
                            sb.append(re.getCode()).append("F_XX_XX_XX_XXX_");
                            sb.append(CI);
                            sb.append(stp.getOrdernum());
//                            if(stp.getCode().equals(CI))
//                            {
//                                sbtable.append("JSFW.");
//                                sbtable.append(sb);
//                            }
                            WindPowerStationTestingPoint po=new WindPowerStationTestingPoint();
                            po.setCode(String.valueOf(sb));
                            sb =new StringBuilder();
                            sb.append(re.getName()).append(stp.getName());
                            po.setName(String.valueOf(sb));
                            po.setModel(null);
                            po.setModelid(null);
                            if(regions.size()==1)
                            {
                                po.setWindpowerstationid("0");
                            }else
                            {
                                StringBuilder tempsb=new StringBuilder();
                                tempsb.append(re.getId());
                                po.setWindpowerstationid(String.valueOf(tempsb));
                            }
                            po.setUniformcode(stp.getUniformcode());

//                            if(stp.getCode().equals(CI))
//                            {
//                                StringBuilder tempsb=new StringBuilder();
//                                tempsb.append(cs.getId()).append(re.getCode());
//                                tempsb.append(".JSFW");
//                                po.setRealtimeid(String.valueOf(tempsb));
//                            }

                            if(stp.getCode().equals(CI))
                            {
                                sb =new StringBuilder();
                                sb.append("GDHF.JSFW");
                                po.setRealtimeid(String.valueOf(sb));
                            }
                            points.add(po);
                        }

                        allpoints.addAll(points);
                        // windPowerstationTestingPointService.insertBatch(points);

                        /*******************************************风电测点生成*******************************************************/

//            points=new ArrayList<>();
//            for(int i=0;i<stpointls.size();i++)
//            {
//                StringBuilder sbtable =new StringBuilder();
//
//                Windpowerstationstandardpoint stp=stpointls.get(i);
//                StringBuilder sb =new StringBuilder();
//                sb.append(String.valueOf(sba));
//                sb.append("FDC_XX_XX_XX_XXX_");
//                sb.append(CI);
//                sb.append(stp.getOrdernum());
////                            if(stp.getCode().equals(CI))
////                            {
////                                sbtable.append("JSFW.");
////                                sbtable.append(sb);
////                            }
//                WindPowerStationTestingPoint po=new WindPowerStationTestingPoint();
//                po.setCode(String.valueOf(sb));
//                sb =new StringBuilder();
//                sb.append(re.getName()).append(stp.getName());
//                po.setName(String.valueOf(sb));
//                po.setModel(null);
//                po.setModelid(null);
//                if(regions.size()==1)
//                {
//                    po.setWindpowerstationid("-1");
//                }else
//                {
//                    StringBuilder tempsb=new StringBuilder();
//                    tempsb.append(re.getCode()).append(1);
//                    po.setWindpowerstationid(String.valueOf(tempsb));
//                }
//                po.setUniformcode(stp.getUniformcode());
//
////                            if(stp.getCode().equals(CI))
////                            {
////                                StringBuilder tempsb=new StringBuilder();
////                                tempsb.append(cs.getId()).append(re.getCode());
////                                tempsb.append(".JSFW");
////                                po.setRealtimeid(String.valueOf(tempsb));
////                            }
//
//
//
//                if(stp.getCode().equals(CI))
//                {
//                    sb =new StringBuilder();
//                    sb.append("GDHF.JSFWFC");
//                    po.setRealtimeid(String.valueOf(sb));
//                }
//                points.add(po);
//            }
//
//            allpoints.addAll(points);
//            //windPowerstationTestingPointService.insertBatch(points);
//
//            if(isGf)
//            {
//                /*********************************************光伏测点生成*****************************************************/
//
//                points=new ArrayList<>();
//                for(int i=0;i<stpointls.size();i++)
//                {
//
//
//                    Windpowerstationstandardpoint stp=stpointls.get(i);
//                    StringBuilder sb =new StringBuilder();
//                    sb.append(String.valueOf(sba));
//                    sb.append("GDC_XX_XX_XX_XXX_");
//                    sb.append(CI);
//                    sb.append(stp.getOrdernum());
////                                if(stp.getCode().equals(CI))
////                                {
////                                    sbtable.append("JSFW.");
////                                    sbtable.append(sb);
////                                }
//                    WindPowerStationTestingPoint po=new WindPowerStationTestingPoint();
//                    po.setCode(String.valueOf(sb));
//                    sb =new StringBuilder();
//                    sb.append(re.getName()).append(stp.getName());
//                    po.setName(String.valueOf(sb));
//                    po.setModel(null);
//                    po.setModelid(null);
//                    if(regions.size()==1)
//                    {
//                        po.setWindpowerstationid("-2");
//                    }else
//                    {
//                        StringBuilder tempsb=new StringBuilder();
//                        tempsb.append(re.getCode()).append(2);
//                        po.setWindpowerstationid(String.valueOf(tempsb));
//                    }
//                    po.setUniformcode(stp.getUniformcode());
//
////                                if(stp.getCode().equals(CI))
////                                {
////                                    StringBuilder tempsb=new StringBuilder();
////                                    tempsb.append(cs.getId()).append(re.getCode());
////                                    tempsb.append(".JSFW");
////                                    po.setRealtimeid(String.valueOf(tempsb));
////                                }
//                    if(stp.getCode().equals(CI))
//                    {
//                        sb =new StringBuilder();
//                        sb.append("GDHF.JSFWGC");
//                        po.setRealtimeid(String.valueOf(sb));
//                    }
//                    points.add(po);
//                }
//
//                allpoints.addAll(points);
//                // windPowerstationTestingPointService.insertBatch(points);
//            }
                    }
                }
            }


        }



        /*********************************************场站、项目、线路测点生成*****************************************************/

        for (Windpowerstation wp:InitialRunner.wpallls)
        {

            if(!stpointls.isEmpty())
            {

                createWpPoints(wp, stpointls,allpoints);
                createPjPoints(wp, stpointls,allpoints);
                createLnPoints(wp, stpointls,allpoints);
            }
        }

        //创建一个数组用于设置表头
        String[] arr = new String[]{"编码","名称","型号","单位","英文名称","类型编号","所属型号","最大值","最小值","合理最大值",
                "合理最小值","统一编码","短ID","长ID","风场编号","实时配置编号"};
        String heardName="风机测点表";
        //调用Excel导出工具类
        ExcelExport.exportToPath(allpoints,arr,heardName,6,"场站测点");
    }

    private void createWpPoints(Windpowerstation wp, List<Windpowerstationstandardpoint> stpointls,List<WindPowerStationTestingPoint> allpoints) {
        List<WindPowerStationTestingPoint> points=new ArrayList<>();
        for(int i=0;i<stpointls.size();i++)
        {


            Windpowerstationstandardpoint stp=stpointls.get(i);
            StringBuilder sb =new StringBuilder();
            sb.append(wp.getPhoto());
            String temp=wp.getId().substring(0,wp.getId().indexOf("_"));

            if(wp.getId().endsWith("FDC"))
            {

                sb.append(temp).append("F_").append("JS_XX_XX_XXX_");
            }else   if(wp.getId().endsWith("GDC"))
            {

                sb.append(temp).append("G_").append("JS_XX_XX_XXX_");
            }



            sb.append(CI);

            sb.append(stp.getOrdernum());

//            if(stp.getCode().equals(CI))
//            {
//                sbtable.append("JSFW.");
//                sbtable.append(sb);
//            }

            WindPowerStationTestingPoint po=new WindPowerStationTestingPoint();
            po.setCode(String.valueOf(sb));
            sb =new StringBuilder();
            sb.append(wp.getName()).append(stp.getName());
            po.setName(String.valueOf(sb));
            po.setModel(null);
            po.setModelid(null);
            po.setWindpowerstationid(wp.getId());
            po.setUniformcode(stp.getUniformcode());

//            if(stp.getCode().equals(CI))
//            {
//                sb =new StringBuilder();
//                temp=wp.getId().substring(0,wp.getId().indexOf("_"));
//                sb.append(temp).append(".JSFW");
//                po.setRealtimeid(String.valueOf(sb));
//            }

            if(stp.getCode().equals(CI))
            {
                sb =new StringBuilder();
                temp=wp.getId().substring(0,wp.getId().indexOf("_"));

                if(wp.getId().endsWith("FDC"))
                {
                    sb.append("GDHF.JSFW").append(temp).append("FC");
                }else
                {
                    sb.append("GDHF.JSFW").append(temp).append("GC");
                }

                po.setRealtimeid(String.valueOf(sb));
            }
            points.add(po);
        }

        allpoints.addAll(points);
        //windPowerstationTestingPointService.insertBatch(points);
    }

    private void createPjPoints(Windpowerstation wp, List<Windpowerstationstandardpoint> stpointls,List<WindPowerStationTestingPoint> allpoints) {


        for(Project pj:InitialRunner.pjls)
        {
            if(pj.getWindpowerstationid().equals(wp.getId()))
            {
                List<WindPowerStationTestingPoint> points=new ArrayList<>();
                for(int i=0;i<stpointls.size();i++)
                {


                    Windpowerstationstandardpoint stp=stpointls.get(i);
                    StringBuilder sb =new StringBuilder();
                    sb.append(wp.getPhoto());
                    String temp=wp.getId().substring(0,wp.getId().indexOf("_"));


                    sb.append(temp).append("F_").append("JS_");
                    temp=pj.getId().substring(0,pj.getId().lastIndexOf("_"));
                    sb.append("P").append(Integer.valueOf(temp.substring(temp.length()-2))).append("_");
                    sb.append("XX_XXX_");
                    sb.append(CI);

                    sb.append(stp.getOrdernum());

//                    if(stp.getCode().equals(CI))
//                    {
//                        sbtable.append("JSFW.");
//                        sbtable.append(sb);
//                    }

                    WindPowerStationTestingPoint po=new WindPowerStationTestingPoint();
                    po.setCode(String.valueOf(sb));
                    sb =new StringBuilder();
                    sb.append(pj.getName()).append(stp.getName());
                    po.setName(String.valueOf(sb));
                    po.setModel(null);
                    po.setModelid(null);
                    po.setWindpowerstationid(pj.getId());
                    po.setUniformcode(stp.getUniformcode());

//                    if(stp.getCode().equals(CI))
//                    {
//                        sb =new StringBuilder();
//                        temp=wp.getId().substring(0,wp.getId().indexOf("_"));
//                        sb.append(temp).append(".JSFW");
//                        po.setRealtimeid(String.valueOf(sb));
//                    }

                    if(stp.getCode().equals(CI))
                    {
                        sb =new StringBuilder();
                        temp=wp.getId().substring(0,wp.getId().indexOf("_"));

                        if(wp.getId().endsWith("FDC"))
                        {
                            sb.append("GDHF.JSFW").append(temp).append("FC");
                        }else
                        {
                            sb.append("GDHF.JSFW").append(temp).append("GC");
                        }

                        po.setRealtimeid(String.valueOf(sb));
                    }
                    points.add(po);
                }
                allpoints.addAll(points);
            }
        }

    }

    private void createLnPoints(Windpowerstation wp, List<Windpowerstationstandardpoint> stpointls,List<WindPowerStationTestingPoint> allpoints) {

        for(Line ln:InitialRunner.linels)
        {
            if(InitialRunner.pjmap.containsKey(ln.getProjectid()))
            {
                Project pj=InitialRunner.pjmap.get(ln.getProjectid());

                if(pj.getWindpowerstationid().equals(wp.getId()))
                {
                    List<WindPowerStationTestingPoint> points=new ArrayList<>();
                    for(int i=0;i<stpointls.size();i++)
                    {


                        Windpowerstationstandardpoint stp=stpointls.get(i);
                        StringBuilder sb =new StringBuilder();
                        sb.append(wp.getPhoto());
                        String temp=wp.getId().substring(0,wp.getId().indexOf("_"));


                        sb.append(temp).append("F_").append("JS_");
                        temp=pj.getId().substring(0,pj.getId().lastIndexOf("_"));
                        sb.append("P").append(Integer.valueOf(temp.substring(temp.length()-2))).append("_");
                        temp=ln.getId().substring(0,ln.getId().lastIndexOf("_"));
                        sb.append("L").append(Integer.valueOf(temp.substring(temp.length()-2))).append("_");
                        sb.append("XXX_");
                        sb.append(CI);

                        sb.append(stp.getOrdernum());

//                        if(stp.getCode().equals(CI))
//                        {
//                            sbtable.append("JSFW.");
//                            sbtable.append(sb);
//                        }

                        WindPowerStationTestingPoint po=new WindPowerStationTestingPoint();
                        po.setCode(String.valueOf(sb));
                        sb =new StringBuilder();
                        sb.append(ln.getName()).append(stp.getName());
                        po.setName(String.valueOf(sb));
                        po.setModel(null);
                        po.setModelid(null);
                        po.setWindpowerstationid(ln.getId());
                        po.setUniformcode(stp.getUniformcode());

//                        if(stp.getCode().equals(CI))
//                        {
//                            sb =new StringBuilder();
//                            temp=wp.getId().substring(0,wp.getId().indexOf("_"));
//                            sb.append(temp).append(".JSFW");
//                            po.setRealtimeid(String.valueOf(sb));
//                        }


                        if(stp.getCode().equals(CI))
                        {
                            sb =new StringBuilder();
                            temp=wp.getId().substring(0,wp.getId().indexOf("_"));

                            if(wp.getId().endsWith("FDC"))
                            {
                                sb.append("GDHF.JSFW").append(temp).append("FC");
                            }else
                            {
                                sb.append("GDHF.JSFW").append(temp).append("GC");
                            }

                            po.setRealtimeid(String.valueOf(sb));
                        }
                        points.add(po);
                    }
                    allpoints.addAll(points);


                }
            }

        }

    }

    @Override
    public void initalSyz() {

    }

    @Override
    public void initalDd() throws IOException {

        windsubstationtestingpoint2Service.deleteAll();

        List<Windsubstationtandardpoint> stpointls=windsubstationstandardpointService.findAllList();
        List<Windsubstation> wsubls=windsubstationService.findAllList();
        List<Windsubstationtestingpoint> allpoints=new ArrayList<>();
        if(!wsubls.isEmpty() && !stpointls.isEmpty())
        {
            for(Windsubstation wsub:wsubls)
            {

                if(InitialRunner.wpmap.containsKey(wsub.getWindpowerstationid()) )
                {
                    Windpowerstation wp=InitialRunner.wpmap.get(wsub.getWindpowerstationid());

                    List<Windsubstationtestingpoint> points=new ArrayList<>();
                    for(int i=0;i<stpointls.size();i++)
                    {
                        StringBuilder sbtable =new StringBuilder();

                        Windsubstationtandardpoint stp=stpointls.get(i);
                        StringBuilder sb =new StringBuilder();
                        sb.append(wp.getPhoto());
                        String temp=wsub.getId().substring(0,wsub.getId().indexOf("_"));


                        if(stp.getCode().endsWith("CI"))
                        {
                            if(wp.getId().endsWith("FDC"))
                            {
                                sbtable.append(temp).append("FC");
                                sb.append(temp).append("F_").append("XX_XX_XX_XXX_");
                            }else   if(wp.getId().endsWith("GDC"))
                            {
                                sbtable.append(temp).append("GC");
                                sb.append(temp).append("G_").append("XX_XX_XX_XXX_");
                            }

                        }else
                        {
                            sbtable.append(temp).append("DD");
                            if(wp.getId().endsWith("FDC"))
                            {

                                sb.append(temp).append("F_").append("DD_P1_L1_001_");
                            }else   if(wp.getId().endsWith("GDC"))
                            {
                                sb.append(temp).append("G_").append("DD_P1_L1_001_");
                            }
                        }



                        if(stp.getCode().equals(AI))
                        {
                            sb.append(AI);
                        }else if(stp.getCode().equals(DI))
                        {
                            sb.append(DI);
                        }else if(stp.getCode().equals(CI))
                        {
                            sb.append(CI);
                        }

                        sb.append(stp.getOrdernum());

//                        if(stp.getCode().equals(CI))
//                        {
//                            sbtable.append("JSFW.");
//                            sbtable.append(sb);
//                        }else
//                        {
//                            sbtable.append(".").append(sb);
//                        }
                        Windsubstationtestingpoint po=new Windsubstationtestingpoint();
                        po.setCode(String.valueOf(sb));
                        sb =new StringBuilder();
                        sb.append(wsub.getAname()).append(stp.getName());
                        po.setName(String.valueOf(sb));
                        po.setModel(null);
                        po.setModelid(null);
                        po.setWindsubstationid(wsub.getId());
                        po.setUniformcode(stp.getUniformcode());
                        if(stp.getCode().equals(CI))
                        {
//                            sb =new StringBuilder();
//                            temp=wsub.getId().substring(0,wsub.getId().indexOf("_"));
//                            sb.append(temp).append(".JSFW");
//                            po.setRealtimeid(String.valueOf(sb));


                            sb =new StringBuilder();
                            temp=wp.getId().substring(0,wp.getId().indexOf("_"));
                            sb.append("GDHF.JSFW").append(temp).append("DD");
                            po.setRealtimeid(String.valueOf(sb));
                        }


                        points.add(po);
//                                windturbinetestingpointService.insertSelective(po);
                    }

                    allpoints.addAll(points);
                }

            }
        }

        //创建一个数组用于设置表头
        String[] arr = new String[]{"编号","编码","名称","型号","单位","英文名称","类型编号","所属型号","最大值","最小值","合理最大值",
                "合理最小值","风机编号","统一编码","短ID","长ID","风场编号","实时配置编号"};
        String heardName="风机测点表";
        //调用Excel导出工具类
        ExcelExport.exportToPath(allpoints,arr,heardName,6,"调度测点");

    }

    @Override
    public void initalFgl() throws IOException {




        List<Forecaststationtandardpoint>  stpointls=forecaststationtandardpointService.findAllList();

        List<WindPowerStationTestingPoint> allpoints=new ArrayList<>();
        /*********************************************风功率测点生成*****************************************************/

        for (Windpowerstation wp:InitialRunner.wpallls)
        {

            if(wp.getCompanyid().equals("1") && !stpointls.isEmpty())
            {

                List<WindPowerStationTestingPoint> points=new ArrayList<>();
                for(int i=0;i<stpointls.size();i++)
                {


                    Forecaststationtandardpoint stp=stpointls.get(i);
                    StringBuilder sb =new StringBuilder();
                    sb.append(wp.getPhoto());
                    String temp=wp.getId().substring(0,wp.getId().indexOf("_"));

                    if(wp.getId().endsWith("FDC"))
                    {

                        sb.append(temp).append("F_").append("YC_P1_L1_001_");
                    }else   if(wp.getId().endsWith("GDC"))
                    {

                        sb.append(temp).append("G_").append("YC_P1_L1_001_");
                    }



                    sb.append(stp.getCode());
                    sb.append(stp.getOrdernum());


                    WindPowerStationTestingPoint po=new WindPowerStationTestingPoint();
                    po.setCode(String.valueOf(sb));
                    sb =new StringBuilder();
                    sb.append(wp.getName()).append(stp.getName());
                    po.setName(String.valueOf(sb));
                    po.setModel(null);
                    po.setModelid(null);
                    po.setWindpowerstationid(wp.getId());
                    po.setUniformcode(stp.getUniformcode());

                    if(stp.getCode().equals(CI))
                    {
                        sb =new StringBuilder();
                        temp=wp.getId().substring(0,wp.getId().indexOf("_"));


                        if(wp.getId().endsWith("FDC"))
                        {

                            sb =new StringBuilder();
                            temp=wp.getId().substring(0,wp.getId().indexOf("_"));
                            sb.append("GDHF.").append(temp).append("FGL");
                            po.setRealtimeid(String.valueOf(sb));
                        }else  if(wp.getId().endsWith("GDC"))
                        {

                            sb =new StringBuilder();
                            temp=wp.getId().substring(0,wp.getId().indexOf("_"));
                            sb.append("GDHF.").append(temp).append("GGL");
                            po.setRealtimeid(String.valueOf(sb));
                        }


                        po.setRealtimeid(String.valueOf(sb));
                    }
                    points.add(po);
                }
                allpoints.addAll(points);
            }


        }

        //创建一个数组用于设置表头
        String[] arr = new String[]{"编号","编码","名称","型号","单位","英文名称","类型编号","所属型号","最大值","最小值","合理最大值",
                "合理最小值","风机编号","统一编码","短ID","长ID","风场编号","实时配置编号"};
        String heardName="风机测点表";
        //调用Excel导出工具类
        ExcelExport.exportToPath(allpoints,arr,heardName,6,"风功率测点");
    }


    public void initalFj() throws IOException {

        // windturbinetestingpointService.deleteAll();

        List<Windturbinestandardpoint>  stpointls=windturbinestandardpointService.findAllList();

        Map<String, List<Windturbinestandardpoints>> wpsmap=windturbinestandardpointsService.findAllMap();
        List<Windturbinetestingpoint> allpoints=new ArrayList<>();
//            for (Windpowerstation wp:InitialRunner.wpls)
//            {
//
//
////                if(wp.getId().endsWith("FDC"))
////                {
//                    List<Windturbine> wtls=InitialRunner.wp_wtmap.get(wp.getId());
//
//
//                    if(!stpointls.isEmpty())
//                    {
//                        for(Windturbine wt:wtls)
//                        {
//                            List<Windturbinetestingpoint> points=new ArrayList<>();
//                            for(int i=0;i<stpointls.size();i++)
//                            {
//
//
//                                Windturbinestandardpoint stp=stpointls.get(i);
//                                StringBuilder sb =new StringBuilder();
//                                sb.append(wp.getPhoto());
//                                String temp=wp.getId().substring(0,wp.getId().indexOf("_"));
//
//
//                              //  sb.append(temp).append("F_").append("FJ_");
//
//                                if(stp.getCode().equals(CI))
//                                {
//                                    sb.append(temp).append("F_").append("JS_");
//                                }else
//                                {
//                                    sb.append(temp).append("F_").append("FJ_");
//                                }
//                                temp=wt.getProjectid().substring(0,wt.getProjectid().lastIndexOf("_"));
//                                sb.append("P").append(Integer.valueOf(temp.substring(temp.length()-2))).append("_");
//                                temp=wt.getLineid().substring(0,wt.getProjectid().lastIndexOf("_"));
//                                sb.append("L").append(Integer.valueOf(temp.substring(temp.length()-2))).append("_");
//
//                                temp=wt.getId().substring(wt.getId().lastIndexOf("_")+1);
//
//                                if(temp.length()==1)
//                                {
//                                    sb.append("00").append(temp).append("_");
//                                }else if(temp.length()==2)
//                                {
//                                    sb.append("0").append(temp).append("_");
//                                }else
//                                {
//                                    sb.append(temp).append("_");
//                                }
//
//
//                                sb.append(stp.getCode());
//
//                                sb.append(stp.getOrdernum());
//
//
//                                Windturbinetestingpoint po=new Windturbinetestingpoint();
//                                po.setId(String.valueOf(sb));
//                                po.setCode(String.valueOf(sb));
//                                sb =new StringBuilder();
//                                sb.append(wt.getName()).append(stp.getName());
//                                po.setName(String.valueOf(sb));
//                                po.setModel(wt.getModelid());
//                                po.setModelid(wt.getModelid());
//                                po.setWindturbineid(wt.getId());
//                                po.setUniformcode(stp.getUniformcode());
//                                po.setWindpowerstationid(wt.getWindpowerstationid());
//
//                                if(stp.getCode().equals(CI))
//                                {
//                                    sb =new StringBuilder();
//                                    temp=wp.getId().substring(0,wp.getId().indexOf("_"));
//                                    sb.append("GDHF.JSFW").append(temp).append("FJ");
//                                    po.setRealtimeid(String.valueOf(sb));
//                                }else
//                                {
//                                    sb =new StringBuilder();
//                                    temp=wp.getId().substring(0,wp.getId().indexOf("_"));
//                                    sb.append("GDHF.").append(temp).append("FJ");
//                                    po.setRealtimeid(String.valueOf(sb));
//                                }
//                                points.add(po);
//
//
////                                windturbinetestingpointService.insertSelective(po);
//                            }
//                            allpoints.addAll(points);
////                            windturbinetestingpointService.insertBatch(points);
//
//
//                        }
//                    }
//
//
//
// //               }
//
//
//
//            }



        for (Windpowerstation wp:InitialRunner.wpls)
        {


            List<Windturbine> wtls=InitialRunner.wp_wtmap.get(wp.getId());


            if(!stpointls.isEmpty())
            {
                for(Windturbine wt:wtls)
                {

                    if(wpsmap.containsKey(wt.getModelid()))
                    {
                        List<Windturbinestandardpoints> wpsls=wpsmap.get(wt.getModelid());

                        List<Windturbinetestingpoint> points=new ArrayList<>();
                        for(int i=0;i<wpsls.size();i++)
                        {


                            Windturbinestandardpoints stp=wpsls.get(i);
                            StringBuilder sb =new StringBuilder();
                            sb.append(wp.getPhoto());
                            String temp=wp.getId().substring(0,wp.getId().indexOf("_"));


                            //  sb.append(temp).append("F_").append("FJ_");

                            if(stp.getCode().equals(CI))
                            {
                                sb.append(temp).append("F_").append("JS_");
                            }else
                            {
                                sb.append(temp).append("F_").append("FJ_");
                            }
                            temp=wt.getProjectid().substring(0,wt.getProjectid().lastIndexOf("_"));
                            sb.append("P").append(Integer.valueOf(temp.substring(temp.length()-2))).append("_");
                            temp=wt.getLineid().substring(0,wt.getProjectid().lastIndexOf("_"));
                            sb.append("L").append(Integer.valueOf(temp.substring(temp.length()-2))).append("_");

                            temp=wt.getId().substring(wt.getId().lastIndexOf("_")+1);

                            if(temp.length()==1)
                            {
                                sb.append("00").append(temp).append("_");
                            }else if(temp.length()==2)
                            {
                                sb.append("0").append(temp).append("_");
                            }else
                            {
                                sb.append(temp).append("_");
                            }


                            sb.append(stp.getCode());

                            sb.append(stp.getOrdernum());


                            Windturbinetestingpoint po=new Windturbinetestingpoint();
                            po.setId(String.valueOf(sb));
                            po.setCode(String.valueOf(sb));
                            sb =new StringBuilder();
                            sb.append(wt.getName()).append(stp.getName());
                            po.setName(String.valueOf(sb));
                            po.setModel(wt.getModelid());
                            po.setModelid(wt.getModelid());
                            po.setWindturbineid(wt.getId());
                            po.setUniformcode(stp.getUniformcode());
                            po.setWindpowerstationid(wt.getWindpowerstationid());

                            if(stp.getCode().equals(CI))
                            {
                                sb =new StringBuilder();
                                temp=wp.getId().substring(0,wp.getId().indexOf("_"));
                                sb.append("GDHF.JSFW").append(temp).append("FJ");
                                po.setRealtimeid(String.valueOf(sb));
                            }else
                            {
                                sb =new StringBuilder();
                                temp=wp.getId().substring(0,wp.getId().indexOf("_"));
                                sb.append("GDHF.").append(temp).append("FJ");
                                po.setRealtimeid(String.valueOf(sb));
                            }
                            points.add(po);


//                               allpoints.addAll(points);
                        }
                        allpoints.addAll(points);
                    }

                }
            }


        }
        //创建一个数组用于设置表头
        String[] arr = new String[]{"编号","编码","名称","型号","单位","英文名称","类型编号","所属型号","最大值","最小值","合理最大值",
                "合理最小值","风机编号","统一编码","短ID","长ID","风场编号","实时配置编号"};
        String heardName="风机测点表";
        //调用Excel导出工具类
        ExcelExport.exportToPath(allpoints,arr,heardName,6,"风机测点DI");

    }

}
