fuliqi
2024-11-14 e9af9f5cfeddbe5c0b33a3060b8ea6364c51e744
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;
@@ -69,4 +70,31 @@
                .filter(errorType -> errorType.getCategory() == category)
                .collect(Collectors.toList());
    }
    // 根据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();
            }
        }
        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;
    }
}