package jnpf.tmsEntity.enums;
|
|
/**
|
* TMS 业务字典枚举约定。
|
* <p>
|
* 库字段与前端字典 {@code enCode} 统一存 {@link #getCode()};
|
* 业务比较请用 {@link #equalsCode(String)} / {@link #of(Class, String)},避免散落魔法字符串。
|
* </p>
|
*/
|
public interface TmsDictEnum {
|
|
/** 字典/库字段编码(与 base_dictionary_data.f_en_code 一致) */
|
String getCode();
|
|
/** 中文说明(便于日志与注释,非强制对外展示) */
|
String getLabel();
|
|
/** 是否与给定编码相等 */
|
default boolean equalsCode(String code) {
|
return getCode() != null && getCode().equals(code);
|
}
|
|
/** 是否与给定编码相等(忽略大小写,兼容历史脏数据) */
|
default boolean equalsCodeIgnoreCase(String code) {
|
return getCode() != null && code != null && getCode().equalsIgnoreCase(code.trim());
|
}
|
|
/** 按编码解析;空或不识别返回 null */
|
static <E extends Enum<E> & TmsDictEnum> E of(Class<E> type, String code) {
|
if (code == null || code.isEmpty() || type == null) {
|
return null;
|
}
|
for (E e : type.getEnumConstants()) {
|
if (e.equalsCode(code)) {
|
return e;
|
}
|
}
|
return null;
|
}
|
|
/** 编码是否命中任一枚举值 */
|
@SafeVarargs
|
static <E extends Enum<E> & TmsDictEnum> boolean equalsAny(String code, E... values) {
|
if (code == null || values == null) {
|
return false;
|
}
|
for (E e : values) {
|
if (e != null && e.equalsCode(code)) {
|
return true;
|
}
|
}
|
return false;
|
}
|
}
|