|
@@ -19,7 +19,7 @@ import (
|
|
|
// @param reportId int
|
|
|
// @param reportChapterId int
|
|
|
func ReportAddOrModifyKnowledge(reportId, reportChapterId int) {
|
|
|
- if reportId <= 0 && reportChapterId <= 0 {
|
|
|
+ if reportId <= 0 {
|
|
|
return
|
|
|
}
|
|
|
var err error
|
|
@@ -53,6 +53,69 @@ func ReportAddOrModifyKnowledge(reportId, reportChapterId int) {
|
|
|
htmlContent = reportInfo.Content
|
|
|
}
|
|
|
|
|
|
+ err = handleReportAddOrModifyKnowledge(reportId, reportChapterId, title, author, htmlContent, publishTime)
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// ReportAddOrModifyKnowledgeByReportId
|
|
|
+// @Description: ETA报告加入/修改到知识库(只传id的情况)
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2025-04-07 15:41:15
|
|
|
+// @param reportId int
|
|
|
+func ReportAddOrModifyKnowledgeByReportId(reportId int) {
|
|
|
+ if reportId <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ errList := make([]string, 0)
|
|
|
+ defer func() {
|
|
|
+ if len(errList) > 0 {
|
|
|
+ utils.FileLog.Error("ReportAddOrModifyKnowledge error,报告ID:%d:%s", reportId, strings.Join(errList, "\n"))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ reportInfo, err := models.GetReportByReportId(reportId)
|
|
|
+ if err != nil {
|
|
|
+ errList = append(errList, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果是单篇报告,那么直接处理
|
|
|
+ if reportInfo.HasChapter == 0 {
|
|
|
+ err = handleReportAddOrModifyKnowledge(reportId, 0, reportInfo.Title, reportInfo.Author, reportInfo.Content, reportInfo.PublishTime)
|
|
|
+ errList = append(errList, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 章节类型的报告,需要查询出来后再处理
|
|
|
+ chapterInfoList, err := models.GetPublishedChapterListByReportId(reportId)
|
|
|
+ if err != nil {
|
|
|
+ errList = append(errList, err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ for _, v := range chapterInfoList {
|
|
|
+ err = handleReportAddOrModifyKnowledge(reportId, v.ReportChapterId, v.Title, v.Author, v.Content, reportInfo.PublishTime)
|
|
|
+ if err != nil {
|
|
|
+ errList = append(errList, fmt.Sprintf("第%d章:%s,异常:\n%s", v.ReportChapterId, v.Title, err.Error()))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// handleReportAddOrModifyKnowledge
|
|
|
+// @Description: 处理ETA报告加入/修改到知识库
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2025-04-07 15:33:38
|
|
|
+// @param reportId int
|
|
|
+// @param reportChapterId int
|
|
|
+// @param title string
|
|
|
+// @param author string
|
|
|
+// @param htmlContent string
|
|
|
+// @param publishTime time.Time
|
|
|
+// @return err error
|
|
|
+func handleReportAddOrModifyKnowledge(reportId, reportChapterId int, title, author, htmlContent string, publishTime time.Time) (err error) {
|
|
|
htmlContent = html.UnescapeString(htmlContent)
|
|
|
doc, err := html.Parse(strings.NewReader(htmlContent))
|
|
|
if err != nil {
|
|
@@ -149,6 +212,39 @@ func ReportUnPublishedKnowledge(reportId, reportChapterId int) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// ReportUnPublishedKnowledgeByReportId
|
|
|
+// @Description: ETA报告取消发布同步到知识库(只传报告id的情况)
|
|
|
+// @author: Roc
|
|
|
+// @datetime 2025-04-07 15:41:15
|
|
|
+// @param reportId int
|
|
|
+func ReportUnPublishedKnowledgeByReportId(reportId int) {
|
|
|
+ errList := make([]string, 0)
|
|
|
+ defer func() {
|
|
|
+ if len(errList) > 0 {
|
|
|
+ utils.FileLog.Error("ReportUnPublishedKnowledgeByReportId error,报告ID:%d:%s", reportId, strings.Join(errList, "\n"))
|
|
|
+ }
|
|
|
+ }()
|
|
|
+
|
|
|
+ obj := rag.RagEtaReport{}
|
|
|
+ list, err := obj.GetListByCondition(``, ` AND report_id = ? `, []interface{}{reportId}, 0, 1000)
|
|
|
+ if err != nil && !utils.IsErrNoRow(err) {
|
|
|
+ // 查询异常,且不是没找到数据的报错
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, item := range list {
|
|
|
+ item.IsPublished = 0
|
|
|
+ item.ModifyTime = time.Now()
|
|
|
+ err = item.Update([]string{"is_published", "modify_time"})
|
|
|
+ if err != nil {
|
|
|
+ errList = append(errList, fmt.Sprintf("第%d章:%s,异常:\n%s", item.ReportChapterId, item.Title, err.Error()))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func getArticleContent(content *strings.Builder, htmlContentNode *html.Node) {
|
|
|
if htmlContentNode.Type == html.TextNode {
|
|
|
cleanData := strings.TrimSpace(htmlContentNode.Data)
|