package com.happy.Until.Enum;

import com.happy.Until.Func;

/**
 * 访问量
 *     //1.今日 2.本月 3.本年 4.自定义时间
 */
public enum VisitsEnum {

    今日(1,"今日"),本周(2,"本周"),本月(3,"本月"),
    自定义(4,"自定义"),状态异常(0,"状态异常");

    private int key;
    private String value;

    VisitsEnum(int key, String value) {
        this.key = key;
        this.value = value;
    }

    /**
     * 遍历枚举类
     * @param key
     * @return
     */
    public static VisitsEnum getEunmBykey(int key) {
        try {
            for (VisitsEnum type : VisitsEnum.values()) {
                if (Func.parseInt(type.getKey()) == key) {
                    return type;
                }
            }
        } catch (Exception e) {
            return 状态异常;
        }
        return 状态异常;
    }

    /**
     * 遍历枚举类
     * @param key
     * @return
     */
    public static String getValueBykey(int key) {
        try {
            for (VisitsEnum type : VisitsEnum.values()) {
                if (Func.parseInt(type.getKey()) == key) {
                    return type.getValue();
                }
            }
        } catch (Exception e) {
            return 状态异常.getValue();
        }
        return 状态异常.getValue();
    }

    /**
     * 遍历枚举类
     * @param value
     * @return
     */
    public static int getKeyByValue(String value) {
        try {
            if (Func.checkNull(value))
                return 状态异常.getKey();

            for (VisitsEnum type : VisitsEnum.values()) {
                if (value.equals(Func.parseStr(type.getValue()))) {
                    return type.getKey();
                }
            }
        } catch (Exception e) {
            return 状态异常.getKey();
        }
        return 状态异常.getKey();
    }


    public int getKey() {
        return key;
    }

    public void setKey(int key) {
        this.key = key;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
