|
@@ -0,0 +1,73 @@
|
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
|
+import com.aliyun.odps.utils.StringUtils;
|
|
|
|
+import com.google.common.collect.ImmutableMap;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.function.Function;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author: π
|
|
|
|
+ * 2021/8/17 16:57
|
|
|
|
+ * 注入称谓title
|
|
|
|
+ */
|
|
|
|
+public class merge_title extends UDF {
|
|
|
|
+ private static final String empty = "[]";
|
|
|
|
+ private static final Map<String, String> maping = ImmutableMap.of("0", "原告", "1", "被告");
|
|
|
|
+
|
|
|
|
+ public String evaluate(String name, String party_title, String flag, String case_no) {
|
|
|
|
+ if (StringUtils.isBlank(name)) return empty;
|
|
|
|
+ List<Map> list1 = JSON.parseArray(name, Map.class);
|
|
|
|
+ if (list1.isEmpty()) return empty;
|
|
|
|
+ List<Map> list2 = new ArrayList<>();
|
|
|
|
+ Map<Object, Map> m1 = new HashMap<>();
|
|
|
|
+ if (StringUtils.isNotBlank(party_title)) {
|
|
|
|
+ m1 = JSON.parseArray(party_title, Map.class).stream().collect(Collectors.toMap(x -> x.getOrDefault("name", ""), a -> a, (k1, k2) -> k1));
|
|
|
|
+ }
|
|
|
|
+ String defult_title = getTitle(flag, case_no);
|
|
|
|
+ for (Map s : list1) {
|
|
|
|
+ Object name1 = s.getOrDefault("name", "");
|
|
|
|
+ Object litigant_id1 = s.getOrDefault("litigant_id", "");
|
|
|
|
+ Object title = m1.getOrDefault(name1, new HashMap()).getOrDefault("party_title", defult_title);
|
|
|
|
+ list2.add(ImmutableMap.of("name", name1, "litigant_id", litigant_id1, "party_title", title));
|
|
|
|
+ }
|
|
|
|
+ return JSON.toJSONString(list2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String getTitle(String flag, String case_no) {
|
|
|
|
+ if (StringUtils.isBlank(case_no)) return maping.get(flag);
|
|
|
|
+ if (case_no.contains("执")) {
|
|
|
|
+ return "申请执行人、被执行人";
|
|
|
|
+ } else if (case_no.contains("刑初")) {
|
|
|
|
+ return "被告";
|
|
|
|
+ } else if (case_no.contains("终")) {
|
|
|
|
+ return "上诉人、被上诉人";
|
|
|
|
+ } else if (case_no.contains("民申")) {
|
|
|
|
+ return "再审申请人、被申请人";
|
|
|
|
+ } else if (case_no.contains("行终")) {
|
|
|
|
+ return "上诉人、被上诉人";
|
|
|
|
+ } else if (case_no.contains("财保")) {
|
|
|
|
+ return "申请人、被申请人";
|
|
|
|
+ }
|
|
|
|
+ return maping.get(flag);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ String name = "[{\"name\":\"n11\",\"litigant_id\":\"p11\"},{\"name\":\"n21\",\"litigant_id\":\"p22\"},{\"name\":\"n33\",\"litigant_id\":\"p33\"}]";
|
|
|
|
+ //String name = null;
|
|
|
|
+ //String party_title = "[{\"name\":\"n11\",\"litigant_id\":\"p22\",\"party_title\":\"一审原告\"},{\"name\":\"n21\",\"litigant_id\":\"p22\",\"party_title\":\"第三人\"}]";
|
|
|
|
+ String party_title = null;
|
|
|
|
+ String flag = "1";
|
|
|
|
+ String case_no = "(2020)粤1302民初16042号";
|
|
|
|
+ merge_title m = new merge_title();
|
|
|
|
+ System.out.println(m.evaluate(name, party_title, flag, case_no));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|