Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db data import #1339

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum ExportFileSuffix {
//word
WORD(".docx"),
//excel
EXCEL(".xlsx"),
XLSX(".xlsx"),
//markdown
MARKDOWN(".md"),
//html
Expand All @@ -26,7 +26,7 @@ public enum ExportFileSuffix {
JSON(".json"),

CSV(".csv"),

XLS(".xls"),
ZIP(".zip");

private String suffix;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package ai.chat2db.server.domain.api.param.datasource;

import ai.chat2db.server.tools.common.model.rdb.data.option.AbstractExportDataOptions;
import ai.chat2db.server.tools.common.model.rdb.data.option.table.BaseTableOptions;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* @author: zgq
* @date: 2024年03月24日 13:17
Expand All @@ -14,5 +19,7 @@
public class DatabaseExportDataParam {
private String databaseName;
private String schemaName;
private String exportType;
@NotNull
private AbstractExportDataOptions exportDataOption;
private List<BaseTableOptions> exportTableOptions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ai.chat2db.server.domain.api.param.datasource;

import ai.chat2db.server.tools.common.model.rdb.data.option.AbstractImportDataOptions;
import ai.chat2db.server.tools.common.model.rdb.data.option.table.ImportTableOptions;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* 功能描述
*
* @author: zgq
* @date: 2024年04月23日 13:52
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DatabaseImportDataParam {
private String databaseName;
private String schemaName;
private ImportTableOptions importTableOption;
private AbstractImportDataOptions importDataOption;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ai.chat2db.server.tools.base.enums;

import lombok.Getter;

/**
* @author: zgq
* @date: 2024年05月01日 19:57
*/
@Getter
public enum JdbcUrlParameterEnum implements BaseEnum<String> {

CONTINUE_BATCH_ON_ERROR("continueBatchOnError");

JdbcUrlParameterEnum(String description) {
this.description = description;
}

final String description;

/**
* @return
*/
@Override
public String getCode() {
return this.name();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ai.chat2db.server.tools.common.model.rdb.data.option;

import jakarta.validation.constraints.NotNull;
import lombok.Data;

/**
* @author: zgq
* @date: 2024年04月25日 22:59
*/
@Data
public abstract class AbstractDataOption implements AbstractDataOptionInterface {
@NotNull
protected String fileType;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ai.chat2db.server.tools.common.model.rdb.data.option;

public interface AbstractDataOptionInterface {
String getFileType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ai.chat2db.server.tools.common.model.rdb.data.option;

import ai.chat2db.server.tools.common.model.rdb.data.option.json.ExportData2JsonOptions;
import ai.chat2db.server.tools.common.model.rdb.data.option.sql.BaseExportData2SqlOptions;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
* @author: zgq
* @date: 2024年04月25日 23:31
*/
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "fileType",
visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = BaseExportDataOptions.class, name = "CSV"),
@JsonSubTypes.Type(value = BaseExportData2SqlOptions.class, name = "SQL"),
@JsonSubTypes.Type(value = BaseExportDataOptions.class, name = "XLSX"),
@JsonSubTypes.Type(value = BaseExportDataOptions.class, name = "XLS"),
@JsonSubTypes.Type(value = ExportData2JsonOptions.class, name = "JSON")
})
public abstract class AbstractExportDataOptions extends AbstractDataOption {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ai.chat2db.server.tools.common.model.rdb.data.option;

import ai.chat2db.server.tools.common.model.rdb.data.option.json.ImportJsonDataOptions;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;

/**
* @author: zgq
* @date: 2024年04月25日 23:04
*/
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "fileType",
visible = true
)
@JsonSubTypes({
@JsonSubTypes.Type(value = BaseImportExcelDataOptions.class, name = "CSV"),
@JsonSubTypes.Type(value = BaseImportExcelDataOptions.class, name = "XLSX"),
@JsonSubTypes.Type(value = BaseImportExcelDataOptions.class, name = "XLS"),
@JsonSubTypes.Type(value = ImportJsonDataOptions.class, name = "JSON")
})
public abstract class AbstractImportDataOptions extends AbstractDataOption {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ai.chat2db.server.tools.common.model.rdb.data.option;

import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* 功能描述
*
* @author: zgq
* @date: 2024年04月26日 0:02
*/
@Data
@EqualsAndHashCode(callSuper =true)
public class BaseExportDataOptions extends AbstractExportDataOptions {
@NotNull
public Boolean containsHeader;

public BaseExportDataOptions() {
this.containsHeader = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ai.chat2db.server.tools.common.model.rdb.data.option;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @author: zgq
* @date: 2024年04月25日 23:40
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class BaseImportDataOptions extends AbstractImportDataOptions {
public Integer dataStartRowNum;
public Integer dataEndRowNum;

public BaseImportDataOptions() {
dataStartRowNum = 1;
dataEndRowNum = Integer.MAX_VALUE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ai.chat2db.server.tools.common.model.rdb.data.option;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @author: zgq
* @date: 2024年04月26日 10:06
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class BaseImportExcelDataOptions extends BaseImportDataOptions {
public Integer headerRowNum;

public BaseImportExcelDataOptions() {
this.headerRowNum = 1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ai.chat2db.server.tools.common.model.rdb.data.option.json;

import ai.chat2db.server.tools.common.model.rdb.data.option.AbstractExportDataOptions;
import cn.hutool.core.date.DatePattern;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @author: zgq
* @date: 2024年04月26日 0:20
*/
@Data
@EqualsAndHashCode(callSuper =true)
public class ExportData2JsonOptions extends AbstractExportDataOptions {

private String dataTimeFormat;

private Boolean isTimestamps;

public ExportData2JsonOptions() {
dataTimeFormat = DatePattern.NORM_DATETIME_PATTERN;
isTimestamps = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ai.chat2db.server.tools.common.model.rdb.data.option.json;

import ai.chat2db.server.tools.common.model.rdb.data.option.BaseImportDataOptions;
import cn.hutool.core.date.DatePattern;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @author: zgq
* @date: 2024年04月25日 23:08
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class ImportJsonDataOptions extends BaseImportDataOptions {
private String rootNodeName;
private String dataTimeFormat;

public ImportJsonDataOptions() {
dataTimeFormat = DatePattern.NORM_DATETIME_PATTERN;
rootNodeName = "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package ai.chat2db.server.tools.common.model.rdb.data.option.sql;

import ai.chat2db.server.tools.common.model.rdb.data.option.BaseExportDataOptions;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* @author: zgq
* @date: 2024年04月26日 0:36
*/
@Data
@EqualsAndHashCode(callSuper =true)
public class BaseExportData2SqlOptions extends BaseExportDataOptions {
@NotBlank
public String sqlType;
public String updateCondition;
public BaseExportData2SqlOptions() {
sqlType= "single";
updateCondition= "id";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ai.chat2db.server.tools.common.model.rdb.data.option.table;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;

import java.util.List;

/**
* @author: zgq
* @date: 2024年04月25日 23:53
*/
@Data
public class BaseTableOptions implements TableOptionInterface {
@NotBlank
public String tableName;
@NotEmpty
public List<String> tableColumns;
@NotEmpty
public List<String> fileColumns;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ai.chat2db.server.tools.common.model.rdb.data.option.table;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
* @author: zgq
* @date: 2024年04月26日 9:32
*/
@Data
@EqualsAndHashCode(callSuper =true)
public class ImportNewTableOptions extends ImportTableOptions{

/*
* create table sql
* */
private String sql;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ai.chat2db.server.tools.common.model.rdb.data.option.table;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.Data;

/**
* @author: zgq
* @date: 2024年04月26日 9:39
*/

@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
property = "importType",
visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = ImportTableOptions.class, name = "OLD"),
@JsonSubTypes.Type(value = ImportNewTableOptions.class, name = "NEW"),
})
@Data
public class ImportTableOptions extends BaseTableOptions {
private String importType;

public ImportTableOptions() {
importType = "OLD";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ai.chat2db.server.tools.common.model.rdb.data.option.table;

import java.util.List;

/**
* @author: zgq
* @date: 2024年04月25日 23:49
*/
public interface TableOptionInterface {
String getTableName();

List<String> getTableColumns();

List<String> getFileColumns();
}
Loading