xufei 2 роки тому
батько
коміт
656cd385bb

+ 38 - 0
src/main/java/com/winhc/bigdata/udf/get_eq_name.java

@@ -0,0 +1,38 @@
+package com.winhc.bigdata.udf;
+
+import com.alibaba.fastjson.JSON;
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author: π
+ * 2022/2/11 16:57
+ * @describle: 获取相同key的value
+ */
+public class get_eq_name extends UDF {
+    public String evaluate(String json, String id) {
+        if (StringUtils.isBlank(json) || "[]".equals(json) || StringUtils.isBlank(id)) {
+            return null;
+        }
+        List<Map> list = JSON.parseArray(json, Map.class);
+        for (Map s : list) {
+            String name1 = (String) s.getOrDefault("name", "");
+            String litigant_id1 = (String) s.getOrDefault("litigant_id", "");
+            if (StringUtils.isNotBlank(litigant_id1) && StringUtils.isNotBlank(name1) && litigant_id1.equals(id)) {
+                return name1;
+            }
+        }
+        return null;
+    }
+
+    public static void main(String[] args) {
+        get_eq_name g = new get_eq_name();
+        String json = "[{\"name\":\"北京神州汽车租赁有限公司\",\"litigant_id\":\"3cfbd0eee545602690de455d7c82a51b\"},{\"name\":\"中国人民财产保险股份有限公司北京市分公司\",\"litigant_id\":\"2a7de5114c7980ab0dbaa163c2350394\"}]";
+        String id = "2a7de5114c7980ab0dbaa163c2350394";
+        System.out.println(g.evaluate(json,id));
+    }
+}

+ 42 - 0
src/main/java/com/winhc/bigdata/udf/lawyer_list.java

@@ -0,0 +1,42 @@
+package com.winhc.bigdata.udf;
+
+import com.alibaba.fastjson.JSON;
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * @author: π
+ * 2021/8/30 16:57
+ */
+public class lawyer_list extends UDF {
+    public List<String> evaluate(String json) {
+        if (StringUtils.isBlank(json) || "[]".equals(json)) return null;
+        List<Map> list1 = JSON.parseArray(json, Map.class);
+        Set<String> set = list1.stream().map(x -> {
+            String lawyer_name = (String) x.getOrDefault("lawyer_name", "");
+            String lawfirm_name = (String) x.getOrDefault("lawfirm_name", "");
+            if (StringUtils.isNotBlank(lawyer_name) && StringUtils.isNotBlank(lawfirm_name)) {
+                return lawyer_name + "@@" + lawfirm_name;
+            }
+            return null;
+        }).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
+        if (set.isEmpty()) return null;
+        return new ArrayList<>(set);
+    }
+
+    public static void main(String[] args) {
+        lawyer_list j = new lawyer_list();
+        String js = "[{\"lawyer_name\": \"柴昕\", \"lawfirm_name\": \"湖南人和(东莞)律师事务所\"}, {\"lawyer_name\": \"王丹\", \"lawfirm_name\": \"湖南人和(东莞)律师事务所\"}]";
+        //String js = "";
+        List<String> evaluate = j.evaluate(js);
+        System.out.println(evaluate);
+        evaluate.stream().forEach(x->{
+            String[] arr = x.split("@@");
+            System.out.println(Arrays.toString(arr));
+        });
+    }
+
+}