package com.mortals.xhx.common.code;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* ${EnumName}枚举类
*
* @author zxfei
*/
public enum ${EnumClassName?cap_first}Enum {
<#list enums as enum>
    <#if JavaType="Integer">
    ${enum.value}(${enum.num}, "${enum.value}")<#sep>,
    <#elseif JavaType="String">
    ${enum.value}("${enum.num}", "${enum.value}")<#sep>,
    </#if>
</#list>
;
    private ${JavaType} value;
    private String desc;

    ${EnumClassName?cap_first}Enum(${JavaType} value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public ${JavaType} getValue() {
        return this.value;
    }

    public String getDesc() {
        return this.desc;
    }

    public static ${EnumClassName?cap_first}Enum getByValue(${JavaType} value) {
        for (${EnumClassName?cap_first}Enum ${EnumClassName?uncap_first}Enum : ${EnumClassName?cap_first}Enum.values()) {
            if (${EnumClassName?uncap_first}Enum.getValue() == value) {
                return ${EnumClassName?uncap_first}Enum;
            }
        }
        return null;
    }

    /**
    * 获取Map集合
    *
    * @param eItem 不包含项
    * @return
    */
    public static Map<String, String> getEnumMap(${JavaType}... eItem) {
        Map<String, String> resultMap = new LinkedHashMap<>();
        for (${EnumClassName?cap_first}Enum item : ${EnumClassName?cap_first}Enum.values()) {
            try {
                boolean hasE = false;
                for (${JavaType} e : eItem) {
                    if (item.getValue() == e) {
                        hasE = true;
                        break;
                    }
                }
                if (!hasE) {
                    resultMap.put(item.getValue() + "", item.getDesc());
                }
            } catch (Exception ex) {

            }
        }
        return resultMap;
    }
}