|
|
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 MiniGetArticleCommentLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
}
|
|
|
|
|
|
func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic {
|
|
|
return &MiniGetArticleCommentLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取单条评论详情
|
|
|
func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
//获取主评论
|
|
|
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
if commentInfo.CompanyId != req.CompanyId {
|
|
|
return nil, xerr.NewErrMsg("没有查看权限")
|
|
|
}
|
|
|
|
|
|
if commentInfo.Show == domain.CommentShowDisable {
|
|
|
return nil, xerr.NewErrMsg("没有查看权限")
|
|
|
}
|
|
|
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("topId", commentInfo.Id).MustWithKV("show", domain.CommentShowEnable)
|
|
|
//获取回复的评论
|
|
|
_, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
|
|
|
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
|
|
|
}
|
|
|
queryOption = domain.NewQueryOptions().WithFindOnly().
|
|
|
MustWithKV("articleId", commentInfo.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{}{}
|
|
|
}
|
|
|
|
|
|
//混合数据
|
|
|
commentResp := types.ArticleCommentItem{
|
|
|
Id: commentInfo.Id,
|
|
|
Pid: commentInfo.Pid,
|
|
|
TopId: commentInfo.TopId,
|
|
|
ArtitcleId: commentInfo.ArticleId,
|
|
|
SectionId: commentInfo.ArticleId,
|
|
|
FromUserId: commentInfo.FromUserId,
|
|
|
FromUser: types.CommentAuthor{
|
|
|
Id: commentInfo.FromUser.Id,
|
|
|
Name: commentInfo.FromUser.Name,
|
|
|
Avatar: commentInfo.FromUser.Avatar,
|
|
|
Position: commentInfo.FromUser.Position,
|
|
|
Company: commentInfo.FromUser.Company,
|
|
|
},
|
|
|
ToUserId: commentInfo.ToUserId,
|
|
|
ToUser: types.CommentAuthor{
|
|
|
Id: commentInfo.ToUser.Id,
|
|
|
Name: commentInfo.ToUser.Name,
|
|
|
Avatar: commentInfo.ToUser.Avatar,
|
|
|
Position: commentInfo.ToUser.Position,
|
|
|
Company: commentInfo.ToUser.Company,
|
|
|
},
|
|
|
SectionContent: commentInfo.SectionContent,
|
|
|
CountReply: commentInfo.CountReply,
|
|
|
CountUserLove: commentInfo.CountUserLove,
|
|
|
CountAdminLove: commentInfo.CountAdminLove,
|
|
|
AtWho: []types.CommentAtWho{},
|
|
|
CreatedAt: commentInfo.CreatedAt,
|
|
|
MeLoveFlag: 0,
|
|
|
}
|
|
|
if _, ok := flagMap[commentInfo.Id]; ok {
|
|
|
commentResp.MeLoveFlag = 1
|
|
|
}
|
|
|
for _, val := range commentInfo.AtWho {
|
|
|
commentResp.AtWho = append(commentResp.AtWho, types.CommentAtWho{
|
|
|
Id: val.Id,
|
|
|
Name: val.Name,
|
|
|
})
|
|
|
}
|
|
|
// 回复的评论
|
|
|
allReply := []types.ArticleCommentItem{}
|
|
|
for _, val := range replyCommenList {
|
|
|
reply := 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 := flagMap[val.Id]; ok {
|
|
|
reply.MeLoveFlag = 1
|
|
|
}
|
|
|
for _, val2 := range val.AtWho {
|
|
|
reply.AtWho = append(reply.AtWho, types.CommentAtWho{
|
|
|
Id: val2.Id,
|
|
|
Name: val2.Name,
|
|
|
})
|
|
|
}
|
|
|
allReply = append(allReply, reply)
|
|
|
}
|
|
|
resp = &types.MiniGetArticleCommentResponse{
|
|
|
ArticleCommentAndReply: types.ArticleCommentAndReply{
|
|
|
Comment: commentResp,
|
|
|
Reply: allReply,
|
|
|
TotalReply: int64(len(replyCommenList)),
|
|
|
},
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|