...
|
...
|
@@ -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/pkg/xerr"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
...
|
...
|
@@ -12,15 +13,17 @@ import ( |
|
|
|
|
|
type SystemListAticleCommentLogic struct {
|
|
|
logx.Logger
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
ctx context.Context
|
|
|
svcCtx *svc.ServiceContext
|
|
|
userCache map[int64]types.CommentAuthor
|
|
|
}
|
|
|
|
|
|
func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListAticleCommentLogic {
|
|
|
return &SystemListAticleCommentLogic{
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
ctx: ctx,
|
|
|
svcCtx: svcCtx,
|
|
|
userCache: make(map[int64]types.CommentAuthor),
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -29,7 +32,7 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System |
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
|
|
|
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size,
|
|
|
req.TopId, req.ArticleTitle, req.Content, req.FromUser, req.Show, [2]int64{req.BeginTime, req.EndTime},
|
|
|
req.TopId, req.ArticleTitle, req.Content, req.FromUserId, req.Show, [2]int64{req.BeginTime, req.EndTime},
|
|
|
)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取评论列表失败", err)
|
...
|
...
|
@@ -42,18 +45,12 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System |
|
|
|
|
|
for i, val := range commentList {
|
|
|
resp.List[i] = types.SystemCommentItem{
|
|
|
Id: val.Id,
|
|
|
Pid: val.Pid,
|
|
|
TopId: val.TopId,
|
|
|
ArticleTitle: val.ArticleTitle,
|
|
|
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,
|
|
|
},
|
|
|
Id: val.Id,
|
|
|
Pid: val.Pid,
|
|
|
TopId: val.TopId,
|
|
|
ArticleTitle: val.ArticleTitle,
|
|
|
FromUserId: val.FromUserId,
|
|
|
FromUser: l.getCommentAuthor(conn, val.FromUserId, ""),
|
|
|
CreatedAt: val.CreatedAt,
|
|
|
Content: val.Content,
|
|
|
Show: val.Show,
|
...
|
...
|
@@ -65,3 +62,22 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System |
|
|
|
|
|
return resp, nil
|
|
|
}
|
|
|
|
|
|
func (l *SystemListAticleCommentLogic) 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{}
|
|
|
} |
...
|
...
|
|