package com.smartcampus.workflow.entity.enums;
import java.util.Objects;
/**
* @Description 状态枚举
* @Date 2023/8/1 9:14
* @Author guohongqiang
**/
public enum Status {//最后一个枚举是分号 前面是逗号
NEW(10, "新建"),
SHENHE(15, "审核"),
SUBMIT(20, "提交"),
APPROVE(30, "审批"),
DONE(40, "完结");
/**
* 枚举构造方法
*/
Status(int code, String state) {
this.code = code;
this.state = state;
}
/**
* 枚举中对应的属性字段
*/
public final Integer code;
public final String state;
/**如果字段属性是private需要加下面的两个get方法获取属性字段对应的值*/
public Integer getCode() {
return code;
}
public String getState() {
return state;
}
/**
* 根据code获取状态值
*
*/
public static String getStateByCode(int code) {
String resultState = null;
/**获取当前枚举类中所有的枚举*/
Status[] values = Status.values();
/**遍历枚举获取匹配的值*/
for (Status value : values) {
if (Objects.equals(code, value.code)) {
resultState = value.state;
break;
}
}
return resultState;
}
/**
* 根据状态值获取code
*
*/
public static Integer getCodeByState(String state) {
Integer resultState = null;
/**获取当前枚举类中所有的枚举*/
Status[] values = Status.values();
/**遍历枚举获取匹配的值*/
for (Status value : values) {
if (Objects.equals(state, value.state)) {
resultState = value.code;
break;
}
}
return resultState;
}
}