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:
vran
2022-01-25 23:48:34 +08:00
committed by GitHub
parent 1c909cbeda
commit 604cb4ab47
20 changed files with 492 additions and 44 deletions

View File

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

View File

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

View File

@@ -54,6 +54,10 @@ public class ProjectCreateRequest {
private List<String> ignoreColumnNameRegexes = new ArrayList<>();
private Boolean isAutoSync = false;
private String autoSyncCron;
}
}

View File

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

View File

@@ -17,6 +17,10 @@ public class ProjectSimpleResponse {
private String databaseType;
private Boolean isAutoSync;
private String autoSyncCron;
private LocalDateTime createAt;
}

View File

@@ -52,5 +52,10 @@ public class ProjectUpdateRequest {
private List<String> ignoreColumnNameRegexes = new ArrayList<>();
@NotNull
private Boolean isAutoSync;
private String autoSyncCron;
}
}

View File

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