package com.xydl.cac.model;

import lombok.Data;

import java.util.Iterator;
import java.util.Map;

@Data
public class SanbizhiModel {
    Float c2h2;
    Float c2h4;
    Float ch4;
    Float h2;
    Float c2h6;
    Float c2h2_c2h4_value;
    String c2h2_c2h4_code;
    Float ch4_h2_value;
    String ch4_h2_code;
    Float c2h4_c2h6_value;
    String c2h4_c2h6_code;
    String status;
    String desc;

    public boolean build(Map<String, Object> map) {
        Iterator<String> it = map.keySet().iterator();
        while (it.hasNext()) {
            String key = it.next();
            Object value = map.get(key);
            String name = key.toLowerCase().replace("ppm", "");
            if (value != null) {
                if (name.equals("c2h2")) {
                    c2h2 = Float.parseFloat(value.toString());
                } else if (name.equals("c2h4")) {
                    c2h4 = Float.parseFloat(value.toString());
                } else if (name.equals("ch4")) {
                    ch4 = Float.parseFloat(value.toString());
                } else if (name.equals("h2")) {
                    h2 = Float.parseFloat(value.toString());
                } else if (name.equals("c2h6")) {
                    c2h6 = Float.parseFloat(value.toString());
                }
            }
        }
        if (c2h2 == null || c2h4 == null || ch4 == null || h2 == null || c2h6 == null) {
            status = "必要数据缺失";
            return false;
        }
        c2h2_c2h4_value = c2h2 / c2h4;
        ch4_h2_value = ch4 / h2;
        c2h4_c2h6_value = c2h4 / c2h6;
        if (c2h2_c2h4_value < 0.1) {
            c2h2_c2h4_code = "0";
        } else if (c2h2_c2h4_value < 1) {
            c2h2_c2h4_code = "1";
        } else if (c2h2_c2h4_value < 3) {
            c2h2_c2h4_code = "1";
        } else {
            c2h2_c2h4_code = "2";
        }
        if (ch4_h2_value < 0.1) {
            ch4_h2_code = "1";
        } else if (ch4_h2_value < 1) {
            ch4_h2_code = "0";
        } else if (ch4_h2_value < 3) {
            ch4_h2_code = "2";
        } else {
            ch4_h2_code = "2";
        }
        if (c2h4_c2h6_value < 0.1) {
            c2h4_c2h6_code = "0";
        } else if (c2h4_c2h6_value < 1) {
            c2h4_c2h6_code = "0";
        } else if (c2h4_c2h6_value < 3) {
            c2h4_c2h6_code = "1";
        } else {
            c2h4_c2h6_code = "2";
        }
        status = "正常";
        if (c2h2_c2h4_code.equals("0")) {
            if (c2h4_c2h6_code.equals("0")) {
                if (ch4_h2_code.equals("0")) {

                } else if (ch4_h2_code.equals("1")) {
                    status = "局部放电";
                    desc = "高湿度，高含气量引起油中低能量密度的局部放电";
                } else if (ch4_h2_code.equals("2")) {
                    status = "低温过热(150-300)C";
                    desc = "分接开关接触不良，引线夹件螺丝松动或接头焊接不良，涡流引起铜过热，铁心漏磁，局部短路，层间绝缘不良，铁心多点接等";
                }
            } else if (c2h4_c2h6_code.equals("1")) {
                if (ch4_h2_code.equals("0")) {
                    status = "低温过热(低于150C)";
                    desc = "绝缘导线过热，注意CO和CO₂含量和CO₂/CO值";
                } else if (ch4_h2_code.equals("1")) {

                } else if (ch4_h2_code.equals("2")) {
                    status = "中温过热(300-700)C";
                    desc = "分接开关接触不良，引线夹件螺丝松动或接头焊接不良，涡流引起铜过热，铁心漏磁，局部短路，层间绝缘不良，铁心多点接等";
                }
            } else if (c2h4_c2h6_code.equals("2")) {
                status = "高温过热(高于700C)";
                desc = "分接开关接触不良，引线夹件螺丝松动或接头焊接不良，涡流引起铜过热，铁心漏磁，局部短路，层间绝缘不良，铁心多点接等";
            }
        } else if (c2h2_c2h4_code.equals("1")) {
            if (ch4_h2_code.equals("0")) {
                status = "低能放电";
            } else if (ch4_h2_code.equals("1")) {
                status = "低能放电";
            } else if (ch4_h2_code.equals("2")) {
                status = "低能放电兼过热";
            }
            desc = "引线对电位未固定的部件之间连续火花放电，分接抽头引线和油膜闪络，不同电位之间的油中火花放电或悬浮电位之间的火花放电";
        } else if (c2h2_c2h4_code.equals("2")) {
            if (ch4_h2_code.equals("0")) {
                status = "电弧放电";
            } else if (ch4_h2_code.equals("1")) {
                status = "电弧放电";
            } else if (ch4_h2_code.equals("2")) {
                status = "电弧放电兼过热";
            }
            desc = "线圈匝间、层间短路，相间闪络，分接头引线间油膜闪络，引线对箱壳放电，线圈熔断，分接开关飞弧，因环路电流引起电弧，引线对其他接地体放电等";
        }
        return true;
    }
}
