作者 郑周

1. 消息列表 系统消息 增加逻辑

@@ -207,25 +207,25 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -207,25 +207,25 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
207 207
208 // CommentArticle 评论文章 208 // CommentArticle 评论文章
209 func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, content string, at []int64) (err error) { 209 func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, content string, at []int64) (err error) {
210 - return l.submit(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, 0, content, at) 210 + return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, 0, content, at)
211 } 211 }
212 212
213 // CommentReply 评论回复 213 // CommentReply 评论回复
214 func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, content string, at []int64) (err error) { 214 func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, content string, at []int64) (err error) {
215 - return l.submit(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, content, at) 215 + return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, content, at)
216 } 216 }
217 217
218 // LikeArticle 点赞文章 218 // LikeArticle 点赞文章
219 func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) { 219 func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) {
220 - return l.submit(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, "", []int64{at}) 220 + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, "", []int64{at})
221 } 221 }
222 222
223 // LikeComment 点赞评论 223 // LikeComment 点赞评论
224 func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) { 224 func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {
225 - return l.submit(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, "", []int64{at}) 225 + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, "", []int64{at})
226 } 226 }
227 227
228 -func (l *MiniBusinessLogic) submit( 228 +func (l *MiniBusinessLogic) createMessage(
229 conn transaction.Conn, 229 conn transaction.Conn,
230 msgType domain.MsgBusinessType, 230 msgType domain.MsgBusinessType,
231 optType domain.MsgBusinessOpt, 231 optType domain.MsgBusinessOpt,
@@ -2,10 +2,13 @@ package message @@ -2,10 +2,13 @@ package message
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "fmt"
5 "github.com/zeromicro/go-zero/core/logx" 6 "github.com/zeromicro/go-zero/core/logx"
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 7 "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" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
9 ) 12 )
10 13
11 type MiniSystemLogic struct { 14 type MiniSystemLogic struct {
@@ -23,8 +26,11 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy @@ -23,8 +26,11 @@ func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSy
23 } 26 }
24 27
25 func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) { 28 func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *types.MessageSystemResponse, err error) {
26 - queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size)  
27 - total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), queryOptions) 29 + var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  30 +
  31 + total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions().
  32 + WithOffsetLimit(req.Page, req.Size).
  33 + WithKV("recipientId", userToken.UserId))
28 if err != nil { 34 if err != nil {
29 return nil, err 35 return nil, err
30 } 36 }
@@ -34,7 +40,7 @@ func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *typ @@ -34,7 +40,7 @@ func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *typ
34 for _, item := range list { 40 for _, item := range list {
35 to := types.MessageSystemItem{ 41 to := types.MessageSystemItem{
36 Id: item.Id, 42 Id: item.Id,
37 - Type: item.Type, 43 + Type: int(item.Type),
38 Title: item.Title, 44 Title: item.Title,
39 Content: item.Content, 45 Content: item.Content,
40 CreatedAt: item.CreatedAt, 46 CreatedAt: item.CreatedAt,
@@ -44,15 +50,39 @@ func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *typ @@ -44,15 +50,39 @@ func (l *MiniSystemLogic) MiniSystem(req *types.MessageSystemRequest) (resp *typ
44 return resp, nil 50 return resp, nil
45 } 51 }
46 52
47 -func (l *MiniSystemLogic) CreateMessage(dm *domain.MessageSystem) error {  
48 - _, err := l.svcCtx.MessageSystemRepository.Insert(l.ctx, l.svcCtx.DefaultDBConn(), dm)  
49 - l.Debugf("")  
50 - return err 53 +// ArticleDefined 文章已定性
  54 +func (l *MiniSystemLogic) ArticleDefined(conn transaction.Conn, companyId, at int64, item string) (err error) {
  55 + return l.createMessage(conn, companyId, at, domain.MsgTypeNormal, "帖子已定性", fmt.Sprintf("您的帖子[%s]已被定性,如有疑问,请联系运营管理员了解详情。", item))
  56 +}
  57 +
  58 +// AbnormalArticleUnapproved 文章未审核通过
  59 +func (l *MiniSystemLogic) AbnormalArticleUnapproved(conn transaction.Conn, companyId, at int64, item string) (err error) {
  60 + return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "发帖未通过审核", fmt.Sprintf("您的帖子[%s]因违反运营规则未通过审核,如有疑问,请联系运营管理员了解详情。", item))
51 } 61 }
52 62
53 -//// CreateSystemMessage 生成一条信息  
54 -//func CreateSystemMessage(ctx context.Context, svcCtx *svc.ServiceContext, dm *domain.MessageSystem) error {  
55 -// l := NewMiniSystemLogic(ctx, svcCtx)  
56 -// err := l.CreateMessage(dm)  
57 -// return err  
58 -//} 63 +// AbnormalArticleHidden 文章被隐藏
  64 +func (l *MiniSystemLogic) AbnormalArticleHidden(conn transaction.Conn, companyId, at int64, item string) (err error) {
  65 + return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "帖子被隐藏", fmt.Sprintf("您的帖子[%s]已被隐藏,如有疑问,请联系运营管理员了解详情。", item))
  66 +}
  67 +
  68 +// AbnormalCommentUnapproved 评论未审核通过
  69 +func (l *MiniSystemLogic) AbnormalCommentUnapproved(conn transaction.Conn, companyId, at int64, item string) (err error) {
  70 + return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "评论未通过审核", fmt.Sprintf("您的评论[%s]因违反运营规则未通过审核,如有疑问,请联系运营管理员了解详情。", item))
  71 +}
  72 +
  73 +// AbnormalCommentHidden 评论被隐藏
  74 +func (l *MiniSystemLogic) AbnormalCommentHidden(conn transaction.Conn, companyId, at int64, item string) (err error) {
  75 + return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "评论被隐藏", fmt.Sprintf("您的评论[%s]已被隐藏,如有疑问,请联系运营管理员了解详情。", item))
  76 +}
  77 +
  78 +func (l *MiniSystemLogic) createMessage(conn transaction.Conn, companyId, at int64, msgType domain.MsgSystemType, title string, content string) (err error) {
  79 + var msg = &domain.MessageSystem{
  80 + Type: msgType,
  81 + CompanyId: companyId,
  82 + RecipientId: at,
  83 + Title: title,
  84 + Content: content,
  85 + }
  86 + msg, err = l.svcCtx.MessageSystemRepository.Insert(l.ctx, conn, msg)
  87 + return err
  88 +}
@@ -6,16 +6,16 @@ import ( @@ -6,16 +6,16 @@ import (
6 ) 6 )
7 7
8 type MessageSystem struct { 8 type MessageSystem struct {
9 - Id int64 // 唯一标识  
10 - CompanyId int64 `json:"companyId"` // 公司ID  
11 - RecipientId int64 `json:"recipientId"` // 接收者ID  
12 - Type int `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知)  
13 - Title string `json:"title"` // 标题  
14 - Content string `json:"content"` // 内容  
15 - CreatedAt int64 `json:",omitempty"`  
16 - UpdatedAt int64 `json:",omitempty"`  
17 - DeletedAt int64 `json:",omitempty"`  
18 - Version int `json:",omitempty"` 9 + Id int64 // 唯一标识
  10 + CompanyId int64 `json:"companyId"` // 公司ID
  11 + RecipientId int64 `json:"recipientId"` // 接收者ID
  12 + Type MsgSystemType `json:"type"` // 系统分类(0待定、1业务正常通知、2业务异常通知)
  13 + Title string `json:"title"` // 标题
  14 + Content string `json:"content"` // 内容
  15 + CreatedAt int64 `json:",omitempty"`
  16 + UpdatedAt int64 `json:",omitempty"`
  17 + DeletedAt int64 `json:",omitempty"`
  18 + Version int `json:",omitempty"`
19 } 19 }
20 20
21 type MsgSystemType int 21 type MsgSystemType int