...
|
...
|
@@ -5,6 +5,7 @@ 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/db/transaction"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
...
|
...
|
@@ -13,21 +14,27 @@ import ( |
|
|
|
|
|
type MiniGetArticleCommentLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
userCache map[int64]types.CommentAuthor
|
|
|
}
|
|
|
|
|
|
func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic {
|
|
|
return &MiniGetArticleCommentLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
userCache: make(map[int64]types.CommentAuthor),
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 获取单条评论详情
|
|
|
func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) {
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("读取公司数据失败", err)
|
|
|
}
|
|
|
//获取主评论
|
|
|
commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
|
|
|
if err != nil {
|
...
|
...
|
@@ -38,10 +45,14 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt |
|
|
}
|
|
|
|
|
|
if commentInfo.Show == domain.CommentShowDisable {
|
|
|
return nil, xerr.NewErrMsg("没有查看权限")
|
|
|
return nil, xerr.NewErrMsg("具体评论已被关闭")
|
|
|
}
|
|
|
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("topId", commentInfo.Id).MustWithKV("show", domain.CommentShowEnable)
|
|
|
//获取回复的评论
|
|
|
|
|
|
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 {
|
...
|
...
|
@@ -60,30 +71,17 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt |
|
|
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,
|
|
|
},
|
|
|
Id: commentInfo.Id,
|
|
|
Pid: commentInfo.Pid,
|
|
|
TopId: commentInfo.TopId,
|
|
|
ArtitcleId: commentInfo.ArticleId,
|
|
|
SectionId: commentInfo.ArticleId,
|
|
|
FromUserId: commentInfo.FromUserId,
|
|
|
FromUser: l.getCommentAuthor(conn, commentInfo.FromUserId, companyInfo.Name),
|
|
|
ToUserId: commentInfo.ToUserId,
|
|
|
ToUser: l.getCommentAuthor(conn, commentInfo.ToUserId, companyInfo.Name),
|
|
|
SectionContent: commentInfo.SectionContent,
|
|
|
CountReply: commentInfo.CountReply,
|
|
|
CountUserLove: commentInfo.CountUserLove,
|
...
|
...
|
@@ -110,27 +108,15 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt |
|
|
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,
|
|
|
},
|
|
|
Id: val.Id,
|
|
|
Pid: val.Pid,
|
|
|
TopId: val.TopId,
|
|
|
ArtitcleId: val.ArticleId,
|
|
|
SectionId: val.SectionId,
|
|
|
FromUserId: val.FromUserId,
|
|
|
FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name),
|
|
|
ToUserId: val.ToUserId,
|
|
|
ToUser: l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name),
|
|
|
SectionContent: "",
|
|
|
CountReply: val.CountReply,
|
|
|
CountUserLove: val.CountUserLove,
|
...
|
...
|
@@ -141,6 +127,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt |
|
|
MeLoveFlag: 0,
|
|
|
Content: val.Content,
|
|
|
}
|
|
|
|
|
|
if _, ok := flagMap[val.Id]; ok {
|
|
|
reply.MeLoveFlag = 1
|
|
|
}
|
...
|
...
|
@@ -164,3 +151,22 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt |
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (l *MiniGetArticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor {
|
|
|
if u, ok := l.userCache[userid]; ok {
|
|
|
return u
|
|
|
}
|
|
|
toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
|
|
|
if err == nil {
|
|
|
commentToUser := types.CommentAuthor{
|
|
|
Id: toUser.Id,
|
|
|
Name: toUser.Name,
|
|
|
Avatar: toUser.Avatar,
|
|
|
Position: toUser.Position,
|
|
|
Company: companyName,
|
|
|
}
|
|
|
l.userCache[toUser.Id] = commentToUser
|
|
|
return commentToUser
|
|
|
}
|
|
|
return types.CommentAuthor{}
|
|
|
} |
...
|
...
|
|