mirror of
https://github.com/vran-dev/databasir.git
synced 2025-09-19 10:16:58 +08:00
feat: update frontend resources
This commit is contained in:
@@ -1,2 +1,21 @@
|
||||
package com.databasir.core.domain.description.event;public class DescriptionUpdated {
|
||||
package com.databasir.core.domain.description.event;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class DescriptionUpdated {
|
||||
|
||||
private Integer groupId;
|
||||
|
||||
private Integer projectId;
|
||||
|
||||
private Integer userId;
|
||||
|
||||
private String tableName;
|
||||
|
||||
private String columnName;
|
||||
|
||||
private String description;
|
||||
}
|
||||
|
@@ -2,6 +2,8 @@ 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.core.domain.description.event.DescriptionUpdated;
|
||||
import com.databasir.core.infrastructure.event.EventPublisher;
|
||||
import com.databasir.dao.impl.DocumentDescriptionDao;
|
||||
import com.databasir.dao.tables.pojos.DocumentDescriptionPojo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -16,6 +18,8 @@ public class DocumentDescriptionService {
|
||||
|
||||
private final DocumentDescriptionPojoConverter documentDescriptionPojoConverter;
|
||||
|
||||
private final EventPublisher eventPublisher;
|
||||
|
||||
@Transactional
|
||||
public void save(Integer groupId,
|
||||
Integer projectId,
|
||||
@@ -28,5 +32,14 @@ public class DocumentDescriptionService {
|
||||
} else {
|
||||
documentDescriptionDao.update(pojo);
|
||||
}
|
||||
DescriptionUpdated event = DescriptionUpdated.builder()
|
||||
.tableName(request.getTableName())
|
||||
.columnName(request.getColumnName())
|
||||
.description(request.getContent())
|
||||
.userId(userId)
|
||||
.projectId(projectId)
|
||||
.groupId(groupId)
|
||||
.build();
|
||||
eventPublisher.publish(event);
|
||||
}
|
||||
}
|
||||
|
@@ -32,5 +32,7 @@ public interface DocumentFullTextPojoConverter {
|
||||
ProjectPojo project,
|
||||
DatabaseDocumentPojo db,
|
||||
TableDocumentPojo table,
|
||||
TableColumnDocumentPojo column);
|
||||
TableColumnDocumentPojo column,
|
||||
String tableDescription,
|
||||
String columnDescription);
|
||||
}
|
||||
|
@@ -211,7 +211,20 @@ public class DocumentService {
|
||||
tableTriggerDocumentDao.batchInsert(triggers);
|
||||
|
||||
// save full text
|
||||
saveDocumentFullText(projectId, dbDocPojo, tableMeta);
|
||||
var descriptionMapByJoinName = documentDescriptionDao.selectByProjectId(projectId)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(
|
||||
d -> {
|
||||
if (d.getColumnName() == null) {
|
||||
return d.getTableName();
|
||||
}
|
||||
return String.join(".",
|
||||
d.getTableName(),
|
||||
StringUtils.defaultIfBlank(d.getColumnName(), ""));
|
||||
},
|
||||
DocumentDescriptionPojo::getContent,
|
||||
(a, b) -> a));
|
||||
saveDocumentFullText(projectId, dbDocPojo, tableMeta, descriptionMapByJoinName);
|
||||
});
|
||||
log.info("save new version document success: projectId = {}, name = {}, version = {}",
|
||||
projectId, meta.getDatabaseName(), version);
|
||||
@@ -219,14 +232,21 @@ public class DocumentService {
|
||||
|
||||
private void saveDocumentFullText(Integer projectId,
|
||||
DatabaseDocumentPojo database,
|
||||
TableDocumentPojo table) {
|
||||
TableDocumentPojo table,
|
||||
Map<String, String> descriptionMapByJoinName) {
|
||||
ProjectPojo project = projectDao.selectById(projectId);
|
||||
GroupPojo group = groupDao.selectById(project.getGroupId());
|
||||
List<TableColumnDocumentPojo> columns = tableColumnDocumentDao.selectByTableDocumentId(table.getId());
|
||||
// clear outdated data before save
|
||||
documentFullTextDao.deleteByTableId(table.getId());
|
||||
List<DocumentFullTextPojo> fullTextPojoList = columns.stream()
|
||||
.map(column -> documentFullTextPojoConverter.toPojo(group, project, database, table, column))
|
||||
.map(column -> {
|
||||
String tableName = table.getName();
|
||||
String tableDescription = descriptionMapByJoinName.get(tableName);
|
||||
String columnDescription = descriptionMapByJoinName.get(tableName + "." + column.getName());
|
||||
return documentFullTextPojoConverter.toPojo(group, project, database, table, column,
|
||||
tableDescription, columnDescription);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
documentFullTextDao.batchInsert(fullTextPojoList);
|
||||
}
|
||||
|
@@ -55,10 +55,14 @@ public class SearchResponse {
|
||||
|
||||
private String tableComment;
|
||||
|
||||
private String tableDescription;
|
||||
|
||||
private String colName;
|
||||
|
||||
private String colComment;
|
||||
|
||||
private String colDescription;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,2 +1,36 @@
|
||||
package com.databasir.core.infrastructure.event.subscriber;public class DescriptionEventSubscriber {
|
||||
package com.databasir.core.infrastructure.event.subscriber;
|
||||
|
||||
import com.databasir.core.domain.description.event.DescriptionUpdated;
|
||||
import com.databasir.dao.impl.DocumentFullTextDao;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class DescriptionEventSubscriber {
|
||||
|
||||
private final DocumentFullTextDao documentFullTextDao;
|
||||
|
||||
@EventListener(classes = DescriptionUpdated.class)
|
||||
public void refreshDocumentFullText(DescriptionUpdated event) {
|
||||
if (event.getColumnName() != null) {
|
||||
// update column description
|
||||
int result = documentFullTextDao.updateColumnDescription(event.getGroupId(),
|
||||
event.getProjectId(),
|
||||
event.getTableName(),
|
||||
event.getColumnName(),
|
||||
event.getDescription());
|
||||
log.info("update column description full text success by event {}, effect rows {}", event, result);
|
||||
} else {
|
||||
// update table description
|
||||
int result = documentFullTextDao.updateTableDescription(event.getGroupId(),
|
||||
event.getProjectId(),
|
||||
event.getTableName(),
|
||||
event.getDescription());
|
||||
log.info("update table description full text success by event {}, effect rows {}", event, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user