package com.moral.api.pojo.enums; import com.baomidou.mybatisplus.annotation.EnumValue; import com.fasterxml.jackson.annotation.JsonCreator; import lombok.Getter; import java.util.HashMap; import java.util.Map; /** * @ClassName FileType * @Description * @Author fan * @Date 2021/2/1 13:48 * @Version 1.0 **/ @Getter public enum FileType { /** * 其他 */ NON(-1), /** * 图片 */ PICTURE(1), /** * word */ WORD(2), /** * excel */ EXCEL(3), /** * pdf */ PDF(4), /** * 压缩包 */ ZIP(5), /** * 压缩包 */ MP4(6), ; @EnumValue private final Integer value; FileType(Integer value) { this.value = value; } private static final Map VALUE_MAP = new HashMap<>(); static { for (FileType var : values()) { VALUE_MAP.put(var.getValue(), var); } } @JsonCreator public static FileType getEnumByCode(Integer value) { FileType fileType = VALUE_MAP.get(value); if (fileType == null) { throw new RuntimeException("enum not find element, [" + value + "]"); } return fileType; } }