|
@@ -5,6 +5,8 @@ import ( |
|
@@ -5,6 +5,8 @@ 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/domain"
|
|
|
9
|
+ "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
8
|
|
10
|
|
9
|
"github.com/zeromicro/go-zero/core/logx"
|
11
|
"github.com/zeromicro/go-zero/core/logx"
|
10
|
)
|
12
|
)
|
|
@@ -24,7 +26,166 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont |
|
@@ -24,7 +26,166 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont |
24
|
}
|
26
|
}
|
25
|
|
27
|
|
26
|
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
|
28
|
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
|
27
|
- // todo: add your logic here and delete this line
|
29
|
+ // 先获取最顶层的评论
|
|
|
30
|
+ var conn = l.svcCtx.DefaultDBConn()
|
|
|
31
|
+ if req.Page > 40 {
|
|
|
32
|
+ req.Page = 40
|
|
|
33
|
+ }
|
|
|
34
|
+
|
|
|
35
|
+ queryOption := domain.NewQueryOptions().
|
|
|
36
|
+ WithOffsetLimit(req.Page, req.Size).
|
|
|
37
|
+ MustWithKV("topId", 0).
|
|
|
38
|
+ MustWithKV("articleId", req.ArticleId).
|
|
|
39
|
+ MustWithKV("sectionId", req.SectionId).
|
|
|
40
|
+ MustWithKV("show", domain.CommentShowEnable).
|
|
|
41
|
+ MustWithKV("companyId", req.CompanyId)
|
|
|
42
|
+
|
|
|
43
|
+ cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
|
|
|
44
|
+ if err != nil {
|
|
|
45
|
+ return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
46
|
+ }
|
|
|
47
|
+ if cnt == 0 {
|
|
|
48
|
+ resp = &types.MiniListArticleCommentResponse{
|
|
|
49
|
+ Total: 0,
|
|
|
50
|
+ List: make([]types.ArticleCommentAndReply, 0),
|
|
|
51
|
+ }
|
|
|
52
|
+ return
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+ queryOption = domain.NewQueryOptions().WithFindOnly().
|
|
|
56
|
+ MustWithKV("articleId", req.ArticleId).
|
|
|
57
|
+ MustWithKV("userId", req.UserId)
|
|
|
58
|
+ // 获取我点赞的评论
|
|
|
59
|
+ _, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
|
|
|
60
|
+ if err != nil {
|
|
|
61
|
+ return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
62
|
+ }
|
|
|
63
|
+ // 我点赞的
|
|
|
64
|
+ flagMap := map[int64]struct{}{}
|
|
|
65
|
+ for _, val := range userFlagList {
|
|
|
66
|
+ flagMap[val.CommentId] = struct{}{}
|
|
|
67
|
+ }
|
|
|
68
|
+ resp = &types.MiniListArticleCommentResponse{
|
|
|
69
|
+ Total: cnt,
|
|
|
70
|
+ List: make([]types.ArticleCommentAndReply, len(commentList)),
|
|
|
71
|
+ }
|
|
|
72
|
+ // 获取回复的评论
|
|
|
73
|
+ for i, val := range commentList {
|
|
|
74
|
+ item := types.ArticleCommentAndReply{
|
|
|
75
|
+ Comment: types.ArticleCommentItem{
|
|
|
76
|
+ Id: val.Id,
|
|
|
77
|
+ Pid: val.Pid,
|
|
|
78
|
+ TopId: val.TopId,
|
|
|
79
|
+ ArtitcleId: val.ArticleId,
|
|
|
80
|
+ SectionId: val.SectionId,
|
|
|
81
|
+ FromUserId: val.FromUserId,
|
|
|
82
|
+ FromUser: types.CommentAuthor{
|
|
|
83
|
+ Id: val.FromUser.Id,
|
|
|
84
|
+ Name: val.FromUser.Name,
|
|
|
85
|
+ Avatar: val.FromUser.Avatar,
|
|
|
86
|
+ Position: val.FromUser.Position,
|
|
|
87
|
+ Company: val.FromUser.Company,
|
|
|
88
|
+ },
|
|
|
89
|
+ ToUserId: val.ToUserId,
|
|
|
90
|
+ ToUser: types.CommentAuthor{
|
|
|
91
|
+ Id: val.ToUser.Id,
|
|
|
92
|
+ Name: val.ToUser.Name,
|
|
|
93
|
+ Avatar: val.ToUser.Avatar,
|
|
|
94
|
+ Position: val.ToUser.Position,
|
|
|
95
|
+ Company: val.ToUser.Company,
|
|
|
96
|
+ },
|
|
|
97
|
+ SectionContent: val.SectionContent,
|
|
|
98
|
+ CountReply: val.CountReply,
|
|
|
99
|
+ CountUserLove: val.CountUserLove,
|
|
|
100
|
+ CountAdminLove: val.CountAdminLove,
|
|
|
101
|
+ AtWho: []types.CommentAtWho{},
|
|
|
102
|
+ CreatedAt: val.CreatedAt,
|
|
|
103
|
+ MeLoveFlag: 0,
|
|
|
104
|
+ },
|
|
|
105
|
+ Reply: []types.ArticleCommentItem{},
|
|
|
106
|
+ TotalReply: int64(val.CountReply),
|
|
|
107
|
+ }
|
|
|
108
|
+
|
|
|
109
|
+ if _, ok := flagMap[val.Id]; ok {
|
|
|
110
|
+ item.Comment.MeLoveFlag = 1
|
|
|
111
|
+ }
|
|
|
112
|
+
|
|
|
113
|
+ for _, val2 := range val.AtWho {
|
|
|
114
|
+ item.Comment.AtWho = append(item.Comment.AtWho, types.CommentAtWho{
|
|
|
115
|
+ Id: val2.Id,
|
|
|
116
|
+ Name: val2.Name,
|
|
|
117
|
+ })
|
|
|
118
|
+ }
|
28
|
|
119
|
|
29
|
- return
|
120
|
+ //获取回复的评论
|
|
|
121
|
+ cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap)
|
|
|
122
|
+
|
|
|
123
|
+ resp.List[i] = item
|
|
|
124
|
+ resp.List[i].Reply = reply
|
|
|
125
|
+ resp.List[i].TotalReply = cntReply
|
|
|
126
|
+ }
|
|
|
127
|
+ return resp, nil
|
|
|
128
|
+}
|
|
|
129
|
+
|
|
|
130
|
+// listCommentReply
|
|
|
131
|
+func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
|
|
|
132
|
+ var conn = l.svcCtx.DefaultDBConn()
|
|
|
133
|
+ queryOption := domain.NewQueryOptions().
|
|
|
134
|
+ WithOffsetLimit(1, 2).
|
|
|
135
|
+ MustWithKV("topId", commentId).
|
|
|
136
|
+ MustWithKV("show", domain.CommentShowEnable)
|
|
|
137
|
+
|
|
|
138
|
+ cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
|
|
|
139
|
+ if err != nil {
|
|
|
140
|
+ return cnt, []types.ArticleCommentItem{}
|
|
|
141
|
+ }
|
|
|
142
|
+ if cnt == 0 {
|
|
|
143
|
+ replyList = []types.ArticleCommentItem{}
|
|
|
144
|
+ return cnt, replyList
|
|
|
145
|
+ }
|
|
|
146
|
+
|
|
|
147
|
+ for _, val := range commentList {
|
|
|
148
|
+ item := types.ArticleCommentItem{
|
|
|
149
|
+ Id: val.Id,
|
|
|
150
|
+ Pid: val.Pid,
|
|
|
151
|
+ TopId: val.TopId,
|
|
|
152
|
+ ArtitcleId: val.ArticleId,
|
|
|
153
|
+ SectionId: val.SectionId,
|
|
|
154
|
+ FromUserId: val.FromUserId,
|
|
|
155
|
+ FromUser: types.CommentAuthor{
|
|
|
156
|
+ Id: val.FromUser.Id,
|
|
|
157
|
+ Name: val.FromUser.Name,
|
|
|
158
|
+ Avatar: val.FromUser.Avatar,
|
|
|
159
|
+ Position: val.FromUser.Position,
|
|
|
160
|
+ Company: val.FromUser.Company,
|
|
|
161
|
+ },
|
|
|
162
|
+ ToUserId: val.ToUserId,
|
|
|
163
|
+ ToUser: types.CommentAuthor{
|
|
|
164
|
+ Id: val.ToUser.Id,
|
|
|
165
|
+ Name: val.ToUser.Name,
|
|
|
166
|
+ Avatar: val.ToUser.Avatar,
|
|
|
167
|
+ Position: val.ToUser.Position,
|
|
|
168
|
+ Company: val.ToUser.Company,
|
|
|
169
|
+ },
|
|
|
170
|
+ SectionContent: val.SectionContent,
|
|
|
171
|
+ CountReply: val.CountReply,
|
|
|
172
|
+ CountUserLove: val.CountUserLove,
|
|
|
173
|
+ CountAdminLove: val.CountAdminLove,
|
|
|
174
|
+ AtWho: []types.CommentAtWho{},
|
|
|
175
|
+ CreatedAt: val.CreatedAt,
|
|
|
176
|
+ MeLoveFlag: 0,
|
|
|
177
|
+ }
|
|
|
178
|
+
|
|
|
179
|
+ if _, ok := loveFlagMap[val.Id]; ok {
|
|
|
180
|
+ item.MeLoveFlag = 1
|
|
|
181
|
+ }
|
|
|
182
|
+ for _, val2 := range val.AtWho {
|
|
|
183
|
+ item.AtWho = append(item.AtWho, types.CommentAtWho{
|
|
|
184
|
+ Id: val2.Id,
|
|
|
185
|
+ Name: val2.Name,
|
|
|
186
|
+ })
|
|
|
187
|
+ }
|
|
|
188
|
+ replyList = append(replyList, item)
|
|
|
189
|
+ }
|
|
|
190
|
+ return cnt, replyList
|
30
|
} |
191
|
} |