Quellcode durchsuchen

feat: 添加注册资本格式化函数

许家凯 vor 2 Jahren
Ursprung
Commit
65a281eab1

+ 4 - 0
src/main/java/com/winhc/bigdata/bean/Category.java

@@ -548,6 +548,10 @@ public class Category {
     }
 
 
+    public String getAllCateCode() {
+        return cateFirstCode + "|" + cateSecondCode + "|" + cateThirdCode;
+    }
+
     public static void main(String[] args) {
         System.out.println(getCategoryCode2Name("28", "1"));
         System.out.println(getCategoryCode2Name("63", "2"));

+ 40 - 0
src/main/java/com/winhc/bigdata/udf/etl/RegisteredCapitalFormat.java

@@ -0,0 +1,40 @@
+package com.winhc.bigdata.udf.etl;
+
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+import java.text.DecimalFormat;
+import java.util.regex.Pattern;
+
+/**
+ * @author: XuJiakai
+ * 2022/2/15 09:20
+ * 注册资本格式化
+ * Ps. 800.000000万元 -> 800万元
+ */
+public class RegisteredCapitalFormat extends UDF {
+    private static final Pattern pattern = Pattern.compile("[^\\x00-\\x7F]+");
+    DecimalFormat decimalFormat = new DecimalFormat("0.###########");
+
+    public String evaluate(String content) {
+        if (StringUtils.isBlank(content)) {
+            return null;
+        }
+        try {
+            String prefix = pattern.matcher(content).replaceAll("");
+            String unit = content.replace(prefix, "");
+            double v = Double.parseDouble(prefix);
+            return decimalFormat.format(v) + unit;
+        } catch (Exception e) {
+            return content;
+        }
+    }
+
+    public static void main(String[] args) {
+        RegisteredCapitalFormat registeredCapitalFormat = new RegisteredCapitalFormat();
+        String evaluate = registeredCapitalFormat.evaluate("0.00000美元");
+        System.out.println(evaluate);
+    }
+}
+
+