package com.gyee.frame.util.ticket;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工作票
 */
public class TicketUtil {

    /**
     * 返回所有场站集合
     *
     * @return
     */
    public static List<String> allDept(){
        List<String> list = new ArrayList<>();

        list.add("石板泉风电场");
        list.add("麻黄山风电场");
        list.add("牛首山风电场");
        list.add("香山风电场");
        list.add("青山风电场");
        list.add("平罗光伏电站");
        list.add("宣和光伏发电站");
        list.add("大武口电站");

        return list;
    }


    /**
     * 工作票类型
     *
     * @param type
     * @return
     */
    public static String ticketType(String type) {
        if (type == null)
            return null;

        switch (type) {
            case "wind":
                type = "风场风机";
                break;
            case "elec1":
                type = "电气一种";
                break;
            case "elec2":
                type = "电气二种";
                break;
            case "fire1":
                type = "风场动火";
                break;
            case "fire2":
                type = "二级动火";
                break;
            case "line1":
                type = "线路一种";
                break;
            case "line2":
                type = "线路二种";
                break;
        }

        return type;
    }

    /**
     * 删除安全措施  格式化
     *
     * @param content
     * @return
     */
    public static Map formatSafeMeasureWind(String content) {
        if (content.isEmpty())
            return null;

        String[] split = content.split(",");
        List<Double> listS = new ArrayList<>();
        List<Double> listW = new ArrayList<>();

        for (String str : split) {
            if (str.endsWith("yxzxaqcs") || str.endsWith("jxzlaqcs") || str.endsWith("tooluse")) {
                String id = str.substring(0, str.indexOf("-"));
                listS.add(Double.parseDouble(id));
            } else if (str.endsWith("protectcs")) {
                String id = str.substring(0, str.indexOf("-"));
                listW.add(Double.parseDouble(id));
            }
        }

        Map<String, List<Double>> map = new HashMap<>();
        map.put("safemeasure", listS);
        map.put("safetybaffle", listW);

        return map;
    }

    /**
     * 删除安全措施  格式化
     *
     * @param content
     * @return
     */
    public static Map formatSafeMeasureElec1(String content) {
        if (content.isEmpty())
            return null;

        String[] split = content.split(",");
        List<Double> listD = new ArrayList<>();
        List<Double> listJ = new ArrayList<>();
        List<Double> listP = new ArrayList<>();
        List<Double> listA = new ArrayList<>();

        for (String str : split) {
            if (str.endsWith("dlqglkg")) {
                String id = str.substring(0, str.indexOf("-"));
                listD.add(Double.parseDouble(id));
            } else if (str.endsWith("jdxjddz")) {
                String id = str.substring(0, str.indexOf("-"));
                listJ.add(Double.parseDouble(id));
            }else if (str.endsWith("protectcs")) {
                String id = str.substring(0, str.indexOf("-"));
                listP.add(Double.parseDouble(id));
            }else if (str.endsWith("attention")) {
                String id = str.substring(0, str.indexOf("-"));
                listA.add(Double.parseDouble(id));
            }
        }

        Map<String, List<Double>> map = new HashMap<>();
        map.put("dlqglkg", listD);
        map.put("jdxjddz", listJ);
        map.put("protectcs", listP);
        map.put("attention", listA);

        return map;
    }

    /**
     * 删除安全措施  格式化
     *
     * @param content
     * @return
     */
    public static Map formatSafeMeasureElec2(String content) {
        if (content.isEmpty())
            return null;

        String[] split = content.split(",");
        List<Double> listC = new ArrayList<>();
        List<Double> listS = new ArrayList<>();

        for (String str : split) {
            if (str.endsWith("condition")) {
                String id = str.substring(0, str.indexOf("-"));
                listC.add(Double.parseDouble(id));
            }
            if (str.endsWith("safety")) {
                String id = str.substring(0, str.indexOf("-"));
                listS.add(Double.parseDouble(id));
            }
        }

        Map<String, List<Double>> map = new HashMap<>();
        map.put("condition", listC);
        map.put("safety", listS);

        return map;
    }


    /**
     * 删除安全措施  格式化
     *
     * @param content
     * @return
     */
    public static Map formatSafeMeasureFire1(String content) {
        if (content.isEmpty())
            return null;

        String[] split = content.split(",");
        List<Double> listC = new ArrayList<>();
        List<Double> listS = new ArrayList<>();

        for (String str : split) {
            if (str.endsWith("saferun")) {
                String id = str.substring(0, str.indexOf("-"));
                listC.add(Double.parseDouble(id));
            }
            if (str.endsWith("saferepair")) {
                String id = str.substring(0, str.indexOf("-"));
                listS.add(Double.parseDouble(id));
            }
        }

        Map<String, List<Double>> map = new HashMap<>();
        map.put("saferun", listC);
        map.put("saferepair", listS);

        return map;
    }


    /**
     * 删除安全措施  格式化
     *
     * @param content
     * @return
     */
    public static Map formatSafeMeasureLine1(String content) {
        if (content.isEmpty())
            return null;

        String[] split = content.split(",");
        List<Double> listG = new ArrayList<>();
        List<Double> listS = new ArrayList<>();
        List<Double> listH = new ArrayList<>();
        List<Double> listE = new ArrayList<>();

        for (String str : split) {
            if (str.endsWith("glkgdlq")) {
                String id = str.substring(0, str.indexOf("-"));
                listG.add(Double.parseDouble(id));
            } else if (str.endsWith("safety")) {
                String id = str.substring(0, str.indexOf("-"));
                listS.add(Double.parseDouble(id));
            }else if (str.endsWith("hoveele")) {
                String id = str.substring(0, str.indexOf("-"));
                listH.add(Double.parseDouble(id));
            }else if (str.endsWith("earthline")) {
                String id = str.substring(0, str.indexOf("-"));
                listE.add(Double.parseDouble(id));
            }
        }

        Map<String, List<Double>> map = new HashMap<>();
        map.put("glkgdlq", listG);
        map.put("safety", listS);
        map.put("hoveele", listH);
        map.put("earthline", listE);

        return map;
    }

    /**
     * 删除安全措施  格式化
     *
     * @param content
     * @return
     */
    public static Map formatSafeMeasureLine2(String content) {
        if (content.isEmpty())
            return null;

        String[] split = content.split(",");
        List<Double> listC = new ArrayList<>();
        List<Double> listS = new ArrayList<>();

        for (String str : split) {
            if (str.endsWith("condition")) {
                String id = str.substring(0, str.indexOf("-"));
                listC.add(Double.parseDouble(id));
            }
            if (str.endsWith("safety")) {
                String id = str.substring(0, str.indexOf("-"));
                listS.add(Double.parseDouble(id));
            }
        }

        Map<String, List<Double>> map = new HashMap<>();
        map.put("condition", listC);
        map.put("safety", listS);

        return map;
    }

    /**
     * 流程角色转换为人员组
     *
     * @param role
     * @return
     */
    public static String roleFormat(String role) {
        String groupName = null;
        switch (role) {
            case "工作票签发人":
                groupName = "WTSIGNATOR";
                break;
            case "值班负责人":
                groupName = "SHIFTENGINEER";
                break;
            case "工作票许可人":
                groupName = "XUKEREN";
                break;
            case "经济运行人员":
                groupName = "ECONOMY";
                break;
            case "缺陷运行人员":
                groupName = "RUNUSER";
                break;
            case "检修人员":
                groupName = "CHECKREPAIRUSER";
                break;
            case "消防监护人":
                groupName = "FIRECONTROL";
                break;
        }

        return groupName;
    }

    /**
     * 各种票据的 name 映射
     *
     * @param wfName
     * @return
     */
    public static String wfNameFormat(String wfName) {
        String app = null;
        switch (wfName) {
            case "风电机组工作票":
                app = "WINDELEC";
                break;
            case "电气一种工作票":
                app = "ELEC1";
                break;
            case "电气二种工作票":
                app = "ELEC2";
                break;
            case "风场动火工作票":
                app = "WOMOVEFIRE";
                break;
            case "二级动火工作票":
                app = "WOMOVEFIRE2";
                break;
            case "线路一种工作票":
                app = "ELECFIRST";
                break;
            case "线路二种工作票":
                app = "ELECFIRST2";
                break;
        }

        return app;
    }
}
