xufei 2 년 전
부모
커밋
1fcd8ec891
1개의 변경된 파일59개의 추가작업 그리고 0개의 파일을 삭제
  1. 59 0
      src/main/java/com/winhc/bigdata/udf/num_pro.java

+ 59 - 0
src/main/java/com/winhc/bigdata/udf/num_pro.java

@@ -0,0 +1,59 @@
+package com.winhc.bigdata.udf;
+
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @Author: π
+ * @Description: 统一信用代码或者工商注册号 转省 市区code
+ * 1、优先用统一代码,如果统一代码长度为18位,省市区依次为3-8
+ * eg:9111010831813798XE
+ * province_code:11
+ * city_code:01
+ * county_code:08
+ * 2、如果统一代码为空或者不符合长度为18位,则取注册号,并且注册号长度必须为15,省市区依次为1-6
+ * eg:110108018092129
+ * province_code:11
+ * city_code:01
+ * county_code:08
+ * 3、如果都没有,或者长度都不符合要求,则置为空
+ */
+public class num_pro extends UDF {
+
+
+    public List<String> evaluate(String credit_code, String reg_number) {
+        if (StringUtils.isBlank(reg_number) && StringUtils.isBlank(credit_code)) {
+            return null;
+        }
+        if (StringUtils.isNotBlank(credit_code) && credit_code.length() == 18) {
+            String p = credit_code.substring(2, 4);
+            String c = credit_code.substring(4, 6);
+            String d = credit_code.substring(6, 8);
+            return Arrays.asList(p, c, d);
+        }
+        if (StringUtils.isNotBlank(reg_number) && reg_number.length() == 15) {
+            String p = reg_number.substring(0, 2);
+            String c = reg_number.substring(2, 4);
+            String d = reg_number.substring(4, 6);
+            return Arrays.asList(p, c, d);
+        }
+
+        return null;
+    }
+
+
+    public static void main(String[] args) {
+        num_pro n = new num_pro();
+        System.out.println(n.evaluate("91110108551385082Q", "110108012660422"));
+        System.out.println(n.evaluate(null, "110108012660422"));
+        System.out.println(n.evaluate(null, null));
+        System.out.println(n.evaluate("91110108551385082Q", null));
+        System.out.println(n.evaluate("9111010855138508221", null));
+    }
+
+}
+
+