2
This commit is contained in:
@@ -91,10 +91,6 @@ func (r *DatabaseTableReader) ReadTableFromDocumentation(ctx context.Context, do
|
||||
}
|
||||
|
||||
// 如果不是JSON格式,先解析为markdown表格,然后转换为JSON格式
|
||||
r.logger.Info("开始解析markdown表格并转换为JSON",
|
||||
zap.String("field_type", fieldType),
|
||||
zap.Int("content_length", len(content)),
|
||||
zap.String("content_preview", r.getContentPreview(content, 200)))
|
||||
|
||||
tableData, err := r.parseMarkdownTable(content)
|
||||
if err != nil {
|
||||
@@ -102,20 +98,10 @@ func (r *DatabaseTableReader) ReadTableFromDocumentation(ctx context.Context, do
|
||||
return nil, fmt.Errorf("解析markdown表格失败: %w", err)
|
||||
}
|
||||
|
||||
r.logger.Info("markdown表格解析成功",
|
||||
zap.String("field_type", fieldType),
|
||||
zap.Int("header_count", len(tableData.Headers)),
|
||||
zap.Int("row_count", len(tableData.Rows)),
|
||||
zap.Strings("headers", tableData.Headers))
|
||||
|
||||
// 将markdown表格数据转换为JSON格式(保持列顺序)
|
||||
r.logger.Debug("开始将表格数据转换为JSON格式", zap.String("field_type", fieldType))
|
||||
jsonArray = r.convertTableDataToJSON(tableData)
|
||||
|
||||
r.logger.Info("表格数据已转换为JSON格式",
|
||||
zap.String("field_type", fieldType),
|
||||
zap.Int("json_array_length", len(jsonArray)))
|
||||
|
||||
// 记录转换后的JSON(用于调试)
|
||||
jsonBytes, marshalErr := json.MarshalIndent(jsonArray, "", " ")
|
||||
if marshalErr != nil {
|
||||
@@ -422,9 +408,6 @@ func (r *DatabaseTableReader) parseMarkdownTablesWithTitles(content string) ([]T
|
||||
return nil, fmt.Errorf("无法解析表格:未找到表头")
|
||||
}
|
||||
|
||||
r.logger.Info("解析多个表格完成",
|
||||
zap.Int("table_count", len(result)))
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -31,11 +31,6 @@ func (r *DatabaseTableRenderer) RenderTable(pdf *gofpdf.Fpdf, tableData *TableDa
|
||||
return nil
|
||||
}
|
||||
|
||||
r.logger.Info("开始渲染表格",
|
||||
zap.Int("header_count", len(tableData.Headers)),
|
||||
zap.Int("row_count", len(tableData.Rows)),
|
||||
zap.Strings("headers", tableData.Headers))
|
||||
|
||||
// 检查表头是否有有效内容
|
||||
hasValidHeader := false
|
||||
for _, header := range tableData.Headers {
|
||||
@@ -109,11 +104,6 @@ func (r *DatabaseTableRenderer) RenderTable(pdf *gofpdf.Fpdf, tableData *TableDa
|
||||
r.logger.Debug("没有数据行,只渲染表头")
|
||||
}
|
||||
|
||||
r.logger.Info("表格渲染完成",
|
||||
zap.Int("header_count", len(tableData.Headers)),
|
||||
zap.Int("row_count", len(tableData.Rows)),
|
||||
zap.Float64("current_y", pdf.GetY()))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -216,9 +216,21 @@ func (fm *FontManager) buildFontPaths(fontNames []string) []string {
|
||||
}
|
||||
}
|
||||
|
||||
// 只记录关键错误
|
||||
// 只记录关键错误,并显示调试信息
|
||||
if len(existingFonts) == 0 {
|
||||
fm.logger.Warn("未找到字体文件", zap.Strings("font_names", fontNames))
|
||||
workDir, _ := os.Getwd()
|
||||
execPath, _ := os.Executable()
|
||||
fm.logger.Warn("未找到字体文件",
|
||||
zap.Strings("font_names", fontNames),
|
||||
zap.String("work_dir", workDir),
|
||||
zap.String("exec_path", execPath),
|
||||
zap.String("base_dir", fm.baseDir),
|
||||
zap.String("first_tried_path", func() string {
|
||||
if len(fontPaths) > 0 {
|
||||
return fontPaths[0]
|
||||
}
|
||||
return "none"
|
||||
}()))
|
||||
}
|
||||
|
||||
return existingFonts
|
||||
|
||||
@@ -266,8 +266,6 @@ func (pb *PageBuilder) AddDocumentationPages(pdf *gofpdf.Fpdf, doc *entities.Pro
|
||||
} else {
|
||||
pb.logger.Warn("返回字段内容为空或只有空白字符")
|
||||
}
|
||||
} else {
|
||||
pb.logger.Info("返回字段说明表格渲染成功")
|
||||
}
|
||||
} else {
|
||||
pb.logger.Debug("返回字段内容为空,跳过渲染")
|
||||
|
||||
@@ -132,11 +132,6 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
|
||||
}
|
||||
}()
|
||||
|
||||
g.logger.Info("开始生成PDF",
|
||||
zap.String("product_id", product.ID),
|
||||
zap.String("product_name", product.Name),
|
||||
zap.Bool("has_doc", doc != nil),
|
||||
)
|
||||
|
||||
// 创建PDF文档 (A4大小,gofpdf v2 默认支持UTF-8)
|
||||
pdf := gofpdf.New("P", "mm", "A4", "")
|
||||
@@ -154,27 +149,19 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
|
||||
pdf.SetAuthor("TYAPI Server", true)
|
||||
pdf.SetCreator("TYAPI Server", true)
|
||||
|
||||
g.logger.Info("PDF文档基本信息设置完成")
|
||||
|
||||
// 创建页面构建器
|
||||
pageBuilder := NewPageBuilder(g.logger, g.fontManager, g.textProcessor, g.markdownProc, g.tableParser, g.tableRenderer, g.jsonProcessor, g.logoPath, g.watermarkText)
|
||||
|
||||
// 添加第一页(产品信息)
|
||||
g.logger.Info("开始添加第一页")
|
||||
pageBuilder.AddFirstPage(pdf, product, doc, chineseFontAvailable)
|
||||
g.logger.Info("第一页添加完成")
|
||||
|
||||
// 如果有关联的文档,添加接口文档页面
|
||||
if doc != nil {
|
||||
g.logger.Info("开始添加文档页面")
|
||||
pageBuilder.AddDocumentationPages(pdf, doc, chineseFontAvailable)
|
||||
g.logger.Info("文档页面添加完成")
|
||||
} else {
|
||||
g.logger.Info("没有文档信息,跳过文档页面")
|
||||
}
|
||||
|
||||
// 生成PDF字节流
|
||||
g.logger.Info("开始生成PDF字节流")
|
||||
var buf bytes.Buffer
|
||||
err = pdf.Output(&buf)
|
||||
if err != nil {
|
||||
@@ -183,10 +170,6 @@ func (g *PDFGeneratorRefactored) generatePDF(product *entities.Product, doc *ent
|
||||
}
|
||||
|
||||
pdfBytes := buf.Bytes()
|
||||
g.logger.Info("PDF生成成功",
|
||||
zap.String("product_id", product.ID),
|
||||
zap.Int("pdf_size", len(pdfBytes)),
|
||||
)
|
||||
|
||||
return pdfBytes, nil
|
||||
}
|
||||
|
||||
@@ -60,11 +60,6 @@ func (tp *TableParser) ParseAndRenderTable(ctx context.Context, pdf *gofpdf.Fpdf
|
||||
return nil
|
||||
}
|
||||
|
||||
tp.logger.Info("准备渲染表格",
|
||||
zap.String("field_type", fieldType),
|
||||
zap.Int("header_count", len(tableData.Headers)),
|
||||
zap.Int("row_count", len(tableData.Rows)),
|
||||
zap.Float64("pdf_current_y", pdf.GetY()))
|
||||
|
||||
// 渲染表格到PDF
|
||||
if err := tp.databaseRenderer.RenderTable(pdf, tableData); err != nil {
|
||||
@@ -72,9 +67,6 @@ func (tp *TableParser) ParseAndRenderTable(ctx context.Context, pdf *gofpdf.Fpdf
|
||||
return fmt.Errorf("渲染表格失败: %w", err)
|
||||
}
|
||||
|
||||
tp.logger.Info("表格渲染成功",
|
||||
zap.String("field_type", fieldType),
|
||||
zap.Float64("pdf_final_y", pdf.GetY()))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user