xiangpei
2025-02-14 c5dafd7dba14635643b4340597fb14c563c8dc7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.ycl.common.enums.business;
 
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;
 
/**
 * 项目类型枚举
 *
 * @author:flq
 * @date:2024/11/27 18:21
 */
@Getter
public enum ProjectTypeEnum {
    HOUSE("house", "房屋建筑"),
    CITY("city","城市基础设施"),
    TRANSPORT("transport","交通运输"),
    WATER("water", "水利"),
    ENERGY("energy", "能源"),
    NON_COAL_MINE("non_coal_mine", "非煤矿山");
 
    @EnumValue // 标明该字段存入数据库
    private final String type;
 
    @JsonValue // 标明在转JSON时使用该字段
    private final String desc;
 
    ProjectTypeEnum(String type, String desc) {
        this.type = type;
        this.desc = desc;
    }
 
    public static String getDescByType(String type) {
        for (ProjectTypeEnum projectType : ProjectTypeEnum.values()) {
            if (projectType.type.equals(type)) {
                return projectType.desc;
            }
        }
        return null; // 如果没有找到对应的type,可以返回null或抛出异常
    }
}