作者 庄敏学

文章列表|文章中的评论发布人改为用户ID查询

@@ -374,7 +374,7 @@ type ( @@ -374,7 +374,7 @@ type (
374 SystemArticleSearchRequest { 374 SystemArticleSearchRequest {
375 CompanyId int64 `json:"companyId,optional"` 375 CompanyId int64 `json:"companyId,optional"`
376 Title string `json:"title,optional"` //标题 376 Title string `json:"title,optional"` //标题
377 - Author string `json:"author,optional"` //发布人 377 + Author int64 `json:"author,optional"` //发布人
378 BeginTime int64 `json:"beginTime,optional"` //开始时间 378 BeginTime int64 `json:"beginTime,optional"` //开始时间
379 EndTime int64 `json:"endTime,optional"` //结束时间 379 EndTime int64 `json:"endTime,optional"` //结束时间
380 Tags []int64 `json:"tags,optional"` //标签 380 Tags []int64 `json:"tags,optional"` //标签
@@ -389,6 +389,7 @@ type ( @@ -389,6 +389,7 @@ type (
389 SystemArticleSearch { 389 SystemArticleSearch {
390 Id int64 `json:"id"` //id 390 Id int64 `json:"id"` //id
391 Title string `json:"title"` //标题 391 Title string `json:"title"` //标题
  392 + AuthorId int64 `json:"author"` //发布人ID
392 Author string `json:"author"` //发布人 393 Author string `json:"author"` //发布人
393 Images []string `json:"images"` //图片 394 Images []string `json:"images"` //图片
394 CreatedAt int64 `json:"createdAt"` //文章的创建日期 395 CreatedAt int64 `json:"createdAt"` //文章的创建日期
@@ -258,7 +258,7 @@ type ( @@ -258,7 +258,7 @@ type (
258 Size int `json:"size"` 258 Size int `json:"size"`
259 ArticleId int64 `json:"articleId"` // 文章ID 259 ArticleId int64 `json:"articleId"` // 文章ID
260 TopId int64 `json:"topId,optional"` // 文章顶层ID 260 TopId int64 `json:"topId,optional"` // 文章顶层ID
261 - Author string `json:"author,optional"` // 用户 261 + Author int64 `json:"author,optional"` // 用户
262 Show int `json:"show,optional"` // 显示状态 262 Show int `json:"show,optional"` // 显示状态
263 BeginTime int64 `json:"beginTime,optional"` // 开始时间 263 BeginTime int64 `json:"beginTime,optional"` // 开始时间
264 EndTime int64 `json:"endTime,optional"` // 结束时间 264 EndTime int64 `json:"endTime,optional"` // 结束时间
@@ -30,7 +30,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS @@ -30,7 +30,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
30 queryOptions := domain.NewQueryOptions(). 30 queryOptions := domain.NewQueryOptions().
31 WithOffsetLimit(req.Page, req.Size). 31 WithOffsetLimit(req.Page, req.Size).
32 WithKV("title", req.Title). 32 WithKV("title", req.Title).
33 - WithKV("author", req.Author). 33 + WithKV("authorId", req.Author).
34 WithKV("beginCreatedAt", req.BeginTime). 34 WithKV("beginCreatedAt", req.BeginTime).
35 WithKV("endCreatedAt", req.EndTime) 35 WithKV("endCreatedAt", req.EndTime)
36 total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions) 36 total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
@@ -41,6 +41,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS @@ -41,6 +41,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
41 Total: int(total), 41 Total: int(total),
42 List: make([]types.SystemArticleSearch, 0), 42 List: make([]types.SystemArticleSearch, 0),
43 } 43 }
  44 + authorIds := make([]int64, 0)
44 lo.ForEach(articles, func(item *domain.Article, index int) { 45 lo.ForEach(articles, func(item *domain.Article, index int) {
45 images := make([]string, 0) 46 images := make([]string, 0)
46 lo.ForEach(item.Images, func(img domain.Image, n int) { 47 lo.ForEach(item.Images, func(img domain.Image, n int) {
@@ -49,6 +50,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS @@ -49,6 +50,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
49 resp.List = append(resp.List, types.SystemArticleSearch{ 50 resp.List = append(resp.List, types.SystemArticleSearch{
50 Id: item.Id, 51 Id: item.Id,
51 Title: item.Title, 52 Title: item.Title,
  53 + AuthorId: item.AuthorId,
52 Author: item.Author.Name, 54 Author: item.Author.Name,
53 Images: images, 55 Images: images,
54 CreatedAt: item.CreatedAt, 56 CreatedAt: item.CreatedAt,
@@ -58,6 +60,16 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS @@ -58,6 +60,16 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
58 Tags: nil, 60 Tags: nil,
59 TargetUser: int(item.TargetUser), 61 TargetUser: int(item.TargetUser),
60 }) 62 })
  63 + authorIds = append(authorIds, item.AuthorId)
  64 + })
  65 + //查询用户数据,重新赋值更新用户名称
  66 + _, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
  67 + lo.ForEach(resp.List, func(item types.SystemArticleSearch, index int) {
  68 + for _, user := range users {
  69 + if user.Id == item.AuthorId {
  70 + resp.List[index].Author = user.Name
  71 + }
  72 + }
61 }) 73 })
62 return resp, nil 74 return resp, nil
63 } 75 }
@@ -35,9 +35,11 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types. @@ -35,9 +35,11 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
35 WithKV("articleId", req.ArticleId). 35 WithKV("articleId", req.ArticleId).
36 WithKV("topId", req.TopId). 36 WithKV("topId", req.TopId).
37 WithKV("show", req.Show). 37 WithKV("show", req.Show).
38 - WithKV("fromUserName", req.Author).  
39 WithKV("beginCreatedAt", req.BeginTime). 38 WithKV("beginCreatedAt", req.BeginTime).
40 WithKV("endCreatedAt", req.EndTime) 39 WithKV("endCreatedAt", req.EndTime)
  40 + if req.Author > 0 {
  41 + queryOptions = queryOptions.WithKV("fromUserId", req.Author)
  42 + }
41 total, comments, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions) 43 total, comments, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions)
42 if err != nil { 44 if err != nil {
43 return nil, xerr.NewErrMsgErr("获取文章评论失败", err) 45 return nil, xerr.NewErrMsgErr("获取文章评论失败", err)
@@ -46,6 +48,7 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types. @@ -46,6 +48,7 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
46 Total: total, 48 Total: total,
47 List: make([]types.SystemArticleCommentSearchItem, 0), 49 List: make([]types.SystemArticleCommentSearchItem, 0),
48 } 50 }
  51 + authorIds := make([]int64, 0)
49 lo.ForEach(comments, func(item *domain.ArticleComment, index int) { 52 lo.ForEach(comments, func(item *domain.ArticleComment, index int) {
50 resp.List = append(resp.List, types.SystemArticleCommentSearchItem{ 53 resp.List = append(resp.List, types.SystemArticleCommentSearchItem{
51 Id: item.Id, 54 Id: item.Id,
@@ -68,6 +71,22 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types. @@ -68,6 +71,22 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
68 Content: item.Content, 71 Content: item.Content,
69 Show: int(item.Show), 72 Show: int(item.Show),
70 }) 73 })
  74 + authorIds = append(authorIds, item.FromUserId)
  75 + })
  76 + //查询用户数据,重新赋值更新用户名称
  77 + _, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
  78 + lo.ForEach(resp.List, func(item types.SystemArticleCommentSearchItem, index int) {
  79 + for _, user := range users {
  80 + if user.Id == item.FromUserId {
  81 + resp.List[index].FromUser = types.CommentAuthor{
  82 + Id: user.Id,
  83 + Name: user.Name,
  84 + Avatar: user.Avatar,
  85 + Position: user.Position,
  86 + Company: item.FromUser.Company,
  87 + }
  88 + }
  89 + }
71 }) 90 })
72 return 91 return
73 } 92 }
@@ -169,7 +169,7 @@ type SystemArticleCommentSearchRequest struct { @@ -169,7 +169,7 @@ type SystemArticleCommentSearchRequest struct {
169 Size int `json:"size"` 169 Size int `json:"size"`
170 ArticleId int64 `json:"articleId"` // 文章ID 170 ArticleId int64 `json:"articleId"` // 文章ID
171 TopId int64 `json:"topId,optional"` // 文章顶层ID 171 TopId int64 `json:"topId,optional"` // 文章顶层ID
172 - Author string `json:"author,optional"` // 用户 172 + Author int64 `json:"author,optional"` // 用户
173 Show int `json:"show,optional"` // 显示状态 173 Show int `json:"show,optional"` // 显示状态
174 BeginTime int64 `json:"beginTime,optional"` // 开始时间 174 BeginTime int64 `json:"beginTime,optional"` // 开始时间
175 EndTime int64 `json:"endTime,optional"` // 结束时间 175 EndTime int64 `json:"endTime,optional"` // 结束时间
@@ -1156,7 +1156,7 @@ type SystemArticleGetResponse struct { @@ -1156,7 +1156,7 @@ type SystemArticleGetResponse struct {
1156 type SystemArticleSearchRequest struct { 1156 type SystemArticleSearchRequest struct {
1157 CompanyId int64 `json:"companyId,optional"` 1157 CompanyId int64 `json:"companyId,optional"`
1158 Title string `json:"title,optional"` //标题 1158 Title string `json:"title,optional"` //标题
1159 - Author string `json:"author,optional"` //发布人 1159 + Author int64 `json:"author,optional"` //发布人
1160 BeginTime int64 `json:"beginTime,optional"` //开始时间 1160 BeginTime int64 `json:"beginTime,optional"` //开始时间
1161 EndTime int64 `json:"endTime,optional"` //结束时间 1161 EndTime int64 `json:"endTime,optional"` //结束时间
1162 Tags []int64 `json:"tags,optional"` //标签 1162 Tags []int64 `json:"tags,optional"` //标签
@@ -1172,6 +1172,7 @@ type SystemArticleSearchResponse struct { @@ -1172,6 +1172,7 @@ type SystemArticleSearchResponse struct {
1172 type SystemArticleSearch struct { 1172 type SystemArticleSearch struct {
1173 Id int64 `json:"id"` //id 1173 Id int64 `json:"id"` //id
1174 Title string `json:"title"` //标题 1174 Title string `json:"title"` //标题
  1175 + AuthorId int64 `json:"author"` //发布人ID
1175 Author string `json:"author"` //发布人 1176 Author string `json:"author"` //发布人
1176 Images []string `json:"images"` //图片 1177 Images []string `json:"images"` //图片
1177 CreatedAt int64 `json:"createdAt"` //文章的创建日期 1178 CreatedAt int64 `json:"createdAt"` //文章的创建日期
@@ -127,9 +127,6 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction. @@ -127,9 +127,6 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
127 if v, ok := queryOptions["title"]; ok && v.(string) != "" { 127 if v, ok := queryOptions["title"]; ok && v.(string) != "" {
128 tx = tx.Where("title like ?", "%"+v.(string)+"%") 128 tx = tx.Where("title like ?", "%"+v.(string)+"%")
129 } 129 }
130 - if v, ok := queryOptions["author"]; ok && v.(string) != "" {  
131 - tx = tx.Where(`author #>> '{"name"}' like ?`, "%"+v.(string)+"%")  
132 - }  
133 if v, ok := queryOptions["beginCreatedAt"]; ok { 130 if v, ok := queryOptions["beginCreatedAt"]; ok {
134 tx = tx.Where("created_at >= ?", v) 131 tx = tx.Where("created_at >= ?", v)
135 } 132 }