作者 庄敏学

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

... ... @@ -374,7 +374,7 @@ type (
SystemArticleSearchRequest {
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
Author int64 `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Tags []int64 `json:"tags,optional"` //标签
... ... @@ -389,6 +389,7 @@ type (
SystemArticleSearch {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"author"` //发布人ID
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
... ...
... ... @@ -258,7 +258,7 @@ type (
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author string `json:"author,optional"` // 用户
Author int64 `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
... ...
... ... @@ -30,7 +30,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
WithKV("title", req.Title).
WithKV("author", req.Author).
WithKV("authorId", req.Author).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
total, articles, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, req.CompanyId, queryOptions)
... ... @@ -41,6 +41,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
Total: int(total),
List: make([]types.SystemArticleSearch, 0),
}
authorIds := make([]int64, 0)
lo.ForEach(articles, func(item *domain.Article, index int) {
images := make([]string, 0)
lo.ForEach(item.Images, func(img domain.Image, n int) {
... ... @@ -49,6 +50,7 @@ func (l *SystemSearchArticleLogic) SystemSearchArticle(req *types.SystemArticleS
resp.List = append(resp.List, types.SystemArticleSearch{
Id: item.Id,
Title: item.Title,
AuthorId: item.AuthorId,
Author: item.Author.Name,
Images: images,
CreatedAt: item.CreatedAt,
... ... @@ -58,6 +60,16 @@ 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
}
... ...
... ... @@ -35,9 +35,11 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
WithKV("articleId", req.ArticleId).
WithKV("topId", req.TopId).
WithKV("show", req.Show).
WithKV("fromUserName", req.Author).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
if req.Author > 0 {
queryOptions = queryOptions.WithKV("fromUserId", req.Author)
}
total, comments, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章评论失败", err)
... ... @@ -46,6 +48,7 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
Total: total,
List: make([]types.SystemArticleCommentSearchItem, 0),
}
authorIds := make([]int64, 0)
lo.ForEach(comments, func(item *domain.ArticleComment, index int) {
resp.List = append(resp.List, types.SystemArticleCommentSearchItem{
Id: item.Id,
... ... @@ -68,6 +71,22 @@ func (l *SystemArticleCommentSearchLogic) SystemArticleCommentSearch(req *types.
Content: item.Content,
Show: int(item.Show),
})
authorIds = append(authorIds, item.FromUserId)
})
//查询用户数据,重新赋值更新用户名称
_, users, _ := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().WithFindOnly().WithKV("ids", authorIds))
lo.ForEach(resp.List, func(item types.SystemArticleCommentSearchItem, index int) {
for _, user := range users {
if user.Id == item.FromUserId {
resp.List[index].FromUser = types.CommentAuthor{
Id: user.Id,
Name: user.Name,
Avatar: user.Avatar,
Position: user.Position,
Company: item.FromUser.Company,
}
}
}
})
return
}
... ...
... ... @@ -165,14 +165,14 @@ type SystemArticleCommentSearchMeResponse struct {
}
type SystemArticleCommentSearchRequest struct {
Page int `json:"page"`
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author string `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
Page int `json:"page"`
Size int `json:"size"`
ArticleId int64 `json:"articleId"` // 文章ID
TopId int64 `json:"topId,optional"` // 文章顶层ID
Author int64 `json:"author,optional"` // 用户
Show int `json:"show,optional"` // 显示状态
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
type SystemArticleCommentSearchResponse struct {
... ... @@ -1156,7 +1156,7 @@ type SystemArticleGetResponse struct {
type SystemArticleSearchRequest struct {
CompanyId int64 `json:"companyId,optional"`
Title string `json:"title,optional"` //标题
Author string `json:"author,optional"` //发布人
Author int64 `json:"author,optional"` //发布人
BeginTime int64 `json:"beginTime,optional"` //开始时间
EndTime int64 `json:"endTime,optional"` //结束时间
Tags []int64 `json:"tags,optional"` //标签
... ... @@ -1172,6 +1172,7 @@ type SystemArticleSearchResponse struct {
type SystemArticleSearch struct {
Id int64 `json:"id"` //id
Title string `json:"title"` //标题
AuthorId int64 `json:"author"` //发布人ID
Author string `json:"author"` //发布人
Images []string `json:"images"` //图片
CreatedAt int64 `json:"createdAt"` //文章的创建日期
... ...
... ... @@ -127,9 +127,6 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["title"]; ok && v.(string) != "" {
tx = tx.Where("title like ?", "%"+v.(string)+"%")
}
if v, ok := queryOptions["author"]; ok && v.(string) != "" {
tx = tx.Where(`author #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
if v, ok := queryOptions["beginCreatedAt"]; ok {
tx = tx.Where("created_at >= ?", v)
}
... ...