...
|
...
|
@@ -5,6 +5,8 @@ import ( |
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
...
|
...
|
@@ -24,7 +26,166 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont |
|
|
}
|
|
|
|
|
|
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
|
|
|
// todo: add your logic here and delete this line
|
|
|
// 先获取最顶层的评论
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
if req.Page > 40 {
|
|
|
req.Page = 40
|
|
|
}
|
|
|
|
|
|
queryOption := domain.NewQueryOptions().
|
|
|
WithOffsetLimit(req.Page, req.Size).
|
|
|
MustWithKV("topId", 0).
|
|
|
MustWithKV("articleId", req.ArticleId).
|
|
|
MustWithKV("sectionId", req.SectionId).
|
|
|
MustWithKV("show", domain.CommentShowEnable).
|
|
|
MustWithKV("companyId", req.CompanyId)
|
|
|
|
|
|
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
if cnt == 0 {
|
|
|
resp = &types.MiniListArticleCommentResponse{
|
|
|
Total: 0,
|
|
|
List: make([]types.ArticleCommentAndReply, 0),
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
queryOption = domain.NewQueryOptions().WithFindOnly().
|
|
|
MustWithKV("articleId", req.ArticleId).
|
|
|
MustWithKV("userId", req.UserId)
|
|
|
// 获取我点赞的评论
|
|
|
_, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
// 我点赞的
|
|
|
flagMap := map[int64]struct{}{}
|
|
|
for _, val := range userFlagList {
|
|
|
flagMap[val.CommentId] = struct{}{}
|
|
|
}
|
|
|
resp = &types.MiniListArticleCommentResponse{
|
|
|
Total: cnt,
|
|
|
List: make([]types.ArticleCommentAndReply, len(commentList)),
|
|
|
}
|
|
|
// 获取回复的评论
|
|
|
for i, val := range commentList {
|
|
|
item := types.ArticleCommentAndReply{
|
|
|
Comment: types.ArticleCommentItem{
|
|
|
Id: val.Id,
|
|
|
Pid: val.Pid,
|
|
|
TopId: val.TopId,
|
|
|
ArtitcleId: val.ArticleId,
|
|
|
SectionId: val.SectionId,
|
|
|
FromUserId: val.FromUserId,
|
|
|
FromUser: types.CommentAuthor{
|
|
|
Id: val.FromUser.Id,
|
|
|
Name: val.FromUser.Name,
|
|
|
Avatar: val.FromUser.Avatar,
|
|
|
Position: val.FromUser.Position,
|
|
|
Company: val.FromUser.Company,
|
|
|
},
|
|
|
ToUserId: val.ToUserId,
|
|
|
ToUser: types.CommentAuthor{
|
|
|
Id: val.ToUser.Id,
|
|
|
Name: val.ToUser.Name,
|
|
|
Avatar: val.ToUser.Avatar,
|
|
|
Position: val.ToUser.Position,
|
|
|
Company: val.ToUser.Company,
|
|
|
},
|
|
|
SectionContent: val.SectionContent,
|
|
|
CountReply: val.CountReply,
|
|
|
CountUserLove: val.CountUserLove,
|
|
|
CountAdminLove: val.CountAdminLove,
|
|
|
AtWho: []types.CommentAtWho{},
|
|
|
CreatedAt: val.CreatedAt,
|
|
|
MeLoveFlag: 0,
|
|
|
},
|
|
|
Reply: []types.ArticleCommentItem{},
|
|
|
TotalReply: int64(val.CountReply),
|
|
|
}
|
|
|
|
|
|
if _, ok := flagMap[val.Id]; ok {
|
|
|
item.Comment.MeLoveFlag = 1
|
|
|
}
|
|
|
|
|
|
for _, val2 := range val.AtWho {
|
|
|
item.Comment.AtWho = append(item.Comment.AtWho, types.CommentAtWho{
|
|
|
Id: val2.Id,
|
|
|
Name: val2.Name,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
return
|
|
|
//获取回复的评论
|
|
|
cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap)
|
|
|
|
|
|
resp.List[i] = item
|
|
|
resp.List[i].Reply = reply
|
|
|
resp.List[i].TotalReply = cntReply
|
|
|
}
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
// listCommentReply
|
|
|
func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
queryOption := domain.NewQueryOptions().
|
|
|
WithOffsetLimit(1, 2).
|
|
|
MustWithKV("topId", commentId).
|
|
|
MustWithKV("show", domain.CommentShowEnable)
|
|
|
|
|
|
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
|
|
|
if err != nil {
|
|
|
return cnt, []types.ArticleCommentItem{}
|
|
|
}
|
|
|
if cnt == 0 {
|
|
|
replyList = []types.ArticleCommentItem{}
|
|
|
return cnt, replyList
|
|
|
}
|
|
|
|
|
|
for _, val := range commentList {
|
|
|
item := types.ArticleCommentItem{
|
|
|
Id: val.Id,
|
|
|
Pid: val.Pid,
|
|
|
TopId: val.TopId,
|
|
|
ArtitcleId: val.ArticleId,
|
|
|
SectionId: val.SectionId,
|
|
|
FromUserId: val.FromUserId,
|
|
|
FromUser: types.CommentAuthor{
|
|
|
Id: val.FromUser.Id,
|
|
|
Name: val.FromUser.Name,
|
|
|
Avatar: val.FromUser.Avatar,
|
|
|
Position: val.FromUser.Position,
|
|
|
Company: val.FromUser.Company,
|
|
|
},
|
|
|
ToUserId: val.ToUserId,
|
|
|
ToUser: types.CommentAuthor{
|
|
|
Id: val.ToUser.Id,
|
|
|
Name: val.ToUser.Name,
|
|
|
Avatar: val.ToUser.Avatar,
|
|
|
Position: val.ToUser.Position,
|
|
|
Company: val.ToUser.Company,
|
|
|
},
|
|
|
SectionContent: val.SectionContent,
|
|
|
CountReply: val.CountReply,
|
|
|
CountUserLove: val.CountUserLove,
|
|
|
CountAdminLove: val.CountAdminLove,
|
|
|
AtWho: []types.CommentAtWho{},
|
|
|
CreatedAt: val.CreatedAt,
|
|
|
MeLoveFlag: 0,
|
|
|
}
|
|
|
|
|
|
if _, ok := loveFlagMap[val.Id]; ok {
|
|
|
item.MeLoveFlag = 1
|
|
|
}
|
|
|
for _, val2 := range val.AtWho {
|
|
|
item.AtWho = append(item.AtWho, types.CommentAtWho{
|
|
|
Id: val2.Id,
|
|
|
Name: val2.Name,
|
|
|
})
|
|
|
}
|
|
|
replyList = append(replyList, item)
|
|
|
}
|
|
|
return cnt, replyList
|
|
|
} |
...
|
...
|
|