CarUseTypeEnum.java 1.5 KB
package cn.fw.valhalla.sdk.enums;

import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 车辆使用性质
 *
 * @author kurisu
 */
public enum CarUseTypeEnum implements IEnum<Integer> {

    /**
     * 个人
     */
    NO_OPERATING(1, "非运营"),
    /**
     * 企业单位
     */
    OPERATING(2, "运营");

    /**
     * 值
     */
    private final Integer value;
    /**
     * 名称
     */
    @Getter
    private final String name;

    CarUseTypeEnum(final Integer value, final String name) {
        this.value = value;
        this.name = name;
    }

    /**
     * 根据枚举值获取枚举对象
     */
    @JsonCreator
    public static CarUseTypeEnum ofValue(final Integer value) {
        for (final CarUseTypeEnum typeEnum : CarUseTypeEnum.values()) {
            if (typeEnum.value.equals(value)) {
                return typeEnum;
            }
        }
        return null;
    }

    /**
     * 根据枚举中文名字获取枚举对象
     *
     * @param name 名字
     * @return 枚举对象
     */
    public static CarUseTypeEnum ofName(final String name) {
        for (final CarUseTypeEnum typeEnum : CarUseTypeEnum.values()) {
            if (typeEnum.value.equals(name)) {
                return typeEnum;
            }
        }
        return null;
    }


    @Override
    @JsonValue
    public Integer getValue() {
        return value;
    }
}