package com.mortals.xhx.common.code;

import com.mortals.framework.common.IBaseEnum;

/**
 * 上传文件类型枚举
 *
 * @author pengziyuan
 */
public enum UploadFileType implements IBaseEnum {

    /** 表格 */
    EXCEL(1, "表格", 1024 * 1023 * 100),
    /** 图片 */
    IMG(2, "图片", 1024 * 1024 * 10),
    /** 压缩文件 */
    ZIP(3, "压缩文件", 1024 * 1024 * 100),
    /** PDF */
    PDF(4, "PDF", 1024 * 1024 * 100),
    /** 其他 */
    OTHER(99, "其他", 1024 * 1024 * 100);

    private int value;
    private String desc;
    private int maxSize;

    UploadFileType(int value, String desc, int maxSize) {
        this.value = value;
        this.desc = desc;
        this.maxSize = maxSize;
    }

    @Override
    public int getValue() {
        return this.value;
    }

    @Override
    public String getDesc() {
        return desc;
    }

    public int getMaxSize() {
        return maxSize;
    }

    public static UploadFileType getFileType(String extension) {
        if ("xls".equalsIgnoreCase(extension) || "xlsx".equalsIgnoreCase(extension)) {
            return EXCEL;
        }
        if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension) || "png".equalsIgnoreCase(extension)
                || "gif".equalsIgnoreCase(extension)) {
            return IMG;
        }
        if ("zip".equalsIgnoreCase(extension)) {
            return ZIP;
        }
        if ("pdf".equalsIgnoreCase(extension)) {
            return PDF;
        }
        return OTHER;
    }

}


