forked from CodePhiliaX/Chat2DB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be9dbfd
commit 6f96808
Showing
27 changed files
with
1,040 additions
and
174 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
...b-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/DeletedTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ai.chat2db.server.domain.api.enums; | ||
|
||
public enum DeletedTypeEnum { | ||
|
||
Y,N | ||
} |
6 changes: 6 additions & 0 deletions
6
...db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TaskStatusEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ai.chat2db.server.domain.api.enums; | ||
|
||
public enum TaskStatusEnum { | ||
|
||
INIT, PROCESSING, FINISH, ERROR | ||
} |
24 changes: 24 additions & 0 deletions
24
...t2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/enums/TaskTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ai.chat2db.server.domain.api.enums; | ||
|
||
public enum TaskTypeEnum { | ||
|
||
/** | ||
* download table data | ||
*/ | ||
DOWNLOAD_TABLE_DATA, | ||
|
||
/** | ||
* upload table data | ||
*/ | ||
UPLOAD_TABLE_DATA, | ||
|
||
/** | ||
* download table structure | ||
*/ | ||
DOWNLOAD_TABLE_STRUCTURE, | ||
|
||
/** | ||
* upload table structure | ||
*/ | ||
UPLOAD_TABLE_STRUCTURE, | ||
} |
84 changes: 84 additions & 0 deletions
84
...main/chat2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/model/Task.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package ai.chat2db.server.domain.api.model; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.Date; | ||
|
||
@Data | ||
public class Task implements Serializable { | ||
/** | ||
* 主键 | ||
*/ | ||
private Long id; | ||
|
||
/** | ||
* 创建时间 | ||
*/ | ||
private Date gmtCreate; | ||
|
||
/** | ||
* 修改时间 | ||
*/ | ||
private Date gmtModified; | ||
|
||
/** | ||
* 数据源连接ID | ||
*/ | ||
private Long dataSourceId; | ||
|
||
/** | ||
* db名称 | ||
*/ | ||
private String databaseName; | ||
|
||
/** | ||
* schema名称 | ||
*/ | ||
private String schemaName; | ||
|
||
/** | ||
* table_name | ||
*/ | ||
private String tableName; | ||
|
||
/** | ||
* 是否被删除,y表示删除,n表示未删除 | ||
*/ | ||
private String deleted; | ||
|
||
/** | ||
* 用户id | ||
*/ | ||
private Long userId; | ||
|
||
/** | ||
* task type, such as: DOWNLOAD_DATA, UPLOAD_TABLE_DATA, DOWNLOAD_TABLE_STRUCTURE, UPLOAD_TABLE_STRUCTURE, | ||
*/ | ||
private String taskType; | ||
|
||
/** | ||
* task status | ||
*/ | ||
private String taskStatus; | ||
|
||
/** | ||
* task progress | ||
*/ | ||
private String taskProgress; | ||
|
||
/** | ||
* task name | ||
*/ | ||
private String taskName; | ||
|
||
/** | ||
* download url | ||
*/ | ||
private String downloadUrl; | ||
|
||
/** | ||
* task content | ||
*/ | ||
private byte[] content; | ||
} |
54 changes: 54 additions & 0 deletions
54
...b-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskCreateParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package ai.chat2db.server.domain.api.param; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
|
||
@Data | ||
public class TaskCreateParam implements Serializable { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* 数据源连接ID | ||
*/ | ||
private Long dataSourceId; | ||
|
||
/** | ||
* db名称 | ||
*/ | ||
private String databaseName; | ||
|
||
/** | ||
* schema名称 | ||
*/ | ||
private String schemaName; | ||
|
||
/** | ||
* table_name | ||
*/ | ||
private String tableName; | ||
|
||
/** | ||
* 用户id | ||
*/ | ||
private Long userId; | ||
|
||
|
||
/** | ||
* task progress | ||
*/ | ||
private String taskProgress; | ||
|
||
/** | ||
* task name | ||
*/ | ||
private String taskName; | ||
|
||
/** | ||
* task type, such as: DOWNLOAD_DATA, UPLOAD_TABLE_DATA, DOWNLOAD_TABLE_STRUCTURE, UPLOAD_TABLE_STRUCTURE, | ||
*/ | ||
private String taskType; | ||
|
||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskPageParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ai.chat2db.server.domain.api.param; | ||
|
||
import ai.chat2db.server.tools.base.wrapper.param.PageQueryParam; | ||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
@Data | ||
public class TaskPageParam extends PageQueryParam implements Serializable { | ||
|
||
|
||
private Long userId; | ||
|
||
private List<String> taskType; | ||
|
||
private String taskStatus; | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
...b-server-domain-api/src/main/java/ai/chat2db/server/domain/api/param/TaskUpdateParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package ai.chat2db.server.domain.api.param; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
|
||
@Data | ||
public class TaskUpdateParam implements Serializable { | ||
|
||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* task id | ||
*/ | ||
private Long id; | ||
|
||
/** | ||
* 用户id | ||
*/ | ||
private Long userId; | ||
|
||
/** | ||
* task type, such as: DOWNLOAD_DATA, UPLOAD_TABLE_DATA, DOWNLOAD_TABLE_STRUCTURE, UPLOAD_TABLE_STRUCTURE, | ||
*/ | ||
private String taskStatus; | ||
|
||
/** | ||
* task progress | ||
*/ | ||
private String taskProgress; | ||
|
||
/** | ||
* task name | ||
*/ | ||
private String taskName; | ||
|
||
/** | ||
* task description | ||
*/ | ||
private String downloadUrl; | ||
|
||
/** | ||
* task content | ||
*/ | ||
private byte[] content; | ||
} |
45 changes: 45 additions & 0 deletions
45
...2db-server-domain-api/src/main/java/ai/chat2db/server/domain/api/service/TaskService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ai.chat2db.server.domain.api.service; | ||
|
||
import ai.chat2db.server.domain.api.model.Task; | ||
import ai.chat2db.server.domain.api.param.TaskCreateParam; | ||
import ai.chat2db.server.domain.api.param.TaskPageParam; | ||
import ai.chat2db.server.domain.api.param.TaskUpdateParam; | ||
import ai.chat2db.server.tools.base.wrapper.result.ActionResult; | ||
import ai.chat2db.server.tools.base.wrapper.result.DataResult; | ||
import ai.chat2db.server.tools.base.wrapper.result.PageResult; | ||
|
||
public interface TaskService { | ||
|
||
/** | ||
* create task | ||
* | ||
* @param param task param | ||
* @return task id | ||
*/ | ||
DataResult<Long> create(TaskCreateParam param); | ||
|
||
/** | ||
* update task status | ||
* | ||
* @param param task param | ||
* @return action result | ||
*/ | ||
ActionResult updateStatus(TaskUpdateParam param); | ||
|
||
|
||
/** | ||
* get task list | ||
* | ||
* @param param task id | ||
* @return task | ||
*/ | ||
PageResult<Task> page(TaskPageParam param); | ||
|
||
/** | ||
* get task | ||
* | ||
* @param id task id | ||
* @return task | ||
*/ | ||
DataResult<Task> get(Long id); | ||
} |
21 changes: 21 additions & 0 deletions
21
...rver-domain-core/src/main/java/ai/chat2db/server/domain/core/converter/TaskConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package ai.chat2db.server.domain.core.converter; | ||
|
||
import ai.chat2db.server.domain.api.model.Task; | ||
import ai.chat2db.server.domain.api.param.TaskCreateParam; | ||
import ai.chat2db.server.domain.repository.entity.TaskDO; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.mapstruct.Mapper; | ||
|
||
import java.util.List; | ||
@Slf4j | ||
@Mapper(componentModel = "spring") | ||
public abstract class TaskConverter { | ||
|
||
public abstract TaskDO todo(TaskCreateParam param); | ||
|
||
|
||
public abstract Task toModel(TaskDO param); | ||
|
||
|
||
public abstract List<Task> toModel(List<TaskDO> param); | ||
} |
69 changes: 69 additions & 0 deletions
69
...-server-domain-core/src/main/java/ai/chat2db/server/domain/core/impl/TaskServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package ai.chat2db.server.domain.core.impl; | ||
|
||
import ai.chat2db.server.domain.api.enums.DeletedTypeEnum; | ||
import ai.chat2db.server.domain.api.enums.TaskStatusEnum; | ||
import ai.chat2db.server.domain.api.model.Task; | ||
import ai.chat2db.server.domain.api.param.TaskCreateParam; | ||
import ai.chat2db.server.domain.api.param.TaskPageParam; | ||
import ai.chat2db.server.domain.api.param.TaskUpdateParam; | ||
import ai.chat2db.server.domain.api.service.TaskService; | ||
import ai.chat2db.server.domain.core.converter.TaskConverter; | ||
import ai.chat2db.server.domain.repository.MapperUtils; | ||
import ai.chat2db.server.domain.repository.entity.TaskDO; | ||
import ai.chat2db.server.tools.base.wrapper.result.ActionResult; | ||
import ai.chat2db.server.tools.base.wrapper.result.DataResult; | ||
import ai.chat2db.server.tools.base.wrapper.result.PageResult; | ||
import com.baomidou.mybatisplus.core.metadata.IPage; | ||
import com.baomidou.mybatisplus.core.metadata.OrderItem; | ||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||
import com.google.common.collect.Lists; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class TaskServiceImpl implements TaskService { | ||
|
||
/** | ||
* task converter | ||
*/ | ||
@Autowired | ||
private TaskConverter taskConverter; | ||
|
||
@Override | ||
public DataResult<Long> create(TaskCreateParam param) { | ||
TaskDO taskDO = taskConverter.todo(param); | ||
taskDO.setDeleted(DeletedTypeEnum.N.name()); | ||
taskDO.setTaskStatus(TaskStatusEnum.INIT.name()); | ||
MapperUtils.getTaskMapper().insert(taskDO); | ||
return DataResult.of(taskDO.getId()); | ||
} | ||
|
||
@Override | ||
public ActionResult updateStatus(TaskUpdateParam param) { | ||
TaskDO taskDO = new TaskDO(); | ||
taskDO.setId(param.getId()); | ||
taskDO.setTaskStatus(param.getTaskStatus()); | ||
taskDO.setContent(param.getContent()); | ||
MapperUtils.getTaskMapper().updateById(taskDO); | ||
return ActionResult.isSuccess(); | ||
} | ||
|
||
@Override | ||
public PageResult<Task> page(TaskPageParam param) { | ||
Page<TaskDO> page = new Page<>(); | ||
page.setCurrent(param.getPageNo()); | ||
page.setSize(param.getPageSize()); | ||
page.setOrders(Lists.newArrayList(OrderItem.desc("gmt_create"))); | ||
IPage<TaskDO> iPage = MapperUtils.getTaskMapper().pageQuery(page, param.getUserId(), DeletedTypeEnum.N.name()); | ||
if (iPage != null) { | ||
return PageResult.of(taskConverter.toModel(iPage.getRecords()), param); | ||
} | ||
return PageResult.empty(param.getPageNo(), param.getPageSize()); | ||
} | ||
|
||
@Override | ||
public DataResult<Task> get(Long id) { | ||
TaskDO task = MapperUtils.getTaskMapper().selectById(id); | ||
return DataResult.of(taskConverter.toModel(task)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...rver-domain-repository/src/main/java/ai/chat2db/server/domain/repository/MapperUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package ai.chat2db.server.domain.repository; | ||
|
||
import ai.chat2db.server.domain.repository.mapper.TaskMapper; | ||
|
||
public class MapperUtils { | ||
|
||
public static TaskMapper getTaskMapper() { | ||
return Dbutils.getMapper(TaskMapper.class); | ||
} | ||
} |
Oops, something went wrong.