|
@@ -0,0 +1,53 @@
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
+
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.winhc.bigdata.bean.EquityInfo;
|
|
|
+import com.winhc.bigdata.bean.Pledgee;
|
|
|
+import com.winhc.bigdata.bean.Pledgor;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: XuJiakai
|
|
|
+ * 2021/3/12 14:57
|
|
|
+ */
|
|
|
+public class EquityInfoUdf extends UDF {
|
|
|
+ public String evaluate(String type, Map<String, String> map, String value) {
|
|
|
+ if (map == null) {
|
|
|
+ map = new HashMap<>();
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(value)) {
|
|
|
+ return get_json(new ArrayList<>(), map);
|
|
|
+ }
|
|
|
+ if ("pledgee".equals(type)) {
|
|
|
+ List<EquityInfo> collect = Arrays.stream(value.split("[,,、]")).map(Pledgee::new).collect(Collectors.toList());
|
|
|
+ return get_json(collect, map);
|
|
|
+ }
|
|
|
+ if ("pledgor".equals(type)) {
|
|
|
+ List<EquityInfo> collect = Arrays.stream(value.split("[,,、]")).map(Pledgor::new).collect(Collectors.toList());
|
|
|
+ return get_json(collect, map);
|
|
|
+ }
|
|
|
+ throw new RuntimeException("type is not found!");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String get_json(List<EquityInfo> list, Map<String, String> map) {
|
|
|
+ List<EquityInfo> collect = list.stream().peek(equityInfo -> {
|
|
|
+ String name = equityInfo.getName();
|
|
|
+ String orDefault = map.getOrDefault(name, null);
|
|
|
+ equityInfo.setId(orDefault);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return new Gson().toJson(collect);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("abc", "123");
|
|
|
+ map.put("a", "456");
|
|
|
+ String pledgee = new EquityInfoUdf().evaluate("pledgee", null, "a,{\"{b,c");
|
|
|
+ System.out.println(pledgee);
|
|
|
+ }
|
|
|
+}
|