fuliqi
2024-11-14 5533880a277aa5dd75c1794f7f5fa4426ea41d6e
ycl-common/src/main/java/enumeration/ErrorType.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -71,14 +72,29 @@
    }
    // 根据value获取desc
    public static List<String> getDescriptionList() {
        List<String> list = new ArrayList<>();
        for (ErrorType errorType : ErrorType.values()) {
            list.add(errorType.getDesc());
        }
        return list;
    }
    // 根据value获取desc
    public static String getDescriptionByValue(String value) {
        for (ErrorType errorType : ErrorType.values()) {
            if (errorType.getValue().equals(value)) {
                return errorType.getDesc();
            }
        }
        // 如果没有找到匹配的value,返回null或者抛出一个异常
        // 这里返回null
        return null;
    }
    // 根据desc获取value
    public static String getValueByDescription(String desc) {
        for (ErrorType errorType : ErrorType.values()) {
            if (errorType.getDesc().equals(desc)) {
                return errorType.getValue();
            }
        }
        return null;
    }
}