package com.gyee.generation.service.initialpoint;


import com.gyee.generation.init.CacheContext;
import com.gyee.generation.model.auto.*;
import com.gyee.generation.service.auto.*;
import com.gyee.generation.util.ExcelExport;
import com.gyee.generation.util.StringUtils;
import org.springframework.stereotype.Service;

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

@Service
public class InitialPointGoldenXkService implements IinitialPoint {


    @Resource
    private IProBasicRegionService proBasicRegionService;
    @Resource
    private IProBasicCompanyService proBasicCompanyService;

    @Resource
    private IProBasicPowerstationService proBasicWindpowerstationService;
    @Resource
    private IProBasicProjectService proBasicProjectService;
    @Resource
    private IProBasicLineService proBasicLineService;
    @Resource
    private IProEconWindpowerStandardPointService proEconWindpowerStandardPointService;
    @Resource
    private IProEconWindturbineStandardPointService proEconWindturbineStandardPointService;

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


    private final String FC = "FC";
    private final String GF = "GF";

    @Override
    public void initalFc() throws IOException {


        //   windPowerstationTestingPointService.deleteAll();


        List<ProEconWindpowerStandardPoint> stpointls = proEconWindpowerStandardPointService.list();


        List<ProBasicRegion> regions = proBasicRegionService.list();


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

        if (!regions.isEmpty()) {


            for (ProBasicRegion re : regions) {

                StringBuilder sba = new StringBuilder();
                sba.append(re.getId().substring(0, re.getId().indexOf("_"))).append("_");
                /********************************************区域公司测点**************************************************/
                List<ProBasicPowerstationPoint> points = new ArrayList<>();
                for (int i = 0; i < stpointls.size(); i++) {
                    if (stpointls.get(i).getTypes().equals("GF")) {
                        continue;
                    }
                    ProEconWindpowerStandardPoint stp = stpointls.get(i);
                    StringBuilder sb = new StringBuilder();
                    StringBuilder sbtable = new StringBuilder();
                    sbtable.append(re.getId().substring(0, re.getId().indexOf("_")));
                    sb.append(String.valueOf(sba));
                    sb.append("XXXX_XXX_X_XX_XX_XXXX_");
                    sb.append(CI);
                    sb.append(stp.getOrdernum());
                    if (stp.getNemCode().equals(CI)) {
                        sbtable.append("JSFW.");
                        sbtable.append(sb);
                    }
                    ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();
                    po.setId(StringUtils.getUUID());
                    //                            po.setNemCode(V2Config.getInitialcode());
                    po.setNemCode(String.valueOf(sbtable));
                    sb = new StringBuilder();
                    sb.append(re.getName()).append(stp.getName());
                    po.setName(String.valueOf(sb));
                    po.setModel(null);
                    po.setModelId(null);

                    StringBuilder tempsb = new StringBuilder();

                    if (StringUtils.notEmp(re.getNemCode())) {
                        tempsb.append(re.getNemCode()).append("0");
                    } else {
                        tempsb.append("0");
                    }

                    po.setWindpowerstationId(String.valueOf(tempsb));
                    po.setUniformCode(stp.getUniformcode());


                    if (stp.getNemCode().equals(CI)) {
                        sb = new StringBuilder();
                        sb.append(re.getNemCode()).append(".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++) {
                    sba = new StringBuilder();
                    if (stpointls.get(i).getTypes().equals("GF")) {
                        continue;
                    }
                    ProEconWindpowerStandardPoint stp = stpointls.get(i);
                    StringBuilder sb = new StringBuilder();
                    StringBuilder sbtable = new StringBuilder();
                    sbtable.append(re.getId().substring(0, re.getId().indexOf("_")));
                    sb.append(String.valueOf(sba));
                    sb.append(re.getId().substring(0, re.getId().indexOf("_"))).append("_XXXX_XXX_F_XX_XX_XXXX_");
                    sb.append(CI);
                    sb.append(stp.getOrdernum());
                    if (stp.getNemCode().equals(CI)) {
                        //                                sbtable.append("JSFW.");
                        sbtable.append("JSFW.");
                        sbtable.append(sb);
                    }
                    ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();
                    po.setId(StringUtils.getUUID());
                    //                            po.setNemCode(V2Config.getInitialcode());
                    po.setNemCode(String.valueOf(sbtable));
                    sb = new StringBuilder();
                    sb.append(re.getName()).append("风电").append(stp.getName());
                    po.setName(String.valueOf(sb));
                    po.setModel(null);
                    po.setModelId(null);

                    StringBuilder tempsb = new StringBuilder();
                    if (StringUtils.notEmp(re.getNemCode())) {
                        tempsb.append(re.getNemCode()).append("-1");
                    } else {
                        tempsb.append("-1");
                    }
                    po.setWindpowerstationId(String.valueOf(tempsb));
                    po.setUniformCode(stp.getUniformcode());


                    if (stp.getNemCode().equals(CI)) {
                        sb = new StringBuilder();
                        sb.append(re.getNemCode()).append(".JSFW");
                        po.setRealtimeId(String.valueOf(sb));
                    }
                    //                            else
                    //                            {
                    //                                sb =new StringBuilder();
                    //                                sb.append(re.getNemCode()).append(cs.getId()).append(".JSFWDD");
                    //                                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++) {
                    if (stpointls.get(i).getTypes().equals("FD")) {
                        continue;
                    }

                    ProEconWindpowerStandardPoint stp = stpointls.get(i);
                    StringBuilder sb = new StringBuilder();
                    StringBuilder sbtable = new StringBuilder();
                    sbtable.append(re.getId().substring(0, re.getId().indexOf("_")));
                    sb.append(String.valueOf(sba));
                    sb.append(re.getId().substring(0, re.getId().indexOf("_"))).append("_XXXX_XXX_G_XX_XX_XXXX_");
                    sb.append(CI);
                    sb.append(stp.getOrdernum());
                    if (stp.getNemCode().equals(CI)) {
                        //                                sbtable.append("JSFW.");
                        sbtable.append("JSFW.");
                        sbtable.append(sb);
                    }
                    ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();
                    po.setId(StringUtils.getUUID());
                    //                            po.setNemCode(V2Config.getInitialcode());
                    po.setNemCode(String.valueOf(sbtable));
                    sb = new StringBuilder();
                    sb.append(re.getName()).append("光伏").append(stp.getName());
                    po.setName(String.valueOf(sb));
                    po.setModel(null);
                    po.setModelId(null);
                    StringBuilder tempsb = new StringBuilder();

                    if (StringUtils.notEmp(re.getNemCode())) {
                        tempsb.append(re.getNemCode()).append("-2");
                    } else {
                        tempsb.append("-2");
                    }

                    po.setWindpowerstationId(String.valueOf(tempsb));
                    po.setUniformCode(stp.getUniformcode());

                    if (stp.getNemCode().equals(CI)) {
                        sb = new StringBuilder();
                        sb.append(re.getNemCode()).append(".JSFW");
                        po.setRealtimeId(String.valueOf(sb));
                    }
                    //                            else
                    //                            {
                    //                                sb =new StringBuilder();
                    //                                sb.append(re.getNemCode()).append(cs.getId()).append(".JSFWDD");
                    //                                po.setRealtimeId(String.valueOf(sb));
                    //                            }


                    points.add(po);
                }

                allpoints.addAll(points);
                List<ProBasicCompany> companys = proBasicCompanyService.list().stream().filter(i -> i.getRegionId().equals(re.getId())).collect(Collectors.toList());
                if (!companys.isEmpty()) {
                    for (ProBasicCompany cs : companys) {
                        sba = new StringBuilder();
                        sba.append(cs.getId().substring(0, cs.getId().lastIndexOf("_"))).append("_");
                        /********************************************区域公司测点**************************************************/
                        points = new ArrayList<>();
                        for (int i = 0; i < stpointls.size(); i++) {

                            if (stpointls.get(i).getTypes().equals("GF")) {
                                continue;
                            }
                            ProEconWindpowerStandardPoint stp = stpointls.get(i);
                            StringBuilder sb = new StringBuilder();
                            StringBuilder sbtable = new StringBuilder();
                            sbtable.append(re.getId().substring(0, re.getId().indexOf("_")));

                            sb.append(String.valueOf(sba));
                            sb.append("XXX_X_XX_XX_XXXX_");
                            sb.append(CI);
                            sb.append(stp.getOrdernum());
                            if (stp.getNemCode().equals(CI)) {
                                sbtable.append("JSFW.");
                                sbtable.append(sb);
                            }
                            ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();
                            po.setId(StringUtils.getUUID());
                            //                            po.setNemCode(V2Config.getInitialcode());
                            po.setNemCode(String.valueOf(sbtable));
                            sb = new StringBuilder();
                            sb.append(cs.getName()).append(stp.getName());
                            po.setName(String.valueOf(sb));
                            po.setModel(null);
                            po.setModelId(null);

                            StringBuilder tempsb = new StringBuilder();

                            if (StringUtils.notEmp(cs.getNemCode())) {
                                tempsb.append(cs.getNemCode()).append("0");
                            } else {
                                tempsb.append("0");
                            }

                            po.setWindpowerstationId(String.valueOf(tempsb));
                            po.setUniformCode(stp.getUniformcode());


                            if (stp.getNemCode().equals(CI)) {
                                sb = new StringBuilder();
                                sb.append(cs.getId()).append(".JSFW");
                                po.setRealtimeId(String.valueOf(sb));
                            }


                            points.add(po);
                        }

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

                        /*******************************************区域公司测点*******************************************************/
                        /********************************************风电场公司测点**************************************************/
                        points = new ArrayList<>();

                        sba = new StringBuilder();
                        sba.append(cs.getId().substring(0, cs.getId().lastIndexOf("_"))).append("_");
                        for (int i = 0; i < stpointls.size(); i++) {

                            if (stpointls.get(i).getTypes().equals("GF")) {
                                continue;
                            }
                            ProEconWindpowerStandardPoint stp = stpointls.get(i);
                            StringBuilder sb = new StringBuilder();
                            StringBuilder sbtable = new StringBuilder();
                            sbtable.append(re.getId().substring(0, re.getId().indexOf("_")));
                            sb.append(String.valueOf(sba));
                            sb.append("XXX_F_XX_XX_XXXX_");
                            sb.append(CI);
                            sb.append(stp.getOrdernum());
                            if (stp.getNemCode().equals(CI)) {
                                //                                sbtable.append("JSFW.");
                                sbtable.append("JSFW.");
                                sbtable.append(sb);
                            }
                            ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();
                            po.setId(StringUtils.getUUID());
                            //                            po.setNemCode(V2Config.getInitialcode());
                            po.setNemCode(String.valueOf(sbtable));
                            sb = new StringBuilder();
                            sb.append(cs.getName()).append("风电").append(stp.getName());
                            po.setName(String.valueOf(sb));
                            po.setModel(null);
                            po.setModelId(null);

                            StringBuilder tempsb = new StringBuilder();
                            if (StringUtils.notEmp(cs.getNemCode())) {
                                tempsb.append(cs.getNemCode()).append("-1");
                            } else {
                                tempsb.append("-1");
                            }
                            po.setWindpowerstationId(String.valueOf(tempsb));
                            po.setUniformCode(stp.getUniformcode());


                            if (stp.getNemCode().equals(CI)) {
                                sb = new StringBuilder();
                                sb.append(cs.getId()).append(".JSFW");
                                po.setRealtimeId(String.valueOf(sb));
                            }
                            //                            else
                            //                            {
                            //                                sb =new StringBuilder();
                            //                                sb.append(re.getNemCode()).append(cs.getId()).append(".JSFWDD");
                            //                                po.setRealtimeId(String.valueOf(sb));
                            //                            }


                            points.add(po);
                        }

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

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


                        /*********************************************光伏测点生成*****************************************************/
                        sba = new StringBuilder();
                        sba.append(cs.getId().substring(0, cs.getId().lastIndexOf("_"))).append("_");
                        points = new ArrayList<>();
                        for (int i = 0; i < stpointls.size(); i++) {
                            if (stpointls.get(i).getTypes().equals("FD")) {
                                continue;
                            }

                            ProEconWindpowerStandardPoint stp = stpointls.get(i);
                            StringBuilder sb = new StringBuilder();
                            StringBuilder sbtable = new StringBuilder();
                            sbtable.append(re.getId().substring(0, re.getId().indexOf("_")));
                            sb.append(String.valueOf(sba));
                            sb.append("XXX_G_XX_XX_XXXX_");
                            sb.append(CI);
                            sb.append(stp.getOrdernum());
                            if (stp.getNemCode().equals(CI)) {
                                //                                sbtable.append("JSFW.");
                                sbtable.append("JSFW.");
                                sbtable.append(sb);
                            }
                            ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();
                            po.setId(StringUtils.getUUID());
                            //                            po.setNemCode(V2Config.getInitialcode());
                            po.setNemCode(String.valueOf(sbtable));
                            sb = new StringBuilder();
                            sb.append(cs.getName()).append("光伏").append(stp.getName());
                            po.setName(String.valueOf(sb));
                            po.setModel(null);
                            po.setModelId(null);
                            StringBuilder tempsb = new StringBuilder();

                            if (StringUtils.notEmp(cs.getNemCode())) {
                                tempsb.append(cs.getNemCode()).append("-2");
                            } else {
                                tempsb.append("-2");
                            }

                            po.setWindpowerstationId(String.valueOf(tempsb));
                            po.setUniformCode(stp.getUniformcode());

                            if (stp.getNemCode().equals(CI)) {
                                sb = new StringBuilder();
                                sb.append(cs.getId()).append(".JSFW");
                                po.setRealtimeId(String.valueOf(sb));
                            }
                            //                            else
                            //                            {
                            //                                sb =new StringBuilder();
                            //                                sb.append(re.getNemCode()).append(cs.getId()).append(".JSFWDD");
                            //                                po.setRealtimeId(String.valueOf(sb));
                            //                            }


                            points.add(po);
                        }

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


        //        }


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

        for (ProBasicPowerstation wp : CacheContext.wpls) {
            List<ProEconWindpowerStandardPoint> ls = null;
            if (wp.getId().indexOf("FDC") >= 0) {
                ls = stpointls.stream().filter(i -> i.getTypes().equals("FD")).collect(Collectors.toList());

            } else {
                ls = stpointls.stream().filter(i -> i.getTypes().equals("GF")).collect(Collectors.toList());

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

        }

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

    @Override
    public void initalZb() throws IOException {

    }

    @Override
    public void initalQx() throws IOException {

    }

    @Override
    public void initalFgl() throws IOException {

    }

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


            ProEconWindpowerStandardPoint stp = stpointls.get(i);
            StringBuilder sb = new StringBuilder();
            //            sb.append(wp.getPhoto());
            String temp = wp.getId().substring(0, wp.getId().lastIndexOf("_"));
            temp = temp.substring(0, temp.lastIndexOf("_"));
            temp = temp.substring(temp.lastIndexOf("_") + 1);
            StringBuilder sba = new StringBuilder();

            sb.append(wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"))).append("_");
            if (wp.getId().indexOf("FDC") >= 0) {

                String temp2 = wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"));
                temp2 = temp2.substring(temp2.indexOf("_") + 1);
                sba.append(temp2).append("FC");
                sb.append(temp).append("_F").append("_XX_XX_XXXX_");
            } else if (wp.getId().indexOf("GDC") >= 0) {
                String temp2 = wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"));
                temp2 = temp2.substring(temp2.indexOf("_") + 1);
                sba.append(temp2).append("GC");
                sb.append(temp).append("_G").append("_XX_XX_XXXX_");
            }

            sb.append(CI);
            sb.append(stp.getOrdernum());
            StringBuilder sbtable = new StringBuilder();


            if (stp.getNemCode().equals(CI)) {
                sbtable.append(sba).append("JSFW.");
                sbtable.append(sb);
            }
            //            else
            //            {
            //                sbtable.append(sba).append("DD.");
            //                sbtable.append(sb);
            //            }


            ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();
            po.setId(StringUtils.getUUID());
            //            po.setNemCode(V2Config.getInitialcode());
            po.setNemCode(String.valueOf(sbtable));
            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.getNemCode().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.getNemCode().equals(CI)) {
                sb = new StringBuilder();

                if (StringUtils.notEmp(wp.getPhoto())) {
                    sb.append(wp.getPhoto().replace("_", "")).append(".JSFW").append(sba);
                }

                po.setRealtimeId(String.valueOf(sb));
            }
            //            else
            //            {
            //                sb =new StringBuilder();
            //                temp=wp.getId().substring(0,wp.getId().indexOf("_"));
            //                if(StringUtils.notEmp(wp.getPhoto()))
            //                {
            //                    sb.append(wp.getPhoto().replace("_",""));
            //                }
            //                sb.append(".JSFW").append(temp).append("DD");
            //                po.setRealtimeId(String.valueOf(sb));
            //            }
            points.add(po);
        }

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


    private void createPjPoints(ProBasicPowerstation wp, List<ProEconWindpowerStandardPoint> stpointls, List<ProBasicPowerstationPoint> allpoints) {


        for (ProBasicProject pj : CacheContext.pjls) {
            if (pj.getWindpowerstationId().equals(wp.getId())) {
                List<ProBasicPowerstationPoint> points = new ArrayList<>();
                for (int i = 0; i < stpointls.size(); i++) {


                    ProEconWindpowerStandardPoint stp = stpointls.get(i);
                    StringBuilder sb = new StringBuilder();
                    //                    sb.append(wp.getPhoto());
                    String temp = wp.getId().substring(0, wp.getId().lastIndexOf("_"));
                    temp = temp.substring(0, temp.lastIndexOf("_"));
                    temp = temp.substring(temp.lastIndexOf("_") + 1);
                    sb.append(wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"))).append("_");
                    //                    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);


                    StringBuilder sba = new StringBuilder();

                    if (wp.getId().indexOf("FDC") >= 0) {
                        String temp2 = wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"));
                        temp2 = temp2.substring(temp2.indexOf("_") + 1);
                        sba.append(temp2).append("FC");
                        sb.append(temp).append("_F_");
                        temp = pj.getId().substring(0, pj.getId().lastIndexOf("_"));
                        sb.append("P").append(Integer.valueOf(temp.substring(temp.length() - 2))).append("_");
                        sb.append("XX_XXXX_");
                    } else if (wp.getId().indexOf("GDC") >= 0) {
                        String temp2 = wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"));
                        temp2 = temp2.substring(temp2.indexOf("_") + 1);
                        sba.append(temp2).append("GC");
                        sb.append(temp).append("_G_");
                        temp = pj.getId().substring(0, pj.getId().lastIndexOf("_"));
                        sb.append("P").append(Integer.valueOf(temp.substring(temp.length() - 2))).append("_");
                        sb.append("XX_XXXX_");
                    }

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

                    StringBuilder sbtable = new StringBuilder();


                    if (stp.getNemCode().equals(CI)) {
                        sbtable.append(sba).append("JSFW.");
                        sbtable.append(sb);
                    }

                    ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();

                    po.setId(StringUtils.getUUID());
                    //                    po.setNemCode(V2Config.getInitialcode());
                    po.setNemCode(String.valueOf(sbtable));
                    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.getNemCode().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.getNemCode().equals(CI)) {
                        sb = new StringBuilder();

                        if (StringUtils.notEmp(wp.getPhoto())) {
                            sb.append(wp.getPhoto().replace("_", "")).append(".JSFW").append(sba);
                        }

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

    }


    private void createLnPoints(ProBasicPowerstation wp, List<ProEconWindpowerStandardPoint> stpointls, List<ProBasicPowerstationPoint> allpoints) {

        for (ProBasicLine ln : CacheContext.lnls) {
            if (CacheContext.pjmap.containsKey(ln.getProjectId())) {
                ProBasicProject pj = CacheContext.pjmap.get(ln.getProjectId());

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


                        ProEconWindpowerStandardPoint stp = stpointls.get(i);
                        StringBuilder sb = new StringBuilder();
                        //                        sb.append(wp.getPhoto());
                        String temp = wp.getId().substring(0, wp.getId().lastIndexOf("_"));
                        temp = temp.substring(0, temp.lastIndexOf("_"));
                        temp = temp.substring(temp.lastIndexOf("_") + 1);
                        sb.append(wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"))).append("_");

                        //                        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());
                        StringBuilder sba = new StringBuilder();

                        if (wp.getId().indexOf("FDC") >= 0) {
                            String temp2 = wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"));
                            temp2 = temp2.substring(temp2.indexOf("_") + 1);
                            sba.append(temp2).append("FC");
                            sb.append(temp).append("_F_");
                            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("XXXX_");
                            //                            sb.append(CI);
                        } else if (wp.getId().indexOf("GDC") >= 0) {
                            String temp2 = wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"));
                            temp2 = temp2.substring(temp2.indexOf("_") + 1);
                            sba.append(temp2).append("GC");
                            sb.append(temp).append("G_");
                            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("XXXX_");
                            //                            sb.append(CI);
                        }

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

                        StringBuilder sbtable = new StringBuilder();


                        if (stp.getNemCode().equals(CI)) {
                            sbtable.append(sba).append("JSFW.");
                            sbtable.append(sb);
                        }


                        ProBasicPowerstationPoint po = new ProBasicPowerstationPoint();
                        po.setId(StringUtils.getUUID());
                        //                        po.setNemCode(V2Config.getInitialcode());
                        po.setNemCode(String.valueOf(sbtable));
                        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.getNemCode().equals(CI)) {
                            sb = new StringBuilder();

                            if (StringUtils.notEmp(wp.getPhoto())) {
                                sb.append(wp.getPhoto().replace("_", "")).append(".JSFW").append(sba);
                            }

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


                }
            }

        }

    }


    public void initalFj() throws IOException {

        // windturbinetestingpointService.deleteAll();


        List<ProEconWindturbineStandardPoint> stpointls = proEconWindturbineStandardPointService.list();

        //        Map<String, List<Windturbinestandardpoints>> wpsmap=windturbinestandardpointsService.findAllMap();
        List<ProBasicEquipmentPoint> allpoints = new ArrayList<>();


        for (ProBasicPowerstation wp : CacheContext.wpls) {

            List<ProEconWindturbineStandardPoint> ls = null;
            if (wp.getId().indexOf("FDC") >= 0) {
                ls = stpointls.stream().filter(i -> i.getTypes().equals("FD")).collect(Collectors.toList());

            } else {
                ls = stpointls.stream().filter(i -> i.getTypes().equals("GF")).collect(Collectors.toList());

            }
            List<ProBasicEquipment> wtls = CacheContext.wpwtmap.get(wp.getId());


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

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

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


                        ProEconWindturbineStandardPoint stp = ls.get(i);
                        StringBuilder sb = new StringBuilder();
                        //                        sb.append(wp.getPhoto());

                        String temp = wp.getId().substring(0, wp.getId().lastIndexOf("_"));
                        temp = temp.substring(0, temp.lastIndexOf("_"));
                        temp = temp.substring(temp.lastIndexOf("_") + 1);
                        if (wp.getId().indexOf("FDC") >= 0) {
                            sb.append(wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"))).append("_").append(temp).append("_F_");
                        } else {
                            sb.append(wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"))).append("_").append(temp).append("_G_");
                        }


                        temp = null;
                        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("_") - 4, wt.getId().lastIndexOf("_"));

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


                        sb.append(stp.getNemCode());

                        sb.append(stp.getOrdernum());

                        StringBuilder sba = new StringBuilder();

                        temp = wp.getId().substring(0, wp.getId().lastIndexOf("_"));
                        temp = temp.substring(0, temp.lastIndexOf("_"));
                        temp = temp.substring(temp.lastIndexOf("_") + 1);

                        String temp2 = wp.getCompanyId().substring(0, wp.getCompanyId().lastIndexOf("_"));
                        temp2 = temp2.substring(temp2.indexOf("_") + 1);
                        if (wp.getId().indexOf("FDC") >= 0) {
                            sba.append(temp2).append("FJ");
                        } else if (wp.getId().indexOf("GDC") >= 0) {
                            sba.append(temp2).append("GF");
                        }

                        StringBuilder sbtable = new StringBuilder();


                        if (stp.getNemCode().equals(CI)) {
                            sbtable.append(sba).append("JSFW.");
                            sbtable.append(sb);
                        } else {
                            sbtable.append(sba).append(".");
                            sbtable.append(sb);
                        }

                        ProBasicEquipmentPoint po = new ProBasicEquipmentPoint();
                        po.setId(StringUtils.getUUID());
                        //                        po.setNemCode(V2Config.getInitialcode());

                        if (stp.getNemCode().equals(CI)) {
                            po.setNemCode(String.valueOf(sbtable));
                        } else {
                            po.setNemCode("INITIAL");
                        }

                        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.getNemCode().equals(CI)) {
                            sb = new StringBuilder();

                            sb.append(wp.getId().substring(0, wp.getId().lastIndexOf("_")).replace("_", "")).append(".JSFW").append(sba);

                            po.setRealtimeId(String.valueOf(sb));
                        } else {
                            sb = new StringBuilder();

                            sb.append(wp.getId().substring(0, wp.getId().lastIndexOf("_")).replace("_", "")).append(".").append(sba);

                            po.setRealtimeId(String.valueOf(sb));
                        }

                        points.add(po);


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

            }
            //            }


        }

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

    }


    public void initalJkfc() throws IOException {
    }

    public void initalJkfj() throws IOException {
    }

}
