/**
* 加班申请流程枚举
*/
public enum AddWorkFlowEnums {
SAVE(0,"待提交","个人加班申请暂存状态"),
Submitted(1,"待办","已经交给项目经理审核"),
Pending(2,"经理通过","项目经理通过,待HR审核"),
REJECT(3,"人力通过","人力资源部审核通过"),
ADOPT_ONE(4,"经理拒绝","项目经理拒绝加班申请"),
ADOPT_TOW(5,"人力拒绝","人力资源部拒绝加班申请");
private final Integer key;
private final String value;
private final String desc;
AddWorkFlowEnums(Integer key, String value,String desc) {
this.key = key;
this.value = value;
this.desc = desc;
}
public Integer key() {
return this.key;
}
public String value() {
return this.value;
}
//根据value获取key
public static Integer getKey(String value) {
AddWorkFlowEnums[] kpiTaskTypeEnums = values();
for (AddWorkFlowEnums kpiWorkEnum : kpiTaskTypeEnums) {
if (kpiWorkEnum.value.equals(value)) {
return kpiWorkEnum.key;
}
}
return null;
}
//根据key获取value
public static String getValue(Integer key) {
AddWorkFlowEnums[] workFlowEnums = values();
for (AddWorkFlowEnums kpiWorkEnum : workFlowEnums) {
if (kpiWorkEnum.key.equals(key)) {
return kpiWorkEnum.value;
}
}
return null;
}
}
//根据key获取枚举
public static AddWorkFlowEnums getTypeBykey(String key) {
AddWorkFlowEnums[] status = values();
for (AddWorkFlowEnums s : status) {
if (s.key.equals(key)) {
return s;
}
}
return null;
}
//根据value获取枚举
public static AddWorkFlowEnums getTypeByValue(String value) {
AddWorkFlowEnums[] status = values();
for (AddWorkFlowEnums s : status) {
if (s.value.equals(value)) {
return s;
}
}
return null;
}
然后几个简单的调用测试
public class test {
public static void main(String[] args) {
System.out.println(AddWorkFlowEnums.Submitted);
System.out.println(AddWorkFlowEnums.getValue(1));
System.out.println(AddWorkFlowEnums.Submitted.getDesc());
System.out.println(AddWorkFlowEnums.getKey("待办"));
System.out.println(AddWorkFlowEnums.Submitted.key());
System.out.println(AddWorkFlowEnums.Submitted.value());
AddWorkFlowEnums status = AddWorkFlowEnums.getTypeByValue("人力通过");
if (status == null){
return;
}
switch (status) {
case SAVE:
System.out.println(AddWorkFlowEnums.SAVE.getDesc());
break;
case REJECT:
System.out.println(AddWorkFlowEnums.REJECT.getDesc());
break;
case Pending:
System.out.println(AddWorkFlowEnums.Pending.getDesc());
break;
case ADOPT_ONE:
System.out.println(AddWorkFlowEnums.ADOPT_ONE.getDesc());
break;
case ADOPT_TOW:
System.out.println(AddWorkFlowEnums.ADOPT_TOW.getDesc());
break;
case Submitted:
System.out.println(AddWorkFlowEnums.Submitted.getDesc());
break;
default:
System.out.println("未找到");
}
}
}
运作截图
记得点赞哦