|
@@ -5,6 +5,7 @@ import ( |
|
@@ -5,6 +5,7 @@ import ( |
|
5
|
|
5
|
|
|
6
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
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/types"
|
7
|
"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"
|
|
8
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
9
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
10
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
10
|
|
11
|
|
|
@@ -15,6 +16,7 @@ type MiniListArticleCommentLogic struct { |
|
@@ -15,6 +16,7 @@ type MiniListArticleCommentLogic struct { |
|
15
|
logx.Logger
|
16
|
logx.Logger
|
|
16
|
ctx context.Context
|
17
|
ctx context.Context
|
|
17
|
svcCtx *svc.ServiceContext
|
18
|
svcCtx *svc.ServiceContext
|
|
|
|
19
|
+ userCache map[int64]types.CommentAuthor
|
|
18
|
}
|
20
|
}
|
|
19
|
|
21
|
|
|
20
|
func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListArticleCommentLogic {
|
22
|
func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListArticleCommentLogic {
|
|
@@ -22,6 +24,7 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont |
|
@@ -22,6 +24,7 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont |
|
22
|
Logger: logx.WithContext(ctx),
|
24
|
Logger: logx.WithContext(ctx),
|
|
23
|
ctx: ctx,
|
25
|
ctx: ctx,
|
|
24
|
svcCtx: svcCtx,
|
26
|
svcCtx: svcCtx,
|
|
|
|
27
|
+ userCache: make(map[int64]types.CommentAuthor),
|
|
25
|
}
|
28
|
}
|
|
26
|
}
|
29
|
}
|
|
27
|
|
30
|
|
|
@@ -29,6 +32,10 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont |
|
@@ -29,6 +32,10 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont |
|
29
|
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
|
32
|
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
|
|
30
|
// 先获取最顶层的评论
|
33
|
// 先获取最顶层的评论
|
|
31
|
var conn = l.svcCtx.DefaultDBConn()
|
34
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
|
35
|
+ companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
|
|
|
|
36
|
+ if err != nil {
|
|
|
|
37
|
+ return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
|
38
|
+ }
|
|
32
|
if req.Size > 40 {
|
39
|
if req.Size > 40 {
|
|
33
|
req.Size = 40
|
40
|
req.Size = 40
|
|
34
|
}
|
41
|
}
|
|
@@ -54,7 +61,6 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList |
|
@@ -54,7 +61,6 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList |
|
54
|
}
|
61
|
}
|
|
55
|
return
|
62
|
return
|
|
56
|
}
|
63
|
}
|
|
57
|
-
|
|
|
|
58
|
queryOption = domain.NewQueryOptions().WithFindOnly().
|
64
|
queryOption = domain.NewQueryOptions().WithFindOnly().
|
|
59
|
MustWithKV("articleId", req.ArticleId).
|
65
|
MustWithKV("articleId", req.ArticleId).
|
|
60
|
MustWithKV("userId", req.UserId)
|
66
|
MustWithKV("userId", req.UserId)
|
|
@@ -82,21 +88,9 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList |
|
@@ -82,21 +88,9 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList |
|
82
|
ArtitcleId: val.ArticleId,
|
88
|
ArtitcleId: val.ArticleId,
|
|
83
|
SectionId: val.SectionId,
|
89
|
SectionId: val.SectionId,
|
|
84
|
FromUserId: val.FromUserId,
|
90
|
FromUserId: val.FromUserId,
|
|
85
|
- FromUser: types.CommentAuthor{
|
|
|
|
86
|
- Id: val.FromUser.Id,
|
|
|
|
87
|
- Name: val.FromUser.Name,
|
|
|
|
88
|
- Avatar: val.FromUser.Avatar,
|
|
|
|
89
|
- Position: val.FromUser.Position,
|
|
|
|
90
|
- Company: val.FromUser.Company,
|
|
|
|
91
|
- },
|
91
|
+ FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name),
|
|
92
|
ToUserId: val.ToUserId,
|
92
|
ToUserId: val.ToUserId,
|
|
93
|
- ToUser: types.CommentAuthor{
|
|
|
|
94
|
- Id: val.ToUser.Id,
|
|
|
|
95
|
- Name: val.ToUser.Name,
|
|
|
|
96
|
- Avatar: val.ToUser.Avatar,
|
|
|
|
97
|
- Position: val.ToUser.Position,
|
|
|
|
98
|
- Company: val.ToUser.Company,
|
|
|
|
99
|
- },
|
93
|
+ ToUser: l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name),
|
|
100
|
SectionContent: val.SectionContent,
|
94
|
SectionContent: val.SectionContent,
|
|
101
|
CountReply: val.CountReply,
|
95
|
CountReply: val.CountReply,
|
|
102
|
CountUserLove: val.CountUserLove,
|
96
|
CountUserLove: val.CountUserLove,
|
|
@@ -126,7 +120,6 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList |
|
@@ -126,7 +120,6 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList |
|
126
|
|
120
|
|
|
127
|
//获取回复的评论
|
121
|
//获取回复的评论
|
|
128
|
cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap)
|
122
|
cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap)
|
|
129
|
-
|
|
|
|
130
|
resp.List[i] = item
|
123
|
resp.List[i] = item
|
|
131
|
resp.List[i].Reply = reply
|
124
|
resp.List[i].Reply = reply
|
|
132
|
resp.List[i].TotalReply = cntReply
|
125
|
resp.List[i].TotalReply = cntReply
|
|
@@ -137,6 +130,10 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList |
|
@@ -137,6 +130,10 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList |
|
137
|
// listCommentReply
|
130
|
// listCommentReply
|
|
138
|
func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
|
131
|
func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
|
|
139
|
var conn = l.svcCtx.DefaultDBConn()
|
132
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
|
133
|
+ companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, commentId)
|
|
|
|
134
|
+ if err != nil {
|
|
|
|
135
|
+ return 0, []types.ArticleCommentItem{}
|
|
|
|
136
|
+ }
|
|
140
|
queryOption := domain.NewQueryOptions().
|
137
|
queryOption := domain.NewQueryOptions().
|
|
141
|
WithOffsetLimit(1, 2).
|
138
|
WithOffsetLimit(1, 2).
|
|
142
|
MustWithKV("topId", commentId).
|
139
|
MustWithKV("topId", commentId).
|
|
@@ -159,21 +156,9 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag |
|
@@ -159,21 +156,9 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag |
|
159
|
ArtitcleId: val.ArticleId,
|
156
|
ArtitcleId: val.ArticleId,
|
|
160
|
SectionId: val.SectionId,
|
157
|
SectionId: val.SectionId,
|
|
161
|
FromUserId: val.FromUserId,
|
158
|
FromUserId: val.FromUserId,
|
|
162
|
- FromUser: types.CommentAuthor{
|
|
|
|
163
|
- Id: val.FromUser.Id,
|
|
|
|
164
|
- Name: val.FromUser.Name,
|
|
|
|
165
|
- Avatar: val.FromUser.Avatar,
|
|
|
|
166
|
- Position: val.FromUser.Position,
|
|
|
|
167
|
- Company: val.FromUser.Company,
|
|
|
|
168
|
- },
|
159
|
+ FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name),
|
|
169
|
ToUserId: val.ToUserId,
|
160
|
ToUserId: val.ToUserId,
|
|
170
|
- ToUser: types.CommentAuthor{
|
|
|
|
171
|
- Id: val.ToUser.Id,
|
|
|
|
172
|
- Name: val.ToUser.Name,
|
|
|
|
173
|
- Avatar: val.ToUser.Avatar,
|
|
|
|
174
|
- Position: val.ToUser.Position,
|
|
|
|
175
|
- Company: val.ToUser.Company,
|
|
|
|
176
|
- },
|
161
|
+ ToUser: l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name),
|
|
177
|
SectionContent: "", //不设置值
|
162
|
SectionContent: "", //不设置值
|
|
178
|
CountReply: val.CountReply,
|
163
|
CountReply: val.CountReply,
|
|
179
|
CountUserLove: val.CountUserLove,
|
164
|
CountUserLove: val.CountUserLove,
|
|
@@ -184,7 +169,6 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag |
|
@@ -184,7 +169,6 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag |
|
184
|
MeLoveFlag: 0,
|
169
|
MeLoveFlag: 0,
|
|
185
|
Content: val.Content,
|
170
|
Content: val.Content,
|
|
186
|
}
|
171
|
}
|
|
187
|
-
|
|
|
|
188
|
if _, ok := loveFlagMap[val.Id]; ok {
|
172
|
if _, ok := loveFlagMap[val.Id]; ok {
|
|
189
|
item.MeLoveFlag = 1
|
173
|
item.MeLoveFlag = 1
|
|
190
|
}
|
174
|
}
|
|
@@ -201,3 +185,22 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag |
|
@@ -201,3 +185,22 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag |
|
201
|
}
|
185
|
}
|
|
202
|
return cnt, replyList
|
186
|
return cnt, replyList
|
|
203
|
}
|
187
|
}
|
|
|
|
188
|
+
|
|
|
|
189
|
+func (l *MiniListArticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor {
|
|
|
|
190
|
+ if u, ok := l.userCache[userid]; ok {
|
|
|
|
191
|
+ return u
|
|
|
|
192
|
+ }
|
|
|
|
193
|
+ toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
|
|
|
|
194
|
+ if err == nil {
|
|
|
|
195
|
+ commentToUser := types.CommentAuthor{
|
|
|
|
196
|
+ Id: toUser.Id,
|
|
|
|
197
|
+ Name: toUser.Name,
|
|
|
|
198
|
+ Avatar: toUser.Avatar,
|
|
|
|
199
|
+ Position: toUser.Position,
|
|
|
|
200
|
+ Company: companyName,
|
|
|
|
201
|
+ }
|
|
|
|
202
|
+ l.userCache[toUser.Id] = commentToUser
|
|
|
|
203
|
+ return commentToUser
|
|
|
|
204
|
+ }
|
|
|
|
205
|
+ return types.CommentAuthor{}
|
|
|
|
206
|
+} |