|
@@ -0,0 +1,48 @@
|
|
|
+package com.winhc.bigdata;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+import com.winhc.bigdata.utils.CompanyUtils;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author: π
|
|
|
+ * @Description: 公司名转换
|
|
|
+ */
|
|
|
+public class historyNamesTrans extends UDF {
|
|
|
+
|
|
|
+ public String evaluate(String cname, String names) {
|
|
|
+ if (StringUtils.isEmpty(names)) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ Set<String> set = new HashSet<>();
|
|
|
+ if (StringUtils.isNotBlank(names)) {
|
|
|
+ set = Arrays.stream(names.split("\t;\t")).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
|
|
|
+ }
|
|
|
+ Set<JSONObject> s = set.stream()
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .map(StringUtils::trim)
|
|
|
+ .filter(x -> !x.equals(cname))
|
|
|
+ .map(CompanyUtils::getCompanyName).collect(Collectors.toSet());
|
|
|
+ if (s.isEmpty()) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return JSONObject.toJSONString(s);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ System.out.println(new historyNamesTrans().evaluate("廣滙亞太有限公司","廣滙亞太有限公司111"));
|
|
|
+ System.out.println(new historyNamesTrans().evaluate(null,"廣滙亞太有限公司111"));
|
|
|
+ System.out.println(new historyNamesTrans().evaluate(null,""));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|