Browse Source

feat: 添加统一信用代码,工商注册号校验函数

- credit_code_verify
- reg_number_verify
许家凯 2 years ago
parent
commit
ebc1ecdeeb

+ 18 - 0
src/main/java/com/winhc/bigdata/udf/company/CreditCodeVerify.java

@@ -0,0 +1,18 @@
+package com.winhc.bigdata.udf.company;
+
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+/**
+ * @author: XuJiakai
+ * 2022/7/26 17:34
+ */
+public class CreditCodeVerify extends UDF {
+    /**
+     * @param val
+     * @return true 合法
+     */
+    public boolean evaluate(String val) {
+        return StringUtils.isNotBlank(val) && val.length() == 18 && val.charAt(0) == '9';
+    }
+}

+ 28 - 0
src/main/java/com/winhc/bigdata/udf/company/RegNumberVerify.java

@@ -0,0 +1,28 @@
+package com.winhc.bigdata.udf.company;
+
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+/**
+ * @author: XuJiakai
+ * 2022/7/26 17:36
+ */
+public class RegNumberVerify extends UDF {
+
+    private static boolean isNumber(String val) {
+        try {
+            Double.parseDouble(val);
+            return true;
+        } catch (Exception e) {
+            return false;
+        }
+    }
+
+    /**
+     * @param val
+     * @return true 合法
+     */
+    public boolean evaluate(String val) {
+        return StringUtils.isNotBlank(val) && val.length() == 15 && isNumber(val.substring(0, 6));
+    }
+}