liurunyu
2023-11-27 478ae07891f64484d8a483e15821ce0bc920606f
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.dy.pipIrrGlobal.util;
 
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.dy.common.mybatis.envm.IEnum;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 行政区划级别
 * Provinces, cities, counties, towns, and village groups
 */
public enum DistrictLevel implements IEnum {
 
    Province((byte)0, "省"),
    City((byte)1, "市"),
    County((byte)2, "县"),
    Town((byte)3,  "镇"),
    Village((byte)4,  "村") ;
 
    @EnumValue
    public Byte code ;
    public String name ;
 
    DistrictLevel(Byte code, String name){
        this.code = code ;
        this.name = name ;
    }
 
    //用来转json
    public static Map<Byte, String> ObjMap = new HashMap<>();
    static {
        DistrictLevel[] all = DistrictLevel.values();
        for (DistrictLevel one : all) {
            ObjMap.put(one.code, one.name);
        }
    }
 
    @Override
    public Byte getCode() {
        return this.code ;
    }
 
    @Override
    public String getName() {
        return this.name ;
    }
 
    public static DistrictLevel get(Byte code){
        if(code.byteValue() == Province.code.byteValue()){
            return Province ;
        }if(code.byteValue() == City.code.byteValue()){
            return City ;
        }else if(code.byteValue() == County.code.byteValue()){
            return County ;
        }else if(code.byteValue() == Town.code.byteValue()){
            return Town ;
        }else if(code.byteValue() == Village.code.byteValue()){
            return Village ;
        }
        return null ;
    }
}