|
|
package comment
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
|
|
|
"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"
|
|
|
)
|
|
|
|
|
|
type MiniListReplyArticleCommentLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewMiniListReplyArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListReplyArticleCommentLogic {
|
|
|
return &MiniListReplyArticleCommentLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取评论对应的回复,只获取一级评论
|
|
|
func (l *MiniListReplyArticleCommentLogic) MiniListReplyArticleComment(req *types.MiniListReplyArticleCommentRequest) (resp *types.MiniListReplyArticleCommentResponse, err error) {
|
|
|
// 先获取最顶层的评论
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
if req.CommentId == 0 {
|
|
|
return
|
|
|
}
|
|
|
queryOption := domain.NewQueryOptions().
|
|
|
WithOffsetLimit(req.Page, req.Size).
|
|
|
MustWithKV("show", int(domain.CommentShowEnable)).
|
|
|
MustWithKV("companyId", req.CompanyId).
|
|
|
MustWithKV("pid", req.CommentId)
|
|
|
|
|
|
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
if cnt == 0 || len(commentList) == 0 {
|
|
|
resp = &types.MiniListReplyArticleCommentResponse{
|
|
|
Total: cnt,
|
|
|
List: make([]types.ArticleCommentItem, 0),
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
commentIds := []int64{}
|
|
|
for _, val := range commentList {
|
|
|
commentIds = append(commentIds, val.Id)
|
|
|
}
|
|
|
queryOption = domain.NewQueryOptions().WithFindOnly().
|
|
|
MustWithKV("commentIdList", commentIds).
|
|
|
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.MiniListReplyArticleCommentResponse{
|
|
|
Total: cnt,
|
|
|
List: make([]types.ArticleCommentItem, len(commentList)),
|
|
|
}
|
|
|
// 获取回复的评论
|
|
|
for i, 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{},
|
|
|
MatchUrl: map[string]string{},
|
|
|
CreatedAt: val.CreatedAt,
|
|
|
MeLoveFlag: 0,
|
|
|
Content: val.Content,
|
|
|
}
|
|
|
|
|
|
if _, ok := flagMap[val.Id]; ok {
|
|
|
item.MeLoveFlag = 1
|
|
|
}
|
|
|
for key2, val2 := range val.MatchUrl {
|
|
|
item.MatchUrl[key2] = val2
|
|
|
}
|
|
|
for _, val2 := range val.AtWho {
|
|
|
item.AtWho = append(item.AtWho, types.CommentAtWho{
|
|
|
Id: val2.Id,
|
|
|
Name: val2.Name,
|
|
|
})
|
|
|
}
|
|
|
resp.List[i] = item
|
|
|
}
|
|
|
return resp, nil
|
|
|
} |
...
|
...
|
|