package com.unissoft.model;

public enum TypeEnum {
    ED("600", "上传失败"),
    ZX("ZX", "个人信用报告查询授权书"),
    XX("XX", "个人信息使用授权书"),
    KK("KK", "委托扣款协议书"),
    S_NUL("S_NUL", "检测失败!"),
    S_SOH("S_SOH", "检测开始!"),
    S_STX("S_STX", "设备通讯异常!"),
    S_ETX("S_ETX", "设备故障!"),
    S_EOT("S_EOT", "未知原因!"),
    S_2D_SOH("S_2D_SOH", "本地模式,无法远程控制!"),
    S_EM("S_EM", "仓房号为空!"),
    SM("SM", "设备正忙!");

    private String code;
    private String desc;

    private TypeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * 处理socket返回结果
     * @param str
     * @return
     */
    public static String resultDispose(String str) {
        if (str.contains("7E")) {
            String substring = str.substring(str.length() - 2, str.length());
            if ("00".equals(substring))
                return TypeEnum.S_NUL.getDesc(); // 失败
            else if ("01".equals(substring))
                return TypeEnum.S_SOH.getDesc();// 成功
            else if ("02".equals(substring))
                return TypeEnum.S_STX.getDesc();// 设备通讯异常
            else if ("03".equals(substring))
                return TypeEnum.S_ETX.getDesc();// 设备故障
            else if ("04".equals(substring))
                return TypeEnum.S_EOT.getDesc();// 未知原因
            else if ("05".equals(substring))
                return TypeEnum.S_2D_SOH.getDesc();// 本地模式,无法远程控制
            else if ("06".equals(substring))
                return TypeEnum.SM.getDesc();// 设备正忙
        }
        return str;
    }

}
