...
|
...
|
@@ -43,15 +43,26 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS |
|
|
}
|
|
|
authorIds := make([]int64, 0)
|
|
|
lo.ForEach(articles, func(item *domain.Article, index int) {
|
|
|
authorIds = append(authorIds, item.AuthorId)
|
|
|
})
|
|
|
//查询用户数据,重新赋值更新用户名称
|
|
|
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
|
|
|
lo.ForEach(articles, func(item *domain.Article, index int) {
|
|
|
images := make([]string, 0)
|
|
|
lo.ForEach(item.Images, func(img domain.Image, n int) {
|
|
|
images = append(images, img.Url)
|
|
|
})
|
|
|
author := item.Author.Name
|
|
|
for _, user := range users {
|
|
|
if user.Id == item.AuthorId {
|
|
|
author = user.Name
|
|
|
}
|
|
|
}
|
|
|
resp.List = append(resp.List, types.SystemArticleSearch{
|
|
|
Id: item.Id,
|
|
|
Title: item.Title,
|
|
|
AuthorId: item.AuthorId,
|
|
|
Author: item.Author.Name,
|
|
|
Author: author,
|
|
|
Images: images,
|
|
|
CreatedAt: item.CreatedAt,
|
|
|
CountLove: item.CountLove,
|
...
|
...
|
@@ -60,16 +71,6 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS |
|
|
Tags: nil,
|
|
|
TargetUser: int(item.TargetUser),
|
|
|
})
|
|
|
authorIds = append(authorIds, item.AuthorId)
|
|
|
})
|
|
|
//查询用户数据,重新赋值更新用户名称
|
|
|
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
|
|
|
lo.ForEach(resp.List, func(item types.SystemArticleSearch, index int) {
|
|
|
for _, user := range users {
|
|
|
if user.Id == item.AuthorId {
|
|
|
resp.List[index].Author = user.Name
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
return resp, nil
|
|
|
return
|
|
|
} |
...
|
...
|
|