|
@@ -0,0 +1,53 @@
|
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONPath;
|
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
+
|
|
|
|
+import java.util.*;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Author: π
|
|
|
|
+ * @Date: 2020/5/14 16:26
|
|
|
|
+ * @Description: 比较两个字符串数组包含关系
|
|
|
|
+ */
|
|
|
|
+public class CompareName extends UDF {
|
|
|
|
+
|
|
|
|
+ public Boolean evaluate(String ygName, String bgName) {
|
|
|
|
+ if (StringUtils.isBlank(ygName) || StringUtils.isBlank(bgName)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ //原告
|
|
|
|
+ List<String> list1 = parse(ygName, "$.name").stream().distinct().collect(Collectors.toList());
|
|
|
|
+ //被告
|
|
|
|
+ List<String> list2 = Arrays.stream(bgName.split(",", -1))
|
|
|
|
+ .filter(StringUtils::isNotBlank).distinct().collect(Collectors.toList());
|
|
|
|
+ if (list1.isEmpty() || list2.isEmpty()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ List<String> intersection = list1.stream().filter(list2::contains).collect(Collectors.toList());
|
|
|
|
+ return !intersection.isEmpty();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<String> parse(String json, String json_path) {
|
|
|
|
+ JSONArray jsonArray = ((JSONArray) JSONPath.eval(JSON.parse(json), json_path));
|
|
|
|
+ ArrayList<String> list = new ArrayList<>();
|
|
|
|
+ for (Object o : jsonArray) {
|
|
|
|
+ list.add((String) o);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+
|
|
|
|
+ String yg_name = "[{\"name\":\"张司\",\"litigant_id\":\"4aed1cb57bf538d0aca90ec8b2c9f8bc\"}]";
|
|
|
|
+ String bg_name = "张司,,李四";
|
|
|
|
+ CompareName c = new CompareName();
|
|
|
|
+ System.out.println(c.evaluate(yg_name, bg_name));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|