mirror of
https://github.com/vran-dev/databasir.git
synced 2025-08-08 17:32:14 +08:00
feature: support add description to table or column (#46)
* feat: generate document description model * feat: add description field to document * fix: checkstyle * feat:update frontend resources
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.databasir.core.domain.description.converter;
|
||||
|
||||
import com.databasir.core.domain.description.data.DocumentDescriptionSaveRequest;
|
||||
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface DocumentDescriptionPojoConverter {
|
||||
|
||||
@Mapping(target = "id", ignore = true)
|
||||
@Mapping(target = "createAt", ignore = true)
|
||||
@Mapping(target = "updateAt", ignore = true)
|
||||
DocumentDescriptionPojo of(Integer projectId,
|
||||
Integer updateBy,
|
||||
DocumentDescriptionSaveRequest request);
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.databasir.core.domain.description.data;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class DocumentDescriptionSaveRequest {
|
||||
|
||||
private String tableName;
|
||||
|
||||
private String columnName;
|
||||
|
||||
private String content;
|
||||
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package com.databasir.core.domain.description.service;
|
||||
|
||||
import com.databasir.core.domain.description.converter.DocumentDescriptionPojoConverter;
|
||||
import com.databasir.core.domain.description.data.DocumentDescriptionSaveRequest;
|
||||
import com.databasir.dao.impl.DocumentDescriptionDao;
|
||||
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DocumentDescriptionService {
|
||||
|
||||
private final DocumentDescriptionDao documentDescriptionDao;
|
||||
|
||||
private final DocumentDescriptionPojoConverter documentDescriptionPojoConverter;
|
||||
|
||||
@Transactional
|
||||
public void save(Integer groupId,
|
||||
Integer projectId,
|
||||
Integer userId,
|
||||
DocumentDescriptionSaveRequest request) {
|
||||
|
||||
DocumentDescriptionPojo pojo = documentDescriptionPojoConverter.of(projectId, userId, request);
|
||||
if (!documentDescriptionDao.exists(projectId, request.getTableName(), request.getColumnName())) {
|
||||
documentDescriptionDao.insertAndReturnId(pojo);
|
||||
} else {
|
||||
documentDescriptionDao.update(pojo);
|
||||
}
|
||||
}
|
||||
}
|
@@ -28,21 +28,25 @@ public interface DocumentResponseConverter {
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
DatabaseDocumentResponse.TableDocumentResponse of(TableDocumentPojo tableDocument,
|
||||
Integer discussionCount,
|
||||
String description,
|
||||
List<DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse> columns,
|
||||
List<TableIndexDocumentPojo> indexes,
|
||||
List<TableTriggerDocumentPojo> triggers);
|
||||
|
||||
DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse of(TableColumnDocumentPojo pojo,
|
||||
Integer discussionCount);
|
||||
Integer discussionCount,
|
||||
String description);
|
||||
|
||||
default List<DatabaseDocumentResponse.TableDocumentResponse.ColumnDocumentResponse> of(
|
||||
List<TableColumnDocumentPojo> columns,
|
||||
String tableName,
|
||||
Map<String, Integer> discussionCountMapByJoinName) {
|
||||
Map<String, Integer> discussionCountMapByJoinName,
|
||||
Map<String, String> descriptionMapByJoinName) {
|
||||
return columns.stream()
|
||||
.map(column -> {
|
||||
Integer count = discussionCountMapByJoinName.get(tableName + "." + column.getName());
|
||||
return of(column, count);
|
||||
String description = descriptionMapByJoinName.get(tableName + "." + column.getName());
|
||||
return of(column, count, description);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
@@ -21,14 +21,18 @@ public interface DocumentSimpleResponseConverter {
|
||||
DatabaseDocumentSimpleResponse of(DatabaseDocumentPojo databaseDocument,
|
||||
List<DatabaseDocumentSimpleResponse.TableData> tables);
|
||||
|
||||
DatabaseDocumentSimpleResponse.TableData of(TableDocumentPojo tables, Integer discussionCount);
|
||||
DatabaseDocumentSimpleResponse.TableData of(TableDocumentPojo tables,
|
||||
Integer discussionCount,
|
||||
String description);
|
||||
|
||||
default List<DatabaseDocumentSimpleResponse.TableData> of(List<TableDocumentPojo> tables,
|
||||
Map<String, Integer> discussionCountMapByTableName) {
|
||||
Map<String, Integer> discussionCountMapByTableName,
|
||||
Map<String, String> descriptionMapByTableName) {
|
||||
return tables.stream()
|
||||
.map(table -> {
|
||||
Integer count = discussionCountMapByTableName.get(table.getName());
|
||||
return of(table, count);
|
||||
String description = descriptionMapByTableName.get(table.getName());
|
||||
return of(table, count, description);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
@@ -48,6 +48,8 @@ public class DatabaseDocumentResponse {
|
||||
|
||||
private Integer discussionCount;
|
||||
|
||||
private String description;
|
||||
|
||||
@Builder.Default
|
||||
private List<ColumnDocumentResponse> columns = new ArrayList<>();
|
||||
|
||||
@@ -76,6 +78,8 @@ public class DatabaseDocumentResponse {
|
||||
|
||||
private String comment;
|
||||
|
||||
private String description;
|
||||
|
||||
private Boolean isPrimaryKey;
|
||||
|
||||
private String nullable;
|
||||
|
@@ -37,5 +37,7 @@ public class DatabaseDocumentSimpleResponse {
|
||||
private String comment;
|
||||
|
||||
private Integer discussionCount;
|
||||
|
||||
private String description;
|
||||
}
|
||||
}
|
||||
|
@@ -59,6 +59,8 @@ public class DocumentService {
|
||||
|
||||
private final DocumentDiscussionDao documentDiscussionDao;
|
||||
|
||||
private final DocumentDescriptionDao documentDescriptionDao;
|
||||
|
||||
private final DocumentPojoConverter documentPojoConverter;
|
||||
|
||||
private final DocumentResponseConverter documentResponseConverter;
|
||||
@@ -146,7 +148,15 @@ public class DocumentService {
|
||||
documentDiscussionDao.selectTableDiscussionCount(projectId)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(d -> d.getTableName(), d -> d.getCount(), (a, b) -> a));
|
||||
var tableMetas = documentSimpleResponseConverter.of(tables, discussionCountMapByTableName);
|
||||
Map<String, String> descriptionMapByTableName =
|
||||
documentDescriptionDao.selectTableDescriptionByProjectId(projectId)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(d -> d.getTableName(), d -> d.getContent(), (a, b) -> a));
|
||||
var tableMetas = documentSimpleResponseConverter.of(
|
||||
tables,
|
||||
discussionCountMapByTableName,
|
||||
descriptionMapByTableName
|
||||
);
|
||||
return documentSimpleResponseConverter.of(document, tableMetas);
|
||||
});
|
||||
}
|
||||
@@ -206,19 +216,26 @@ public class DocumentService {
|
||||
}
|
||||
var tables =
|
||||
tableDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
|
||||
// column
|
||||
var columns =
|
||||
tableColumnDocumentDao.selectByDatabaseDocumentIdAndTableIdIn(databaseDocumentId, tableIds);
|
||||
var indexes =
|
||||
tableIndexDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
|
||||
var triggers =
|
||||
tableTriggerDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
|
||||
var discussions = documentDiscussionDao.selectAllDiscussionCount(projectId);
|
||||
Map<Integer, List<TableColumnDocumentPojo>> columnsGroupByTableMetaId = columns.stream()
|
||||
.collect(Collectors.groupingBy(TableColumnDocumentPojo::getTableDocumentId));
|
||||
|
||||
// index
|
||||
var indexes =
|
||||
tableIndexDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
|
||||
Map<Integer, List<TableIndexDocumentPojo>> indexesGroupByTableMetaId = indexes.stream()
|
||||
.collect(Collectors.groupingBy(TableIndexDocumentPojo::getTableDocumentId));
|
||||
|
||||
// trigger
|
||||
var triggers =
|
||||
tableTriggerDocumentDao.selectByDatabaseDocumentIdAndIdIn(databaseDocumentId, tableIds);
|
||||
Map<Integer, List<TableTriggerDocumentPojo>> triggersGroupByTableMetaId = triggers.stream()
|
||||
.collect(Collectors.groupingBy(TableTriggerDocumentPojo::getTableDocumentId));
|
||||
|
||||
// discussion
|
||||
var discussions = documentDiscussionDao.selectAllDiscussionCount(projectId);
|
||||
Map<String, Integer> discussionCountMapByJoinName = discussions.stream()
|
||||
.collect(Collectors.toMap(
|
||||
d -> String.join(".",
|
||||
@@ -226,6 +243,17 @@ public class DocumentService {
|
||||
StringUtils.defaultIfBlank(d.getColumnName(), "")),
|
||||
DocumentDiscussionCountPojo::getCount,
|
||||
(a, b) -> a));
|
||||
|
||||
// description
|
||||
var descriptions = documentDescriptionDao.selectByProjectId(projectId);
|
||||
Map<String, String> descriptionMapByJoinName = descriptions.stream()
|
||||
.collect(Collectors.toMap(
|
||||
d -> String.join(".",
|
||||
d.getTableName(),
|
||||
StringUtils.defaultIfBlank(d.getColumnName(), "")),
|
||||
DocumentDescriptionPojo::getContent,
|
||||
(a, b) -> a));
|
||||
|
||||
return tables.stream()
|
||||
.map(table -> {
|
||||
Integer tableId = table.getId();
|
||||
@@ -233,9 +261,15 @@ public class DocumentService {
|
||||
var subIndexes = indexesGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
||||
var subTriggers = triggersGroupByTableMetaId.getOrDefault(tableId, Collections.emptyList());
|
||||
var discussionCount = discussionCountMapByJoinName.get(table.getName());
|
||||
var description = descriptionMapByJoinName.get(table.getName());
|
||||
var columnResponses =
|
||||
documentResponseConverter.of(subColumns, table.getName(), discussionCountMapByJoinName);
|
||||
return documentResponseConverter.of(table, discussionCount, columnResponses, subIndexes,
|
||||
documentResponseConverter.of(
|
||||
subColumns,
|
||||
table.getName(),
|
||||
discussionCountMapByJoinName,
|
||||
descriptionMapByJoinName);
|
||||
return documentResponseConverter.of(table, discussionCount, description, columnResponses,
|
||||
subIndexes,
|
||||
subTriggers);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
Reference in New Issue
Block a user