feat: add batch query table api
This commit is contained in:
parent
035107c731
commit
6e75a78017
|
@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
@ -86,10 +87,11 @@ public class DocumentController {
|
||||||
return JsonData.ok(documentService.getSimpleOneByProjectId(projectId, version));
|
return JsonData.ok(documentService.getSimpleOneByProjectId(projectId, version));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(Routes.Document.GET_TABLE_DETAIL)
|
@PostMapping(Routes.Document.GET_TABLE_DETAIL)
|
||||||
public JsonData<DatabaseDocumentResponse.TableDocumentResponse> getTableDocument(@PathVariable Integer projectId,
|
public JsonData<List<DatabaseDocumentResponse.TableDocumentResponse>> getTableDocument(@PathVariable Integer projectId,
|
||||||
@PathVariable Integer tableId) {
|
@PathVariable Integer documentId,
|
||||||
return JsonData.ok(documentService.getTableDetails(projectId, tableId));
|
@RequestBody List<Integer> tableIds) {
|
||||||
|
return JsonData.ok(documentService.getTableDetails(projectId, documentId, tableIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public interface Routes {
|
||||||
|
|
||||||
String GET_SIMPLE_ONE = BASE + "/projects/{projectId}/documents/simple";
|
String GET_SIMPLE_ONE = BASE + "/projects/{projectId}/documents/simple";
|
||||||
|
|
||||||
String GET_TABLE_DETAIL = BASE + "/projects/{projectId}/table_documents/{tableId}";
|
String GET_TABLE_DETAIL = BASE + "/projects/{projectId}/documents/{documentId}/table_documents";
|
||||||
|
|
||||||
String EXPORT = BASE + "/projects/{projectId}/document_files";
|
String EXPORT = BASE + "/projects/{projectId}/document_files";
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -180,30 +181,36 @@ public class DocumentService {
|
||||||
.orElseGet(Page::empty);
|
.orElseGet(Page::empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<DatabaseDocumentResponse.TableDocumentResponse> getTableDetails(Integer projectId,
|
public List<DatabaseDocumentResponse.TableDocumentResponse> getTableDetails(Integer projectId,
|
||||||
Integer tableId) {
|
Integer databaseDocumentId,
|
||||||
|
List<Integer> tableIds) {
|
||||||
// maybe deleted
|
// maybe deleted
|
||||||
if (!projectDao.existsById(projectId)) {
|
if (CollectionUtils.isEmpty(tableIds) || !projectDao.existsById(projectId)) {
|
||||||
return Optional.empty();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
var tables =
|
||||||
return tableDocumentDao.selectOptionalById(tableId)
|
tableDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
|
||||||
|
var columns =
|
||||||
|
tableColumnDocumentDao.selectByDatabaseDocumentIdAndTableIdIn(databaseDocumentId, tableIds);
|
||||||
|
var indexes =
|
||||||
|
tableIndexDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
|
||||||
|
var triggers =
|
||||||
|
tableTriggerDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
|
||||||
|
Map<Integer, List<TableColumnDocumentPojo>> columnsGroupByTableMetaId = columns.stream()
|
||||||
|
.collect(Collectors.groupingBy(TableColumnDocumentPojo::getTableDocumentId));
|
||||||
|
Map<Integer, List<TableIndexDocumentPojo>> indexesGroupByTableMetaId = indexes.stream()
|
||||||
|
.collect(Collectors.groupingBy(TableIndexDocumentPojo::getTableDocumentId));
|
||||||
|
Map<Integer, List<TableTriggerDocumentPojo>> triggersGroupByTableMetaId = triggers.stream()
|
||||||
|
.collect(Collectors.groupingBy(TableTriggerDocumentPojo::getTableDocumentId));
|
||||||
|
return tables.stream()
|
||||||
.map(table -> {
|
.map(table -> {
|
||||||
Integer documentId = table.getDatabaseDocumentId();
|
Integer tableId = table.getId();
|
||||||
var columns = tableColumnDocumentDao.selectByDatabaseDocumentId(documentId);
|
|
||||||
var indexes = tableIndexDocumentDao.selectByDatabaseMetaId(documentId);
|
|
||||||
var triggers = tableTriggerDocumentDao.selectByDatabaseDocumentId(documentId);
|
|
||||||
Map<Integer, List<TableColumnDocumentPojo>> columnsGroupByTableMetaId = columns.stream()
|
|
||||||
.collect(Collectors.groupingBy(TableColumnDocumentPojo::getTableDocumentId));
|
|
||||||
Map<Integer, List<TableIndexDocumentPojo>> indexesGroupByTableMetaId = indexes.stream()
|
|
||||||
.collect(Collectors.groupingBy(TableIndexDocumentPojo::getTableDocumentId));
|
|
||||||
Map<Integer, List<TableTriggerDocumentPojo>> triggersGroupByTableMetaId = triggers.stream()
|
|
||||||
.collect(Collectors.groupingBy(TableTriggerDocumentPojo::getTableDocumentId));
|
|
||||||
var subColumns = columnsGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
var subColumns = columnsGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
||||||
var subIndexes = indexesGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
var subIndexes = indexesGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
||||||
var subTriggers = triggersGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
var subTriggers = triggersGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
||||||
return documentResponseConverter.of(table, subColumns, subIndexes, subTriggers);
|
return documentResponseConverter.of(table, subColumns, subIndexes, subTriggers);
|
||||||
});
|
})
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<String> toMarkdown(Integer projectId, Long version) {
|
public Optional<String> toMarkdown(Integer projectId, Long version) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.jooq.DSLContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.databasir.dao.Tables.TABLE_COLUMN_DOCUMENT;
|
import static com.databasir.dao.Tables.TABLE_COLUMN_DOCUMENT;
|
||||||
|
@ -28,10 +29,15 @@ public class TableColumnDocumentDao extends BaseDao<TableColumnDocumentPojo> {
|
||||||
.fetchInto(TableColumnDocumentPojo.class);
|
.fetchInto(TableColumnDocumentPojo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByDatabaseDocumentId(Integer schemaDocumentId) {
|
public List<TableColumnDocumentPojo> selectByDatabaseDocumentIdAndTableIdIn(Integer schemaDocumentId,
|
||||||
getDslContext()
|
List<Integer> tableIdIn) {
|
||||||
.deleteFrom(TABLE_COLUMN_DOCUMENT)
|
if (tableIdIn == null || tableIdIn.isEmpty()) {
|
||||||
.where(TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
|
return Collections.emptyList();
|
||||||
.execute();
|
}
|
||||||
|
return getDslContext()
|
||||||
|
.select(TABLE_COLUMN_DOCUMENT.fields()).from(TABLE_COLUMN_DOCUMENT)
|
||||||
|
.where(TABLE_COLUMN_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId)
|
||||||
|
.and(TABLE_COLUMN_DOCUMENT.TABLE_DOCUMENT_ID.in(tableIdIn)))
|
||||||
|
.fetchInto(TableColumnDocumentPojo.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.jooq.DSLContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.databasir.dao.Tables.TABLE_DOCUMENT;
|
import static com.databasir.dao.Tables.TABLE_DOCUMENT;
|
||||||
|
@ -33,4 +34,16 @@ public class TableDocumentDao extends BaseDao<TableDocumentPojo> {
|
||||||
.deleteFrom(TABLE_DOCUMENT).where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
|
.deleteFrom(TABLE_DOCUMENT).where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<TableDocumentPojo> selectByDatabaseDocumentIdAndIdIn(Integer databaseDocumentId,
|
||||||
|
List<Integer> idList) {
|
||||||
|
if (idList == null || idList.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return getDslContext()
|
||||||
|
.selectFrom(TABLE_DOCUMENT)
|
||||||
|
.where(TABLE_DOCUMENT.DATABASE_DOCUMENT_ID.eq(databaseDocumentId)
|
||||||
|
.and(TABLE_DOCUMENT.ID.in(idList)))
|
||||||
|
.fetchInto(TableDocumentPojo.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.jooq.DSLContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.databasir.dao.Tables.TABLE_INDEX_DOCUMENT;
|
import static com.databasir.dao.Tables.TABLE_INDEX_DOCUMENT;
|
||||||
|
@ -21,16 +22,22 @@ public class TableIndexDocumentDao extends BaseDao<TableIndexDocumentPojo> {
|
||||||
super(TABLE_INDEX_DOCUMENT, TableIndexDocumentPojo.class);
|
super(TABLE_INDEX_DOCUMENT, TableIndexDocumentPojo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TableIndexDocumentPojo> selectByDatabaseMetaId(Integer schemaMetaId) {
|
public List<TableIndexDocumentPojo> selectByDatabaseMetaId(Integer documentId) {
|
||||||
return getDslContext()
|
return getDslContext()
|
||||||
.select(TABLE_INDEX_DOCUMENT.fields()).from(TABLE_INDEX_DOCUMENT)
|
.select(TABLE_INDEX_DOCUMENT.fields()).from(TABLE_INDEX_DOCUMENT)
|
||||||
.where(TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaMetaId))
|
.where(TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID.eq(documentId))
|
||||||
.fetchInto(TableIndexDocumentPojo.class);
|
.fetchInto(TableIndexDocumentPojo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByDatabaseMetaId(Integer schemaMetaId) {
|
public List<TableIndexDocumentPojo> selectByDatabaseDocumentIdAndIdIn(Integer documentId,
|
||||||
getDslContext()
|
List<Integer> tableIdIn) {
|
||||||
.deleteFrom(TABLE_INDEX_DOCUMENT).where(TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaMetaId))
|
if (tableIdIn == null || tableIdIn.isEmpty()) {
|
||||||
.execute();
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return getDslContext()
|
||||||
|
.select(TABLE_INDEX_DOCUMENT.fields()).from(TABLE_INDEX_DOCUMENT)
|
||||||
|
.where(TABLE_INDEX_DOCUMENT.DATABASE_DOCUMENT_ID.eq(documentId)
|
||||||
|
.and(TABLE_INDEX_DOCUMENT.TABLE_DOCUMENT_ID.in(tableIdIn)))
|
||||||
|
.fetchInto(TableIndexDocumentPojo.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.jooq.DSLContext;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.databasir.dao.Tables.TABLE_TRIGGER_DOCUMENT;
|
import static com.databasir.dao.Tables.TABLE_TRIGGER_DOCUMENT;
|
||||||
|
@ -28,10 +29,15 @@ public class TableTriggerDocumentDao extends BaseDao<TableTriggerDocumentPojo> {
|
||||||
.fetchInto(TableTriggerDocumentPojo.class);
|
.fetchInto(TableTriggerDocumentPojo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteByDatabaseDocumentId(Integer schemaDocumentId) {
|
public List<TableTriggerDocumentPojo> selectByDatabaseDocumentIdAndIdIn(Integer documentId,
|
||||||
getDslContext()
|
List<Integer> tableIdIn) {
|
||||||
.deleteFrom(TABLE_TRIGGER_DOCUMENT)
|
if (tableIdIn == null || tableIdIn.isEmpty()) {
|
||||||
.where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(schemaDocumentId))
|
return Collections.emptyList();
|
||||||
.execute();
|
}
|
||||||
|
return getDslContext()
|
||||||
|
.select(TABLE_TRIGGER_DOCUMENT.fields()).from(TABLE_TRIGGER_DOCUMENT)
|
||||||
|
.where(TABLE_TRIGGER_DOCUMENT.DATABASE_DOCUMENT_ID.eq(documentId)
|
||||||
|
.and(TABLE_TRIGGER_DOCUMENT.TABLE_DOCUMENT_ID.in(tableIdIn)))
|
||||||
|
.fetchInto(TableTriggerDocumentPojo.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue