From 99d64c0e3da9acb43726a9e3c06cdf186a689fef Mon Sep 17 00:00:00 2001 From: truthhun <1272881215@qq.com> Date: Thu, 18 May 2023 21:50:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E5=8A=A8?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- biz/document.go | 7 +++++++ model/comment.go | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/biz/document.go b/biz/document.go index c521ade..6da8abe 100644 --- a/biz/document.go +++ b/biz/document.go @@ -3,6 +3,7 @@ package biz import ( "context" "fmt" + "html" "net/url" "os" "path/filepath" @@ -701,6 +702,12 @@ func (s *DocumentAPIService) DownloadDocument(ctx context.Context, req *pb.Docum return res, status.Errorf(codes.Internal, "创建下载失败:%s", err.Error()) } + s.dbModel.CreateDynamic(&model.Dynamic{ + UserId: userId, + Type: model.DynamicTypeDownload, + Content: fmt.Sprintf(`下载了文档《%s》`, doc.Id, html.EscapeString(doc.Title)), + }) + link, err := s.generateDownloadURL(doc, cfg, attachment.Hash) if err != nil { return res, status.Errorf(codes.Internal, "生成下载地址失败:%s", err.Error()) diff --git a/model/comment.go b/model/comment.go index dee927a..79fd7d1 100644 --- a/model/comment.go +++ b/model/comment.go @@ -4,6 +4,8 @@ import ( // "fmt" // "strings" "errors" + "fmt" + "html" "strings" "time" @@ -36,6 +38,9 @@ func (Comment) TableName() string { // CreateComment 创建Comment func (m *DBModel) CreateComment(comment *Comment) (err error) { + doc := &Document{} + m.db.Where("id = ?", comment.DocumentId).Select("id", "title").Find(doc) + tx := m.db.Begin() defer func() { if err != nil { @@ -65,6 +70,10 @@ func (m *DBModel) CreateComment(comment *Comment) (err error) { return } + dynamic := &Dynamic{ + UserId: comment.UserId, + Type: DynamicTypeComment, + } // 更新上级评论的评论数 if comment.ParentId > 0 { err = tx.Model(&Comment{}).Where("id = ?", comment.ParentId).Update("comment_count", gorm.Expr("comment_count + ?", 1)).Error @@ -72,6 +81,15 @@ func (m *DBModel) CreateComment(comment *Comment) (err error) { m.logger.Error("CreateComment", zap.Error(err)) return } + dynamic.Content = fmt.Sprintf(`在文档《%s》中回复了评论`, doc.Id, html.EscapeString(doc.Title)) + } else { + dynamic.Content = fmt.Sprintf(`评论了文档《%s》`, doc.Id, html.EscapeString(doc.Title)) + } + + // 增加评论动态 + err = tx.Create(dynamic).Error + if err != nil { + m.logger.Error("CreateComment", zap.Error(err)) } return