|
|
@@ -61,7 +61,10 @@ public class StructuredDocumentService {
|
|
|
// 5. 获取图片列表
|
|
|
List<ImageDTO> images = buildImageList(documentId);
|
|
|
|
|
|
- // 6. 获取段落列表(包含格式信息)
|
|
|
+ // 6. 获取表格列表
|
|
|
+ List<StructuredDocumentDTO.TableDTO> tables = buildTableList(documentId);
|
|
|
+
|
|
|
+ // 7. 获取段落列表(包含格式信息)
|
|
|
List<StructuredDocumentDTO.ParagraphDTO> paragraphs = buildParagraphList(documentId);
|
|
|
|
|
|
return StructuredDocumentDTO.builder()
|
|
|
@@ -71,6 +74,7 @@ public class StructuredDocumentService {
|
|
|
.status(document.getStatus())
|
|
|
.blocks(blockDTOs)
|
|
|
.images(images)
|
|
|
+ .tables(tables)
|
|
|
.paragraphs(paragraphs)
|
|
|
.entityStats(stats)
|
|
|
.updatedAt(document.getUpdateTime())
|
|
|
@@ -95,6 +99,78 @@ public class StructuredDocumentService {
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 构建表格列表(从 document_elements 表获取)
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private List<StructuredDocumentDTO.TableDTO> buildTableList(String documentId) {
|
|
|
+ List<DocumentElement> tableElements = documentElementService.getTablesByDocumentId(documentId);
|
|
|
+
|
|
|
+ return tableElements.stream()
|
|
|
+ .map(this::convertToTableDTO)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将 DocumentElement 转换为 TableDTO
|
|
|
+ */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private StructuredDocumentDTO.TableDTO convertToTableDTO(DocumentElement el) {
|
|
|
+ List<List<StructuredDocumentDTO.TableCellDTO>> rowDTOs = new ArrayList<>();
|
|
|
+
|
|
|
+ if (el.getTableData() != null) {
|
|
|
+ for (Object rowObj : el.getTableData()) {
|
|
|
+ List<StructuredDocumentDTO.TableCellDTO> cellDTOs = new ArrayList<>();
|
|
|
+
|
|
|
+ if (rowObj instanceof List) {
|
|
|
+ List<?> row = (List<?>) rowObj;
|
|
|
+ for (Object cellObj : row) {
|
|
|
+ if (cellObj instanceof Map) {
|
|
|
+ Map<String, Object> cell = (Map<String, Object>) cellObj;
|
|
|
+
|
|
|
+ // 转换 runs
|
|
|
+ List<StructuredDocumentDTO.TextRunDTO> runDTOs = null;
|
|
|
+ Object runsObj = cell.get("runs");
|
|
|
+ if (runsObj instanceof List) {
|
|
|
+ runDTOs = ((List<Map<String, Object>>) runsObj).stream()
|
|
|
+ .map(run -> StructuredDocumentDTO.TextRunDTO.builder()
|
|
|
+ .text((String) run.get("text"))
|
|
|
+ .fontFamily((String) run.get("fontFamily"))
|
|
|
+ .fontSize(run.get("fontSize") instanceof Number ? ((Number) run.get("fontSize")).doubleValue() : null)
|
|
|
+ .bold((Boolean) run.get("bold"))
|
|
|
+ .italic((Boolean) run.get("italic"))
|
|
|
+ .underline((String) run.get("underline"))
|
|
|
+ .color((String) run.get("color"))
|
|
|
+ .strikeThrough((Boolean) run.get("strikeThrough"))
|
|
|
+ .verticalAlign((String) run.get("verticalAlign"))
|
|
|
+ .highlightColor((String) run.get("highlightColor"))
|
|
|
+ .build())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ cellDTOs.add(StructuredDocumentDTO.TableCellDTO.builder()
|
|
|
+ .text((String) cell.get("text"))
|
|
|
+ .rowSpan(cell.get("rowSpan") instanceof Number ? ((Number) cell.get("rowSpan")).intValue() : null)
|
|
|
+ .colSpan(cell.get("colSpan") instanceof Number ? ((Number) cell.get("colSpan")).intValue() : null)
|
|
|
+ .style((Map<String, Object>) cell.get("style"))
|
|
|
+ .runs(runDTOs)
|
|
|
+ .build());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ rowDTOs.add(cellDTOs);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return StructuredDocumentDTO.TableDTO.builder()
|
|
|
+ .index(el.getElementIndex())
|
|
|
+ .rowCount(el.getTableRowCount())
|
|
|
+ .colCount(el.getTableColCount())
|
|
|
+ .rows(rowDTOs)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 构建段落列表(从 document_elements 表获取,包含格式信息)
|
|
|
*/
|