|
@@ -0,0 +1,53 @@
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: XuJiakai
|
|
|
+ * 2021/8/2 17:13
|
|
|
+ */
|
|
|
+public class CompanyChangeInfo extends UDF {
|
|
|
+ private static final List<String> list = Arrays.asList("人", "代表", "经营者");
|
|
|
+
|
|
|
+ private static String getDefStr(String val) {
|
|
|
+ if (val == null) {
|
|
|
+ return "";
|
|
|
+ } else {
|
|
|
+ return val.replace("(","(").replace(")",")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String evaluate(String content_before, String content_after, String category, List<String> names) {
|
|
|
+ content_before = getDefStr(content_before);
|
|
|
+ content_after = getDefStr(content_after);
|
|
|
+ category = getDefStr(category);
|
|
|
+ if (names == null) {
|
|
|
+ names = Collections.emptyList();
|
|
|
+ }
|
|
|
+ Map<String, Object> map = new HashMap<>(2);
|
|
|
+ String finalContent_after = content_after;
|
|
|
+ String finalContent_before = content_before;
|
|
|
+ List<HashMap<String, String>> collect = names.stream().filter(r -> {
|
|
|
+ String name = r.split("@@")[1];
|
|
|
+ return finalContent_after.contains(name) || finalContent_before.contains(name);
|
|
|
+ }).map(r -> {
|
|
|
+ String keyno = r.split("@@")[0];
|
|
|
+ String name = r.split("@@")[1].replace("(","(").replace(")",")");
|
|
|
+ HashMap<String, String> stringStringHashMap = new HashMap<>(2);
|
|
|
+ stringStringHashMap.put("keyno", keyno);
|
|
|
+ stringStringHashMap.put("name", name);
|
|
|
+ return stringStringHashMap;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (collect == null || collect.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ map.put("entity", collect);
|
|
|
+ return JSONObject.toJSONString(map, SerializerFeature.WriteMapNullValue);
|
|
|
+ }
|
|
|
+}
|