...
|
...
|
@@ -43,33 +43,47 @@ 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))
|
|
|
//获取标签
|
|
|
_, tags, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, domain.NewQueryOptions())
|
|
|
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
|
|
|
}
|
|
|
}
|
|
|
//标签
|
|
|
articleTags := make([]string, 0)
|
|
|
lo.ForEach(item.Tags, func(tagId int64, index int) {
|
|
|
for _, t := range tags {
|
|
|
if t.Id == tagId {
|
|
|
articleTags = append(articleTags, t.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,
|
|
|
CountComment: item.CountComment,
|
|
|
Show: int(item.Show),
|
|
|
Tags: nil,
|
|
|
Tags: articleTags,
|
|
|
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
|
|
|
} |
...
|
...
|
|