瀏覽代碼

feat: amount_format

许家凯 2 年之前
父節點
當前提交
eeca233cb7

+ 27 - 0
src/main/java/com/winhc/bigdata/udf/etl/AmountFormat.java

@@ -0,0 +1,27 @@
+package com.winhc.bigdata.udf.etl;
+
+import com.aliyun.odps.udf.UDF;
+import com.aliyun.odps.utils.StringUtils;
+
+import java.text.DecimalFormat;
+
+/**
+ * @author: XuJiakai
+ * 2022/3/18 15:21
+ * amount_format
+ */
+public class AmountFormat extends UDF {
+    private static final DecimalFormat df = new DecimalFormat("00.00");
+
+    public String evaluate(String content) {
+        if (StringUtils.isBlank(content)) {
+            return null;
+        }
+        try {
+            double v = Double.parseDouble(content);
+            return df.format(v);
+        } catch (Exception e) {
+            return content;
+        }
+    }
+}

+ 66 - 0
src/test/java/com/winhc/bigdata/bean/AreaCodeTreeVo.java

@@ -0,0 +1,66 @@
+package com.winhc.bigdata.bean;
+
+
+import java.util.List;
+
+/**
+ * @author: XuJiakai
+ * 2022/1/19 10:21
+ */
+public class AreaCodeTreeVo {
+    private String label;
+    private String value;
+
+    private List<AreaCodeTreeVo> children;
+
+    public AreaCodeTreeVo(String label, String value) {
+        this.label = label;
+        this.value = value;
+    }
+
+    public AreaCodeTreeVo(String label, String value, List<AreaCodeTreeVo> children) {
+        this.label = label;
+        this.value = value;
+        this.children = children;
+    }
+
+
+    @Override
+    public String toString() {
+        if (children == null) {
+            return "{" +
+                    "\"label\":\"" + label + "\"," +
+                    "\"value\":\"" + value + "\"" +
+                    '}';
+        } else
+            return "{" +
+                    "\"label\":\"" + label + "\"," +
+                    "\"value\":\"" + value + "\"," +
+                    "\"children\":" + children.toString() + "" +
+                    '}';
+    }
+
+    public String getLabel() {
+        return label;
+    }
+
+    public void setLabel(String label) {
+        this.label = label;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+    public List<AreaCodeTreeVo> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<AreaCodeTreeVo> children) {
+        this.children = children;
+    }
+}

+ 40 - 0
src/test/java/com/winhc/bigdata/bean/CategoryTest.java

@@ -0,0 +1,40 @@
+package com.winhc.bigdata.bean;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.*;
+
+public class CategoryTest {
+
+
+    public static void main(String[] args) {
+
+        Map<String, List<Category>> collect = Category.CATEGORY_MAP.values().stream().collect(Collectors.groupingBy(r -> r.getCateFirstCode() + "|" + r.getCateSecondCode() + " " + r.getCateFirst() + " " + r.getCateSecond()));
+
+
+        List<AreaCodeTreeVo> collect2 = collect.entrySet().stream()
+                .map(r -> {
+                    String[] s = r.getKey().split(" ");
+                    List<AreaCodeTreeVo> treeVos = r.getValue().stream().map(rr -> new AreaCodeTreeVo(rr.getCateThird(), rr.getAllCateCode())).collect(Collectors.toList());
+                    return new EntryVo<String, AreaCodeTreeVo>(s[0].split("\\|")[0] + " " + s[1], new AreaCodeTreeVo(s[2], s[0], treeVos));
+                }).collect(Collectors.groupingBy(EntryVo::getKey))
+                .entrySet()
+                .stream()
+                .map(r -> {
+                    String[] s = r.getKey().split(" ");
+                    List<EntryVo<String, AreaCodeTreeVo>> value = r.getValue();
+                    List<AreaCodeTreeVo> collect1 = value.stream().map(EntryVo::getValue).collect(Collectors.toList());
+                    return new AreaCodeTreeVo(s[1], s[0], collect1);
+                }).collect(Collectors.toList());
+
+
+        System.out.println(collect2);
+
+
+
+
+    }
+
+}

+ 34 - 0
src/test/java/com/winhc/bigdata/bean/EntryVo.java

@@ -0,0 +1,34 @@
+package com.winhc.bigdata.bean;
+
+/**
+ * @author: XuJiakai
+ * 2022/1/19 10:37
+ */
+public class EntryVo<K, V> {
+    private K key;
+    private V value;
+
+    public EntryVo() {
+    }
+
+    public EntryVo(K key, V value) {
+        this.key = key;
+        this.value = value;
+    }
+
+    public K getKey() {
+        return key;
+    }
+
+    public void setKey(K key) {
+        this.key = key;
+    }
+
+    public V getValue() {
+        return value;
+    }
+
+    public void setValue(V value) {
+        this.value = value;
+    }
+}