Browse Source

feat: 添加身份证号提取、注册资本提取

许家凯 4 years ago
parent
commit
8bb16b840c

+ 29 - 0
src/main/java/com/winhc/bigdata/udf/IDCardTrim.java

@@ -0,0 +1,29 @@
+package com.winhc.bigdata.udf;
+
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @Author: XuJiakai
+ * @Date: 2020/10/14 17:19
+ * @Description:
+ */
+public class IDCardTrim extends UDF {
+    private static final Pattern pattern = Pattern.compile("^[1-9]\\d{5}(19|20)\\d{2}((0[1-9])|(1[0-2])|([0-1]\\*{1,2})|\\*{2})(([0-2][1-9])|10|20|30|31|\\*{2})\\d{3}[0-9Xx]$");
+
+
+    public String evaluate(String val) {
+        if (StringUtils.isEmpty(val)) {
+            return null;
+        }
+        Matcher matcher = pattern.matcher(val);
+        if (matcher.find()) {
+            return val.substring(0, 10) + "****" + val.substring(val.length() - 4).toUpperCase();
+        } else {
+            return null;
+        }
+    }
+}

+ 48 - 0
src/main/java/com/winhc/bigdata/udf/RegisteredCapitalTrim.java

@@ -0,0 +1,48 @@
+package com.winhc.bigdata.udf;
+
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author: XuJiakai
+ * 2020/11/2 10:16
+ * 注册资本提取
+ */
+public class RegisteredCapitalTrim extends UDF {
+    private static boolean isDouble(String val) {
+        try {
+            Double.parseDouble(val);
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    private static final Pattern pattern = Pattern.compile("[^0-9.]");
+
+
+    public String evaluate(String val) {
+        if (StringUtils.isEmpty(val)) {
+            return null;
+        }
+        if (val.contains("%")) {
+            return null;
+        }
+        Matcher matcher = pattern.matcher(val);
+        try {
+            String a = matcher.replaceAll(" ").split("\\s+")[0];
+            return StringUtils.isNotBlank(a) ? isDouble(a) ? a : null : null;
+        } catch (ArrayIndexOutOfBoundsException exception) {
+            return null;
+        }
+    }
+
+    public static void main(String[] args) {
+        String a = new RegisteredCapitalTrim().evaluate("50万元人民币");
+        System.out.println(a);
+    }
+
+}