|
@@ -1,7 +1,9 @@
|
|
|
package com.winhc.bigdata.bean;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author: XuJiakai
|
|
@@ -464,6 +466,31 @@ public class Category {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ public static final Map<String, String> CATEGORY_CODE_FIRST_MAP = CATEGORY_MAP.entrySet().stream()
|
|
|
+ .map(x -> Arrays.asList(x.getValue().cateFirstCode, x.getValue().cateFirst))
|
|
|
+ .distinct().collect(Collectors.toMap(t -> t.get(0), t -> t.get(1), (n, o) -> n));
|
|
|
+
|
|
|
+ public static final Map<String, String> CATEGORY_CODE_SECOND_MAP = CATEGORY_MAP.entrySet().stream()
|
|
|
+ .map(x -> Arrays.asList(x.getValue().cateSecondCode, x.getValue().cateSecond))
|
|
|
+ .distinct().collect(Collectors.toMap(t -> t.get(0), t -> t.get(1), (n, o) -> n));
|
|
|
+
|
|
|
+ public static final Map<String, String> CATEGORY_CODE_THIRD_MAP = CATEGORY_MAP.entrySet().stream()
|
|
|
+ .map(x -> Arrays.asList(x.getValue().cateThirdCode, x.getValue().cateThird))
|
|
|
+ .distinct().collect(Collectors.toMap(t -> t.get(0), t -> t.get(1), (n, o) -> n));
|
|
|
+
|
|
|
+ public static String getCategoryCode2Name(String code, String index) {
|
|
|
+ switch (index) {
|
|
|
+ case "1":
|
|
|
+ return CATEGORY_CODE_FIRST_MAP.getOrDefault(code,"");
|
|
|
+ case "2":
|
|
|
+ return CATEGORY_CODE_SECOND_MAP.getOrDefault(code,"");
|
|
|
+ case "3":
|
|
|
+ return CATEGORY_CODE_THIRD_MAP.getOrDefault(code,"");
|
|
|
+ default:
|
|
|
+ throw new RuntimeException("不支持的索引,[1,2,3]");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static String getCategoryCode(String code, String index) {
|
|
|
Category category = Category.CATEGORY_MAP.getOrDefault(code, null);
|
|
|
if (category == null) {
|
|
@@ -522,6 +549,8 @@ public class Category {
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
- System.out.println(getCategoryName("28","1"));
|
|
|
+ System.out.println(getCategoryCode2Name("28", "1"));
|
|
|
+ System.out.println(getCategoryCode2Name("63", "2"));
|
|
|
+ System.out.println(getCategoryCode2Name("454", "3"));
|
|
|
}
|
|
|
}
|