mirror of
https://github.com/vran-dev/databasir.git
synced 2025-08-09 18:17:56 +08:00
feature:support auto sync project document by cron task (#3)
* feat: auto sync project document by cron task * feat:update README
This commit is contained in:
@@ -176,7 +176,7 @@ public class DocumentService {
|
||||
|
||||
public Page<DatabaseDocumentVersionResponse> getVersionsBySchemaSourceId(Integer projectId, Pageable page) {
|
||||
return databaseDocumentDao.selectOptionalByProjectId(projectId)
|
||||
.map(schemaMeta -> databaseDocumentHistoryDao.selectPageByDatabaseDocumentId(page, schemaMeta.getId())
|
||||
.map(schemaMeta -> databaseDocumentHistoryDao.selectVersionPageByDatabaseDocumentId(page, schemaMeta.getId())
|
||||
.map(history -> DatabaseDocumentVersionResponse.builder()
|
||||
.version(history.getVersion())
|
||||
.createAt(history.getCreateAt())
|
||||
|
@@ -31,5 +31,7 @@ public interface ProjectResponseConverter {
|
||||
|
||||
@Mapping(target = "id", source = "project.id")
|
||||
@Mapping(target = "createAt", source = "project.createAt")
|
||||
ProjectSimpleResponse toSimple(ProjectPojo project, DataSourcePojo dataSource);
|
||||
ProjectSimpleResponse toSimple(ProjectPojo project,
|
||||
DataSourcePojo dataSource,
|
||||
ProjectSyncRulePojo syncRule);
|
||||
}
|
||||
|
@@ -54,6 +54,10 @@ public class ProjectCreateRequest {
|
||||
|
||||
private List<String> ignoreColumnNameRegexes = new ArrayList<>();
|
||||
|
||||
private Boolean isAutoSync = false;
|
||||
|
||||
private String autoSyncCron;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,6 +15,8 @@ public class ProjectDetailResponse {
|
||||
|
||||
private String description;
|
||||
|
||||
private Integer groupId;
|
||||
|
||||
private DataSourceResponse dataSource;
|
||||
|
||||
private ProjectSyncRuleResponse projectSyncRule;
|
||||
@@ -51,6 +53,10 @@ public class ProjectDetailResponse {
|
||||
|
||||
private List<String> ignoreColumnNameRegexes = new ArrayList<>();
|
||||
|
||||
private Boolean isAutoSync;
|
||||
|
||||
private String autoSyncCron;
|
||||
|
||||
private LocalDateTime createAt;
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,10 @@ public class ProjectSimpleResponse {
|
||||
|
||||
private String databaseType;
|
||||
|
||||
private Boolean isAutoSync;
|
||||
|
||||
private String autoSyncCron;
|
||||
|
||||
private LocalDateTime createAt;
|
||||
|
||||
}
|
||||
|
@@ -52,5 +52,10 @@ public class ProjectUpdateRequest {
|
||||
|
||||
private List<String> ignoreColumnNameRegexes = new ArrayList<>();
|
||||
|
||||
@NotNull
|
||||
private Boolean isAutoSync;
|
||||
|
||||
private String autoSyncCron;
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -73,7 +73,6 @@ public class ProjectService {
|
||||
List<DataSourcePropertyPojo> properties = dataSourcePojoConverter.of(propertyValues, dataSourceId);
|
||||
dataSourcePropertyDao.batchInsert(properties);
|
||||
|
||||
// TODO redesign it
|
||||
ProjectSyncRulePojo syncRule = projectPojoConverter.of(request.getProjectSyncRule(), projectId);
|
||||
projectSyncRuleDao.insertAndReturnId(syncRule);
|
||||
}
|
||||
@@ -98,9 +97,10 @@ public class ProjectService {
|
||||
dataSourcePropertyDao.batchInsert(properties);
|
||||
}
|
||||
|
||||
// update project sync rule TODO redesign it
|
||||
// update project sync rule
|
||||
ProjectSyncRulePojo syncRule = projectPojoConverter.of(request.getProjectSyncRule(), projectId);
|
||||
projectSyncRuleDao.updateByProjectId(syncRule);
|
||||
projectSyncRuleDao.deleteByProjectId(projectId);
|
||||
projectSyncRuleDao.insertAndReturnId(syncRule);
|
||||
|
||||
// update project info
|
||||
ProjectPojo project = projectPojoConverter.of(request);
|
||||
@@ -132,9 +132,13 @@ public class ProjectService {
|
||||
Map<Integer, DataSourcePojo> dataSourceMapByProjectId = dataSourceDao.selectInProjectIds(projectIds)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(DataSourcePojo::getProjectId, Function.identity()));
|
||||
Map<Integer, ProjectSyncRulePojo> syncRuleMapByProjectId = projectSyncRuleDao.selectInProjectIds(projectIds)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(ProjectSyncRulePojo::getProjectId, Function.identity()));
|
||||
return pageData.map(project -> {
|
||||
DataSourcePojo dataSource = dataSourceMapByProjectId.get(project.getId());
|
||||
return projectResponseConverter.toSimple(project, dataSource);
|
||||
ProjectSyncRulePojo syncRule = syncRuleMapByProjectId.get(project.getId());
|
||||
return projectResponseConverter.toSimple(project, dataSource, syncRule);
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user