|
@@ -0,0 +1,39 @@
|
|
|
+package com.winhc.bigdata.udf;
|
|
|
+
|
|
|
+import com.aliyun.odps.udf.UDF;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+
|
|
|
+import java.util.function.Predicate;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author ZhangJi
|
|
|
+ * @since 2022-08-12 09:23
|
|
|
+ */
|
|
|
+public class get_adcode_from_reg_credit extends UDF {
|
|
|
+ public String evaluate(String reg_number, String credit_code) {
|
|
|
+ if (legalString(reg_number, 15)) {
|
|
|
+ String substring = reg_number.substring(0, 6);
|
|
|
+ if (StringUtils.isNumeric(substring)) {
|
|
|
+ return substring;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (legalString(credit_code, 18, code -> code.startsWith("9"))) {
|
|
|
+ String substring = credit_code.substring(2, 8);
|
|
|
+ if (StringUtils.isNumeric(substring)) {
|
|
|
+ return substring;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean legalString(String code, int len) {
|
|
|
+ return legalString(code, len, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean legalString(String code, int len, Predicate<String> predicate) {
|
|
|
+ if (StringUtils.isEmpty(code)) return false;
|
|
|
+ if (code.length() != len) return false;
|
|
|
+ if (predicate != null) return predicate.test(code);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|