作者 郑周

1. 消息列表 优化

@@ -27,9 +27,11 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini @@ -27,9 +27,11 @@ func NewMiniBusinessLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mini
27 } 27 }
28 28
29 func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) { 29 func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (resp *types.MessageBusinessResponse, err error) {
  30 + var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  31 + var conn = l.svcCtx.DefaultDBConn()
30 var msgType = req.Type 32 var msgType = req.Type
31 33
32 - total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions(). 34 + total, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, domain.NewQueryOptions().
33 WithOffsetLimit(req.Page, req.Size). 35 WithOffsetLimit(req.Page, req.Size).
34 WithKV("type", msgType)) 36 WithKV("type", msgType))
35 if err != nil { 37 if err != nil {
@@ -96,11 +98,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -96,11 +98,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
96 98
97 // 获取公司 99 // 获取公司
98 if len(companyIds) > 0 { 100 if len(companyIds) > 0 {
99 - _, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),  
100 - domain.NewQueryOptions().  
101 - WithFindOnly().  
102 - WithKV("ids", userIds).  
103 - WithKV("limit", len(userIds))) 101 + _, companyList, err := l.svcCtx.CompanyRepository.Find(l.ctx, conn, domain.NewQueryOptions().
  102 + WithFindOnly().
  103 + WithKV("ids", userIds).
  104 + WithKV("limit", len(userIds)))
104 if err != nil { 105 if err != nil {
105 return nil, err 106 return nil, err
106 } 107 }
@@ -111,11 +112,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -111,11 +112,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
111 112
112 // 获取用户 113 // 获取用户
113 if len(userIds) > 0 { 114 if len(userIds) > 0 {
114 - _, userList, err := l.svcCtx.UserRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),  
115 - domain.NewQueryOptions().  
116 - WithFindOnly().  
117 - WithKV("ids", userIds).  
118 - WithKV("limit", len(userIds))) 115 + _, userList, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
  116 + WithFindOnly().
  117 + WithKV("ids", userIds).
  118 + WithKV("limit", len(userIds)))
119 if err != nil { 119 if err != nil {
120 return nil, err 120 return nil, err
121 } 121 }
@@ -126,11 +126,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -126,11 +126,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
126 126
127 // 获取评论 127 // 获取评论
128 if len(commentIds) > 0 { 128 if len(commentIds) > 0 {
129 - _, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(),  
130 - domain.NewQueryOptions().  
131 - WithFindOnly().  
132 - WithKV("ids", commentIds).  
133 - WithKV("limit", len(commentIds))) 129 + _, commentList, err := l.svcCtx.CommentRepository.Find(l.ctx, conn, domain.NewQueryOptions().
  130 + WithFindOnly().
  131 + WithKV("ids", commentIds).
  132 + WithKV("limit", len(commentIds)))
134 if err != nil { 133 if err != nil {
135 return nil, err 134 return nil, err
136 } 135 }
@@ -141,11 +140,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -141,11 +140,10 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
141 140
142 // 获取文章数据 141 // 获取文章数据
143 if len(articleIds) > 0 { 142 if len(articleIds) > 0 {
144 - _, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), 0,  
145 - domain.NewQueryOptions().  
146 - WithFindOnly().  
147 - WithKV("ids", articleIds).  
148 - WithKV("limit", len(articleIds))) 143 + _, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().
  144 + WithFindOnly().
  145 + WithKV("ids", articleIds).
  146 + WithKV("limit", len(articleIds)))
149 if err != nil { 147 if err != nil {
150 return nil, err 148 return nil, err
151 } 149 }
@@ -156,18 +154,18 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -156,18 +154,18 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
156 154
157 for _, item := range list { 155 for _, item := range list {
158 to := types.MessageBusinessItem{ 156 to := types.MessageBusinessItem{
159 - Id: item.Id,  
160 - Type: int(item.Type),  
161 - OptType: int(item.OptType),  
162 - CompanyId: item.CompanyId,  
163 - UserId: item.UserId,  
164 - RecipientId: item.RecipientId,  
165 - ArticleId: item.ArticleId,  
166 - CommentId: item.CommentId,  
167 - DiscussionId: item.DiscussionId,  
168 - DiscussionOpinionId: item.DiscussionOpinionId,  
169 - Content: item.Content,  
170 - CreatedAt: item.CreatedAt, 157 + Id: item.Id,
  158 + Type: int(item.Type),
  159 + OptType: int(item.OptType),
  160 + CompanyId: item.CompanyId,
  161 + UserId: item.UserId,
  162 + RecipientId: item.RecipientId,
  163 + ArticleId: item.ArticleId,
  164 + CommentId: item.CommentId,
  165 + //DiscussionId: item.DiscussionId,
  166 + //DiscussionOpinionId: item.DiscussionOpinionId,
  167 + Content: item.Content,
  168 + CreatedAt: item.CreatedAt,
171 } 169 }
172 170
173 if v, ok := userIdMap[item.UserId]; ok { 171 if v, ok := userIdMap[item.UserId]; ok {
@@ -10,22 +10,22 @@ import ( @@ -10,22 +10,22 @@ import (
10 10
11 // MessageBusiness 消息中心业务 11 // MessageBusiness 消息中心业务
12 type MessageBusiness struct { 12 type MessageBusiness struct {
13 - Id int64 // 唯一标识  
14 - Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)  
15 - OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)  
16 - CompanyId int64 `json:"companyId"` // 操作人公司ID  
17 - UserId int64 `json:"userId"` // 操作人用户ID  
18 - RecipientId int64 `json:"recipientId"` // 接收人用户ID  
19 - ArticleId int64 `json:"articleId"` // 文章ID  
20 - CommentId int64 `json:"commentId,omitempty"` // 评论ID  
21 - DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID  
22 - DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID  
23 - Content string `json:"content,omitempty"` // 消息内容  
24 - CreatedAt int64 `json:",omitempty"`  
25 - UpdatedAt int64 `json:",omitempty"`  
26 - DeletedAt int64 `json:",omitempty"`  
27 - Version int `json:",omitempty"`  
28 - IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"` 13 + Id int64 // 唯一标识
  14 + Type int `json:"type"` // 分类 (1回复 2点赞 3被采纳)
  15 + OptType int `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)
  16 + CompanyId int64 `json:"companyId"` // 操作人公司ID
  17 + UserId int64 `json:"userId"` // 操作人用户ID
  18 + RecipientId int64 `json:"recipientId"` // 接收人用户ID
  19 + ArticleId int64 `json:"articleId,omitempty"` // 文章ID
  20 + CommentId int64 `json:"commentId,omitempty"` // 评论ID
  21 + Content string `json:"content,omitempty"` // 消息内容
  22 + CreatedAt int64 `json:",omitempty"`
  23 + UpdatedAt int64 `json:",omitempty"`
  24 + DeletedAt int64 `json:",omitempty"`
  25 + Version int `json:",omitempty"`
  26 + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
  27 + //DiscussionId int64 `json:"discussionId,omitempty"` // 圆桌ID
  28 + //DiscussionOpinionId int64 `json:"discussionOpinionId,omitempty"` // 观点ID
29 } 29 }
30 30
31 func (m *MessageBusiness) TableName() string { 31 func (m *MessageBusiness) TableName() string {
@@ -121,6 +121,9 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran @@ -121,6 +121,9 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran
121 ) 121 )
122 queryFunc := func() (interface{}, error) { 122 queryFunc := func() (interface{}, error) {
123 tx = tx.Model(&ms).Order("created_at desc") 123 tx = tx.Model(&ms).Order("created_at desc")
  124 + if v, ok := queryOptions["companyId"]; ok {
  125 + tx.Where("company_id = ?", v)
  126 + }
124 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 127 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
125 return dms, tx.Error 128 return dms, tx.Error
126 } 129 }
@@ -6,21 +6,22 @@ import ( @@ -6,21 +6,22 @@ import (
6 ) 6 )
7 7
8 type MessageBusiness struct { 8 type MessageBusiness struct {
9 - Id int64 // 唯一标识  
10 - Type MsgBusinessType `json:"type"` // 分类 (1回复 2点赞 3被采纳)  
11 - OptType MsgBusinessOpt `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)  
12 - CompanyId int64 `json:"companyId"` // 操作人公司ID  
13 - UserId int64 `json:"userId"` // 操作人用户ID  
14 - RecipientId int64 `json:"recipientId"` // 接收人用户ID  
15 - ArticleId int64 `json:"articleId"` // 文章ID  
16 - CommentId int64 `json:"commentId"` // 评论ID  
17 - DiscussionId int64 `json:"discussionId"` // 圆桌ID  
18 - DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID  
19 - Content string `json:"content"` // 消息内容  
20 - CreatedAt int64 `json:",omitempty"`  
21 - UpdatedAt int64 `json:",omitempty"`  
22 - DeletedAt int64 `json:",omitempty"`  
23 - Version int `json:",omitempty"` 9 + Id int64 // 唯一标识
  10 + Type MsgBusinessType `json:"type"` // 分类 (1回复 2点赞 3被采纳)
  11 + OptType MsgBusinessOpt `json:"optType"` // 操作类型(1针对文章、1针对评论、2针对圆桌)
  12 + CompanyId int64 `json:"companyId"` // 操作人公司ID
  13 + UserId int64 `json:"userId"` // 操作人用户ID
  14 + RecipientId int64 `json:"recipientId"` // 接收人用户ID
  15 + ArticleId int64 `json:"articleId"` // 文章ID
  16 + CommentId int64 `json:"commentId"` // 评论ID
  17 + Content string `json:"content"` // 消息内容
  18 + CreatedAt int64 `json:",omitempty"`
  19 + UpdatedAt int64 `json:",omitempty"`
  20 + DeletedAt int64 `json:",omitempty"`
  21 + Version int `json:",omitempty"`
  22 +
  23 + //DiscussionId int64 `json:"discussionId"` // 圆桌ID
  24 + //DiscussionOpinionId int64 `json:"discussionOpinionId"` // 观点ID
24 } 25 }
25 26
26 type MsgBusinessType int 27 type MsgBusinessType int