...
|
...
|
@@ -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"
|
|
|
|
...
|
...
|
@@ -15,6 +16,7 @@ type MiniGetArticleCommentLogic struct { |
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
userCache map[int64]types.CommentAuthor
|
|
|
}
|
|
|
|
|
|
func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic {
|
...
|
...
|
@@ -22,12 +24,17 @@ func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceConte |
|
|
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,7 +71,6 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt |
|
|
for _, val := range userFlagList {
|
|
|
flagMap[val.CommentId] = struct{}{}
|
|
|
}
|
|
|
|
|
|
//混合数据
|
|
|
commentResp := types.ArticleCommentItem{
|
|
|
Id: commentInfo.Id,
|
...
|
...
|
@@ -69,21 +79,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt |
|
|
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,
|
|
|
},
|
|
|
FromUser: l.getCommentAuthor(conn, commentInfo.FromUserId, companyInfo.Name),
|
|
|
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,
|
|
|
},
|
|
|
ToUser: l.getCommentAuthor(conn, commentInfo.ToUserId, companyInfo.Name),
|
|
|
SectionContent: commentInfo.SectionContent,
|
|
|
CountReply: commentInfo.CountReply,
|
|
|
CountUserLove: commentInfo.CountUserLove,
|
...
|
...
|
@@ -116,21 +114,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt |
|
|
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,
|
|
|
},
|
|
|
FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name),
|
|
|
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,
|
|
|
},
|
|
|
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{}
|
|
|
} |
...
|
...
|
|