提交 38205f35 authored 作者: lizhuo's avatar lizhuo

--no commit message

上级 16cf689f
...@@ -93,5 +93,6 @@ public class ResourceRequestPath extends BaseRequestPath { ...@@ -93,5 +93,6 @@ public class ResourceRequestPath extends BaseRequestPath {
public static final String UPLOADEPUB = "/uploadepub"; public static final String UPLOADEPUB = "/uploadepub";
/**数据类型*/ /**数据类型*/
public static final String TYPE = "/type"; public static final String TYPE = "/type";
/**下载类型*/
public static final String DOWNLOAD = "/download";
} }
package com.zrqx.core.enums.book;
import java.util.HashMap;
import com.zrqx.core.constant.book.ValidateMessage;
import com.zrqx.core.exception.ParameterValidateException;
/**
* 资源下载类型
* @author Conan
* @date 2018年5月29日 下午3:27:47
*/
public enum BookDownEnum {
SOURCE("source", "排版文件"),
EPUB("epub", "电子书"),
XML("xml", "xml"),
MOBI("mobi", "xml"),
PDF("pdf", "xml"),
OTHER("other", "其他"),
ATTACHMENT("attachment", "附件"),
RESOURCE("resource", "资源内容");
private final String code;
private final String name;
private BookDownEnum(String code,String name){
this.code=code;
this.name=name;
}
public static BookDownEnum valueOfCode(Integer code) {
if (code == null) {
throw new IllegalArgumentException("Book type " + code + " is blank");
}
for (BookDownEnum mt : values()) {
if (mt.getCode().equals(code)) {
return mt;
}
}
throw new IllegalArgumentException("Book type " + code + " is not exist");
}
/**
* 通过ID获取中文名称
* @param code
* @return
*/
public static String getName(Integer code) {
if (code == null) {
return null;
}
for (BookDownEnum mt : values()) {
if (mt.getCode().equals(code)) {
return mt.getName();
}
}
return null;
}
/**
* 获取所有的枚举,以MAP返回
* @return
*/
public static HashMap<String,String> getAllEnumMap() {
HashMap<String,String> map = new HashMap<String,String>();
for (BookDownEnum mt : values()) {
map.put(mt.getCode(), mt.getName());
}
return map;
}
/**
* 获取所有的枚举,以MAP返回, 用于序列化
* @return
*/
public static HashMap<String,String> getEnumsMap() {
HashMap<String,String> map = new HashMap<String,String>();
for (BookDownEnum mt : values()) {
map.put(String.valueOf(mt.getCode()), mt.getName());
}
return map;
}
/**
* 根据名字 获取code
* @Title getCode
* @param name
* @return String
* @author Conan
* @date 2018年7月9日 下午2:52:30
*/
public static String getCode(String name) {
BookDownEnum[] enums = BookDownEnum.values();
for (BookDownEnum BookTypeEnum : enums) {
if (BookTypeEnum.name.equals(name)) {
return BookTypeEnum.code;
}
}
throw new ParameterValidateException(ValidateMessage.STATUS_EXCEPTION);
}
public String getCode() {
return code;
}
public String getName() {
return name;
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论