作者 tangxvhui
@@ -3,6 +3,8 @@ package comment @@ -3,6 +3,8 @@ package comment
3 import ( 3 import (
4 "context" 4 "context"
5 5
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
  7 +
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
@@ -83,18 +85,18 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -83,18 +85,18 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
83 } 85 }
84 } 86 }
85 var atWhoList []*domain.User 87 var atWhoList []*domain.User
  88 + var atWhoIds = make([]int64, 0)
86 if len(req.AtWho) > 0 { 89 if len(req.AtWho) > 0 {
87 - uids := []int64{}  
88 for _, val := range req.AtWho { 90 for _, val := range req.AtWho {
89 - uids = append(uids, val.Id) 91 + atWhoIds = append(atWhoIds, val.Id)
90 } 92 }
91 - uids = lo.Uniq(uids)  
92 - queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", uids) 93 + atWhoIds = lo.Uniq(atWhoIds)
  94 + queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", atWhoIds)
93 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption) 95 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
94 if err != nil { 96 if err != nil {
95 return nil, xerr.NewErrMsgErr("检查@的人员失败", err) 97 return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
96 } 98 }
97 - if len(uids) != len(atWhoList) { 99 + if len(atWhoIds) != len(atWhoList) {
98 return nil, xerr.NewErrMsg("检查@的人员失败") 100 return nil, xerr.NewErrMsg("检查@的人员失败")
99 } 101 }
100 } 102 }
@@ -187,6 +189,21 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -187,6 +189,21 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
187 return err 189 return err
188 } 190 }
189 } 191 }
  192 +
  193 + // 创建回复消息
  194 + var atAllIds = make([]int64, 0)
  195 + atAllIds = append(atAllIds, newComment.ToUserId)
  196 + atAllIds = append(atAllIds, atWhoIds...)
  197 + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
  198 + if pComment != nil {
  199 + err = messageLogic.CommentReply(c, pComment.ArticleId, pComment.SectionId, pComment.Id, req.Content, atAllIds) // 对评论回复
  200 + } else {
  201 + err = messageLogic.CommentArticle(c, req.ArtitcleId, req.SectionId, req.Content, atAllIds) // 对文章回复
  202 + }
  203 + if err != nil {
  204 + return err
  205 + }
  206 +
190 return nil 207 return nil
191 }, true) 208 }, true)
192 209
@@ -207,23 +207,23 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -207,23 +207,23 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
207 } 207 }
208 208
209 // CommentArticle 评论文章 209 // CommentArticle 评论文章
210 -func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, content string, at []int64) (err error) {  
211 - return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, 0, content, at) 210 +func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, sectionId int64, content string, at []int64) (err error) {
  211 + return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, sectionId, 0, content, at)
212 } 212 }
213 213
214 // CommentReply 评论回复 214 // CommentReply 评论回复
215 -func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, content string, at []int64) (err error) {  
216 - return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, content, at) 215 +func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, content string, at []int64) (err error) {
  216 + return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, sectionId, commentId, content, at)
217 } 217 }
218 218
219 // LikeArticle 点赞文章 219 // LikeArticle 点赞文章
220 func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) { 220 func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) {
221 - return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, "", []int64{at}) 221 + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, 0, "", []int64{at})
222 } 222 }
223 223
224 // LikeComment 点赞评论 224 // LikeComment 点赞评论
225 -func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {  
226 - return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, "", []int64{at}) 225 +func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, at int64) (err error) {
  226 + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, sectionId, commentId, "", []int64{at})
227 } 227 }
228 228
229 func (l *MiniBusinessLogic) createMessage( 229 func (l *MiniBusinessLogic) createMessage(
@@ -231,6 +231,7 @@ func (l *MiniBusinessLogic) createMessage( @@ -231,6 +231,7 @@ func (l *MiniBusinessLogic) createMessage(
231 msgType domain.MsgBusinessType, 231 msgType domain.MsgBusinessType,
232 optType domain.MsgBusinessOpt, 232 optType domain.MsgBusinessOpt,
233 articleId int64, 233 articleId int64,
  234 + sectionId int64,
234 commentId int64, 235 commentId int64,
235 content string, 236 content string,
236 at []int64) (err error) { 237 at []int64) (err error) {
@@ -245,6 +246,7 @@ func (l *MiniBusinessLogic) createMessage( @@ -245,6 +246,7 @@ func (l *MiniBusinessLogic) createMessage(
245 UserId: userToken.UserId, 246 UserId: userToken.UserId,
246 RecipientId: at[i], 247 RecipientId: at[i],
247 ArticleId: articleId, 248 ArticleId: articleId,
  249 + SectionId: sectionId,
248 CommentId: commentId, 250 CommentId: commentId,
249 Content: content, 251 Content: content,
250 } 252 }
@@ -17,6 +17,7 @@ type MessageBusiness struct { @@ -17,6 +17,7 @@ type MessageBusiness struct {
17 UserId int64 `json:"userId"` // 操作人用户ID 17 UserId int64 `json:"userId"` // 操作人用户ID
18 RecipientId int64 `json:"recipientId"` // 接收人用户ID 18 RecipientId int64 `json:"recipientId"` // 接收人用户ID
19 ArticleId int64 `json:"articleId,omitempty"` // 文章ID 19 ArticleId int64 `json:"articleId,omitempty"` // 文章ID
  20 + SectionId int64 `json:"sectionId,omitempty"` // 段落ID
20 CommentId int64 `json:"commentId,omitempty"` // 评论ID 21 CommentId int64 `json:"commentId,omitempty"` // 评论ID
21 Content string `json:"content,omitempty"` // 消息内容 22 Content string `json:"content,omitempty"` // 消息内容
22 CreatedAt int64 `json:",omitempty"` 23 CreatedAt int64 `json:",omitempty"`
@@ -13,6 +13,7 @@ type MessageBusiness struct { @@ -13,6 +13,7 @@ type MessageBusiness struct {
13 UserId int64 `json:"userId"` // 操作人用户ID 13 UserId int64 `json:"userId"` // 操作人用户ID
14 RecipientId int64 `json:"recipientId"` // 接收人用户ID 14 RecipientId int64 `json:"recipientId"` // 接收人用户ID
15 ArticleId int64 `json:"articleId"` // 文章ID 15 ArticleId int64 `json:"articleId"` // 文章ID
  16 + SectionId int64 `json:"sectionId"` // 段落ID
16 CommentId int64 `json:"commentId"` // 评论ID 17 CommentId int64 `json:"commentId"` // 评论ID
17 Content string `json:"content"` // 消息内容 18 Content string `json:"content"` // 消息内容
18 CreatedAt int64 `json:",omitempty"` 19 CreatedAt int64 `json:",omitempty"`
@@ -35,7 +36,7 @@ const ( @@ -35,7 +36,7 @@ const (
35 36
36 const ( 37 const (
37 OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章 38 OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章
38 - OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论 39 + OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论()
39 OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论 40 OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论
40 ) 41 )
41 42