Browse Source

add table bean

许家凯 4 years ago
parent
commit
337ec3510e

+ 13 - 2
pom.xml

@@ -8,8 +8,19 @@
     <artifactId>DataWorks-flow-touch</artifactId>
     <version>0.0.1</version>
 
+
+    <properties>
+        <java.version>1.8</java.version>
+    </properties>
+
     <dependencies>
         <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.3.7</version>
+        </dependency>
+
+        <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>fastjson</artifactId>
             <version>1.2.70</version>
@@ -98,8 +109,8 @@
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <configuration>
-                    <source>7</source>
-                    <target>7</target>
+                    <source>8</source>
+                    <target>8</target>
                 </configuration>
             </plugin>
         </plugins>

+ 41 - 0
src/main/java/com/winhc/dataworks/flow/touch/bean/OdpsTableSchema.java

@@ -0,0 +1,41 @@
+package com.winhc.dataworks.flow.touch.bean;
+
+import com.winhc.dataworks.flow.touch.utils.JsonUtils;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+/**
+ * @Author: XuJiakai
+ * @Date: 2020/6/23 14:16
+ * @Description:
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+public class OdpsTableSchema {
+
+    /**
+     * 表前缀工程名,不用于业务流程调度的工程名
+     */
+    private String project;
+    /**
+     * 表名,不加任何前辍
+     */
+    private String tableName;
+    /**
+     * 有效列  逗号分割
+     */
+    private String columns;
+    /**
+     * 去重主列  逗号分割
+     */
+    private String dupliCols;
+
+    @Override
+    public String toString() {
+        return JsonUtils.jsonObjToString(this);
+    }
+}

+ 37 - 0
src/main/java/com/winhc/dataworks/flow/touch/configuration/SchemaInit.java

@@ -0,0 +1,37 @@
+package com.winhc.dataworks.flow.touch.configuration;
+
+import cn.hutool.core.bean.BeanUtil;
+import com.winhc.dataworks.flow.touch.bean.OdpsTableSchema;
+import org.yaml.snakeyaml.Yaml;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.Reader;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * @Author: XuJiakai
+ * @Date: 2020/6/23 14:23
+ * @Description:
+ */
+public class SchemaInit {
+    public static final Map<String, OdpsTableSchema> MAP;
+
+    static {
+        Yaml yml = new Yaml();
+        String path = Object.class.getResource("/").getPath().substring(1) + "odps-schema.yaml";
+        Reader reader = null;
+        try {
+            reader = new FileReader(new File(path));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        Map map1 = yml.loadAs(reader, Map.class);
+        List<Map<String, String>> tables = (List<Map<String, String>>) map1.get("table");
+        MAP = tables.stream()
+                .map(m -> BeanUtil.mapToBean(m, OdpsTableSchema.class, false))
+                .collect(Collectors.toMap(OdpsTableSchema::getTableName, o -> o, (o1, o2) -> o1));
+    }
+}

+ 2 - 10
src/main/java/com/winhc/dataworks/flow/touch/test/TestFlow.java

@@ -1,9 +1,6 @@
 package com.winhc.dataworks.flow.touch.test;
 
-import com.winhc.dataworks.flow.touch.utils.JsonUtils;
-
-import java.util.HashMap;
-import java.util.Map;
+import com.winhc.dataworks.flow.touch.configuration.SchemaInit;
 
 /**
  * @Author: XuJiakai
@@ -12,11 +9,6 @@ import java.util.Map;
  */
 public class TestFlow {
     public static void main(String[] args) {
-        Map<String, String> map = new HashMap<>();
-
-        map.put("a", "b");
-        map.put("b", "c");
-        System.out.println(JsonUtils.jsonObjToString(map));
-
+        System.out.println(SchemaInit.MAP);
     }
 }

+ 4 - 3
src/main/java/com/winhc/dataworks/flow/touch/utils/YmlUtil.java

@@ -5,6 +5,8 @@ package com.winhc.dataworks.flow.touch.utils;
  * @Date 2020/6/23
  * @Description TODO
  */
+import org.yaml.snakeyaml.Yaml;
+
 import java.io.File;
 import java.io.FileReader;
 import java.io.Reader;
@@ -12,10 +14,9 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
 
-import org.yaml.snakeyaml.Yaml;
-
 public class YmlUtil {
-    private static String schemaFileName="schema-file.yml";
+//    private static String schemaFileName="schema-file.yml";
+    private static String schemaFileName="odps-schema.yaml";
     /**
      * 获取yml文件中的指定字段,返回一个map
      *

+ 6 - 0
src/main/resources/odps-schema.yaml

@@ -0,0 +1,6 @@
+table:
+  - project: winhc_eci_dev
+    tableName: company_env_punishment
+    columns: id,name,department,publish_time,punish_number,punish_basis,law_break,reason,content,execution,source_url,source_flag,create_time,update_time,deleted
+    dupliCols: new_cid,source_url
+