From 40c397f8e5f3c50004f557384e3888623b15c4f4 Mon Sep 17 00:00:00 2001 From: truthhun <1272881215@qq.com> Date: Mon, 6 May 2024 15:21:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E6=A1=A3=E8=BD=AC=E6=8D=A2,=E5=A6=82?= =?UTF-8?q?=E6=9E=9C=E5=B7=B2=E5=AD=98=E5=9C=A8=E6=91=98=E8=A6=81,?= =?UTF-8?q?=E5=88=99=E4=B8=8D=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/document.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/model/document.go b/model/document.go index 78393fe..df1565c 100644 --- a/model/document.go +++ b/model/document.go @@ -626,6 +626,9 @@ func (m *DBModel) ConvertDocument() (err error) { defer func() { m.SetDocumentConvertError(document.Id, err) }() + + document.Description = strings.TrimSpace(document.Description) + // 文档转为PDF cfg := m.GetConfigOfConverter() m.SetDocumentStatus([]int64{document.Id}, DocumentStatusConverting) @@ -652,6 +655,9 @@ func (m *DBModel) ConvertDocument() (err error) { sql := " UPDATE `%s` SET `description`= ? , `enable_gzip` = ?, `width` = ?, `height`= ?, `preview`= ?, `pages` = ?, `status` = ? WHERE status in ? and id in (select type_id from `%s` where `hash` = ? and `type` = ?)" sql = fmt.Sprintf(sql, Document{}.TableName(), Attachment{}.TableName()) for hash, doc := range hashMapDocs { + if document.Description != "" { + doc.Description = document.Description + } err = m.db.Exec(sql, doc.Description, doc.EnableGZIP, doc.Width, doc.Height, doc.Preview, doc.Pages, DocumentStatusConverted, []int{DocumentStatusPending, DocumentStatusConverting, DocumentStatusFailed}, hash, AttachmentTypeDocument, ).Error @@ -748,15 +754,17 @@ func (m *DBModel) ConvertDocument() (err error) { m.logger.Error("ConvertPDFToTxt", zap.Error(errPdf2text)) } - // 读取文本内容,以提取关键字和摘要 - if content, errRead := os.ReadFile(textFile); errRead == nil { - contentStr := string(content) - replacer := strings.NewReplacer("\r", " ", "\n", " ", "\t", " ") - contentStr = strings.TrimSpace(replacer.Replace(contentStr)) - if errContent := m.SetAttachmentContentByType(AttachmentTypeDocument, document.Id, []byte(contentStr)); errContent != nil { - m.logger.Error("SetAttachmentContentByType", zap.Error(errContent)) + if document.Description == "" { + // 读取文本内容,以提取关键字和摘要 + if content, errRead := os.ReadFile(textFile); errRead == nil { + contentStr := string(content) + replacer := strings.NewReplacer("\r", " ", "\n", " ", "\t", " ") + contentStr = strings.TrimSpace(replacer.Replace(contentStr)) + if errContent := m.SetAttachmentContentByType(AttachmentTypeDocument, document.Id, []byte(contentStr)); errContent != nil { + m.logger.Error("SetAttachmentContentByType", zap.Error(errContent)) + } + document.Description = util.Substr(contentStr, 255) } - document.Description = util.Substr(contentStr, 255) } document.Status = DocumentStatusConverted