parent
77fed5d052
commit
7bb85618a6
4 changed files with 85 additions and 4 deletions
@ -0,0 +1,81 @@ |
||||
package com.teaching.backend.constant; |
||||
|
||||
import org.apache.commons.lang3.StringUtils; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Author:youhang |
||||
* @Date:2024-08-07-9:14 |
||||
* @Description: |
||||
*/ |
||||
public enum TypeEnum { |
||||
DEFAULT("default",0), |
||||
PNG("png", 1), |
||||
JPEG("jpeg", 2), |
||||
JPG("jpg", 3), |
||||
GIF("gif", 4), |
||||
DOCX("docx", 5), |
||||
PDF("pdf", 6), |
||||
MD("md", 7), |
||||
XLSX("xlsx", 8), |
||||
TXT("txt", 9), |
||||
WBMP("wbmp", 10), |
||||
TIFF("tiff", 11), |
||||
JFIF("jfif", 12), |
||||
TIF("tif", 13), |
||||
FAX("fax", 14), |
||||
JPE("jpe", 15), |
||||
NET("net", 16), |
||||
RP("rp", 17), |
||||
ICO("ico", 18), |
||||
MP4("mp4", 19); |
||||
|
||||
|
||||
private String prefix; |
||||
private Integer type; |
||||
|
||||
private static final Map<String, TypeEnum> ENUM_MAP = new HashMap<>(); |
||||
|
||||
static { |
||||
TypeEnum[] values = values(); |
||||
for (TypeEnum value : values) { |
||||
ENUM_MAP.put(value.getPrefix(), value); |
||||
} |
||||
} |
||||
|
||||
|
||||
|
||||
TypeEnum(String prefix, Integer type) { |
||||
this.prefix = prefix; |
||||
this.type = type; |
||||
} |
||||
|
||||
public String getPrefix() { |
||||
return prefix; |
||||
} |
||||
public Integer getType() { |
||||
return type; |
||||
} |
||||
|
||||
|
||||
public static Integer getTypeByPrefix(String prefix) { |
||||
if(StringUtils.isEmpty(prefix)){ |
||||
return DEFAULT.getType(); |
||||
} |
||||
prefix = prefix.substring(prefix.lastIndexOf(".") + 1); |
||||
|
||||
TypeEnum viewContentTypeEnum = ENUM_MAP.get(prefix); |
||||
if (viewContentTypeEnum == null) { |
||||
return DEFAULT.getType(); |
||||
} |
||||
Integer type = viewContentTypeEnum.getType(); |
||||
if (type != null) { |
||||
return type; |
||||
} |
||||
return DEFAULT.getType(); |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue