1

用枚举来实现 1=部件,2=热线

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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* 几种匹配类型的枚举值
*/
public enum ConversionType {

/**
* 部件匹配类型
*/
BJ(1,"部件"),

/**
* 热线匹配类型
*/

RX(2,"热线");


int conversionTypeInt = 1;
String conversionTypeStr = "热线";

ConversionType(int conversionTypeInt,String ConversionTypeStr ){
this.conversionTypeInt = conversionTypeInt;
this.conversionTypeStr = ConversionTypeStr;

}
/**
* 根据 1 或者 2 两个整数得到枚举类
* @param conversionTypeInt
* @return
*/
public static ConversionType getConversionType(int conversionTypeInt){
ConversionType[] values = ConversionType.values();
for (ConversionType value : values) {
if(value.conversionTypeInt == conversionTypeInt){
return value;
}
}
throw new RuntimeException("枚举类型错误,匹配逻辑只有两种类型,一个1为部件,一个2为事件,没别的");
}

/**
* 根据"热线"或者"部件" 两个汉字得到枚举类
* @param ConversionTypeStr
* @return
*/
public static ConversionType getConversionType(String ConversionTypeStr){
ConversionType[] values = ConversionType.values();
for (ConversionType value : values) {
if(value.conversionTypeStr == ConversionTypeStr){
return value;
}
}
throw new RuntimeException("枚举类型错误,匹配逻辑只有两种类型,一个1为部件,一个2为事件,没别的");
}

/**
* 根据1或者2得到是"热线"或者"部件",
* 或者根据"热线","部件"得到对应的1或者2
* @param conversionTypeInt
* @return
*/
public static String getConversionTypeVal(int conversionTypeInt){
ConversionType[] values = ConversionType.values();
for (ConversionType value : values) {
if(value.conversionTypeInt == conversionTypeInt){
return value.conversionTypeStr;
}
}
throw new RuntimeException("枚举类型错误,匹配逻辑只有两种类型,一个1为部件,一个2为事件,没别的");
}

public static int getConversionTypeVal(String conversionTypeStr){
ConversionType[] values = ConversionType.values();
for (ConversionType value : values) {
if(value.conversionTypeStr == conversionTypeStr){
return value.conversionTypeInt;
}
}
throw new RuntimeException("枚举类型错误,匹配逻辑只有两种类型,一个1为部件,一个2为事件,没别的");
}
}