...
|
...
|
@@ -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,15 +14,17 @@ import ( |
|
|
|
|
|
type MiniTop5ArticleCommentLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
userCache map[int64]types.CommentAuthor
|
|
|
}
|
|
|
|
|
|
func NewMiniTop5ArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniTop5ArticleCommentLogic {
|
|
|
return &MiniTop5ArticleCommentLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
userCache: make(map[int64]types.CommentAuthor),
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -50,9 +53,15 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5 |
|
|
resp = &types.MiniTop5ArticleCommentResponse{
|
|
|
List: make([]types.ArticleCommentItem, len(commentList)),
|
|
|
}
|
|
|
companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取公司信息失败", err)
|
|
|
|
|
|
}
|
|
|
for i, val := range commentList {
|
|
|
item := NewArticleCommentItem(val)
|
|
|
|
|
|
item.FromUser = l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name)
|
|
|
item.ToUser = l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name)
|
|
|
if _, ok := flagMap[val.Id]; ok {
|
|
|
item.MeLoveFlag = 1
|
|
|
}
|
...
|
...
|
@@ -70,6 +79,25 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5 |
|
|
return
|
|
|
}
|
|
|
|
|
|
func (l *MiniTop5ArticleCommentLogic) 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{}
|
|
|
}
|
|
|
|
|
|
func NewArticleCommentItem(val *domain.ArticleComment) types.ArticleCommentItem {
|
|
|
item := types.ArticleCommentItem{
|
|
|
Id: val.Id,
|
...
|
...
|
|