提取公共类

master
lwj 2024-09-10 02:05:44 +08:00
commit e1e570048b
8 changed files with 260 additions and 0 deletions

35
.gitignore vendored 100644
View File

@ -0,0 +1,35 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

33
pom.xml 100644
View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.muyu</groupId>
<artifactId>cloud-common</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>cloud-common-etl</artifactId>
<version>1.0.0</version>
<description>
cloud-common-etl
</description>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.muyu</groupId>
<artifactId>cloud-common-core</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -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();
}

View File

@ -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();
}
}

View File

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

View File

@ -0,0 +1,73 @@
package com.muyu.etl.enums;
import java.math.BigDecimal;
import java.util.Date;
/**
* @Authorzhangzhihao
* @nameDataType
* @Date2024/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;
}
}

View File

@ -0,0 +1,18 @@
package com.muyu.etl.scope;
public class TaskScopeBasic {
private static final ThreadLocal<TaskScopeConfig> 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();
}
}

View File

@ -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> T nextTaskNode(){
return (T) taskNodeQueue.poll();
}
}