Explorar el Código

Merge remote-tracking branch 'origin/master'

许家凯 hace 2 años
padre
commit
7c15c6a028

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2760 - 0
src/main/java/com/winhc/bigdata/udf/ComputeAdCode.java


+ 43 - 0
src/main/java/com/winhc/bigdata/udf/ComputeLostNum.java

@@ -0,0 +1,43 @@
+package com.winhc.bigdata.udf;
+
+import com.aliyun.odps.udf.UDF;
+import com.google.common.collect.Lists;
+
+import java.time.LocalDate;
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+/**
+ * @author ZhangJi
+ * @since 2022-06-30 13:26
+ */
+public class ComputeLostNum extends UDF {
+    private static final Pattern NUM_4 = Pattern.compile("^\\d{4}$");
+    private static final int CURRENT_MONTH = LocalDate.now().getMonthValue();
+
+    public List<String> evaluate(List<String> arr, Integer max) {
+        max -= 1;
+        if (arr == null || arr.size() == 0) {
+            return Collections.singletonList(String.valueOf(max));
+        }
+        int min = arr
+                .stream()
+                .filter(s -> NUM_4.matcher(s).matches())
+                .mapToInt(Integer::parseInt)
+                .min().orElse(max);
+        if (min >= max) return null;
+        Set<String> sets = new HashSet<>(arr);
+        List<String> result = IntStream.range(min, max + 1)
+                .mapToObj(String::valueOf)
+                .filter(s -> !sets.contains(s))
+                .collect(Collectors.toList());
+        if (result.isEmpty()) return null;
+        return result;
+    }
+
+    public static void main(String[] args) {
+        System.out.println(new ComputeLostNum().evaluate(Lists.asList("2012", new String[]{"2018", "2019", "2020"}), 2022));
+    }
+}

+ 39 - 0
src/main/java/com/winhc/bigdata/udf/get_adcode_from_reg_credit.java

@@ -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;
+    }
+}