diff --git a/lib/com/muyu/etl/basic/DataValueBasic.java b/lib/com/muyu/etl/basic/DataValueBasic.java new file mode 100644 index 0000000..028b4b5 --- /dev/null +++ b/lib/com/muyu/etl/basic/DataValueBasic.java @@ -0,0 +1,24 @@ +package com.muyu.etl.basic; + +import com.muyu.etl.domain.DataValue; + +public interface DataValueBasic extends TaskBasic{ + + /** + * 数据值 + * @return 返回查询的数据值 + */ + public DataValue getDataStructure(); + + /** + * 数据记录 + * @return 数据记录 + */ + public DataValue[] getRow(); + + /** + * 数据集 + * @return 数据集 + */ + public DataValue[][] getRows(); +} diff --git a/lib/com/muyu/etl/basic/TaskBasic.java b/lib/com/muyu/etl/basic/TaskBasic.java new file mode 100644 index 0000000..9314294 --- /dev/null +++ b/lib/com/muyu/etl/basic/TaskBasic.java @@ -0,0 +1,11 @@ +package com.muyu.etl.basic; + +import com.muyu.etl.scope.TaskScopeBasic; +import com.muyu.etl.scope.TaskScopeConfig; + +public interface TaskBasic { + + public default TaskScopeConfig getScopeConfig(){ + return TaskScopeBasic.get(); + } +} diff --git a/lib/com/muyu/etl/domain/DataValue.java b/lib/com/muyu/etl/domain/DataValue.java new file mode 100644 index 0000000..d65a389 --- /dev/null +++ b/lib/com/muyu/etl/domain/DataValue.java @@ -0,0 +1,30 @@ +package com.muyu.etl.domain; + +import com.muyu.etl.enums.DataType; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class DataValue { + /** + * 字段名 + */ + private String key; + /** + * 字段类型 + */ + private DataType type; + /** + * 描述 + */ + private String label; + /** + * 值 + */ + private Object value; +} diff --git a/lib/com/muyu/etl/enums/DataType.java b/lib/com/muyu/etl/enums/DataType.java new file mode 100644 index 0000000..aae16d5 --- /dev/null +++ b/lib/com/muyu/etl/enums/DataType.java @@ -0,0 +1,73 @@ +package com.muyu.etl.enums; + +import java.math.BigDecimal; +import java.util.Date; + +/** + * @Author:zhangzhihao + * @name:DataType + * @Date:2024/8/28 18:38 + * 不准抄代码,添加注释,清楚每一行代码意思 + */ +public enum DataType { + VARCHAR("varchar",String.class,"String"), + BIGINT("bigint", Long.class,"Long"), + INT("int", Integer.class,"Integer"), + DECIMAL("decimal", BigDecimal.class,"BigDecimal"), + DATETIME("datetime", Date.class,"Date"), + TEXT("text", String.class,"String"), + DOUBLE("double", Double.class,"Double"); + + private final String sourceType; + + private final Class targetType; + + private final String javaType; + + public String getSourceType() { + return sourceType; + } + + public Class getTargetType() { + return targetType; + } + + public String getJavaType() { + return javaType; + } + + + public static Class convertType(String type){ + for (DataType dataType : DataType.values()) { + if (dataType.sourceType.equalsIgnoreCase(type)){ + return dataType.targetType; + } + } + return String.class; + } + + public static DataType findBySqlType(String sqlType){ + for (DataType dataType : DataType.values()) { + if (dataType.getSourceType().equalsIgnoreCase(sqlType)){ + return dataType; + } + } + return VARCHAR; + } + + public static String convertTypeString(String type){ + + for (DataType dataType : DataType.values()) { + if (dataType.sourceType.equalsIgnoreCase(type)){ + return dataType.javaType; + } + } + return "String"; + } + + DataType(String sourceType, Class targetType, String javaType) { + this.sourceType = sourceType; + this.targetType = targetType; + this.javaType = javaType; + } +} diff --git a/lib/com/muyu/etl/scope/TaskScopeBasic.java b/lib/com/muyu/etl/scope/TaskScopeBasic.java new file mode 100644 index 0000000..7d616ef --- /dev/null +++ b/lib/com/muyu/etl/scope/TaskScopeBasic.java @@ -0,0 +1,18 @@ +package com.muyu.etl.scope; + +public class TaskScopeBasic { + + private static final ThreadLocal localScope = new ThreadLocal<>(); + + public static void set(final TaskScopeConfig handler) { + localScope.set(handler); + } + + public static TaskScopeConfig get() { + return localScope.get(); + } + + public static void remove(){ + localScope.remove(); + } +} diff --git a/lib/com/muyu/etl/scope/TaskScopeConfig.java b/lib/com/muyu/etl/scope/TaskScopeConfig.java new file mode 100644 index 0000000..7bdd377 --- /dev/null +++ b/lib/com/muyu/etl/scope/TaskScopeConfig.java @@ -0,0 +1,36 @@ +package com.muyu.etl.scope; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.concurrent.LinkedBlockingDeque; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TaskScopeConfig { + + /** + * 任務ID + */ + private String taskId; + + + private LinkedBlockingDeque taskNodeQueue = new LinkedBlockingDeque(); + + public void addTaskNode(Object obj){ + this.taskNodeQueue.add(obj); + } + + public boolean hashTaskNodeNext(){ + return !taskNodeQueue.isEmpty(); + } + + private T nextTaskNode(){ + return (T) taskNodeQueue.poll(); + } + +}