You've already forked FrameTour-BE
72 lines
1.5 KiB
Java
72 lines
1.5 KiB
Java
package com.ycwl.basic.constant;
|
|
|
|
/**
|
|
* 免费状态枚举
|
|
* 定义源文件的收费和免费两种状态
|
|
*
|
|
* @author Claude
|
|
* @since 2025-10-31
|
|
*/
|
|
public enum FreeStatus {
|
|
/**
|
|
* 收费状态
|
|
*/
|
|
PAID(0, "收费"),
|
|
|
|
/**
|
|
* 免费状态
|
|
*/
|
|
FREE(1, "免费");
|
|
|
|
private final int code;
|
|
private final String description;
|
|
|
|
FreeStatus(int code, String description) {
|
|
this.code = code;
|
|
this.description = description;
|
|
}
|
|
|
|
public int getCode() {
|
|
return code;
|
|
}
|
|
|
|
public String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
/**
|
|
* 根据代码值获取枚举
|
|
*
|
|
* @param code 状态代码
|
|
* @return 对应的枚举值,如果不存在返回 null
|
|
*/
|
|
public static FreeStatus fromCode(int code) {
|
|
for (FreeStatus status : values()) {
|
|
if (status.code == code) {
|
|
return status;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 判断给定的代码是否为免费状态
|
|
*
|
|
* @param code 状态代码
|
|
* @return true-免费,false-收费
|
|
*/
|
|
public static boolean isFree(Integer code) {
|
|
return code != null && code == FREE.code;
|
|
}
|
|
|
|
/**
|
|
* 判断给定的代码是否为收费状态
|
|
*
|
|
* @param code 状态代码
|
|
* @return true-收费,false-免费
|
|
*/
|
|
public static boolean isPaid(Integer code) {
|
|
return code != null && code == PAID.code;
|
|
}
|
|
}
|