正在显示
7 个修改的文件
包含
25 行增加
和
4 行删除
| @@ -544,6 +544,7 @@ type ( | @@ -544,6 +544,7 @@ type ( | ||
| 544 | MiniSearchArticleItem{ | 544 | MiniSearchArticleItem{ |
| 545 | ArticleId int64 `json:"articleId"` | 545 | ArticleId int64 `json:"articleId"` |
| 546 | Title string `json:"title"` | 546 | Title string `json:"title"` |
| 547 | + AuthorId int64 `json:"authorId"` | ||
| 547 | Author string `json:"author"` // 发布人 | 548 | Author string `json:"author"` // 发布人 |
| 548 | Avatar string `json:"avatar"`// 发布人的头像 | 549 | Avatar string `json:"avatar"`// 发布人的头像 |
| 549 | Images []string `json:"images"` | 550 | Images []string `json:"images"` |
| @@ -80,7 +80,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -80,7 +80,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | //获取作者信息 | 82 | //获取作者信息 |
| 83 | - author, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(req.UserId)) | 83 | + author, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(articleInfo.AuthorId)) |
| 84 | 84 | ||
| 85 | var meLoveFlag int | 85 | var meLoveFlag int |
| 86 | if req.UserId > 0 { | 86 | if req.UserId > 0 { |
| @@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
| 5 | 5 | ||
| 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
| 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
| 8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
| 8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
| 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | 10 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
| 10 | 11 | ||
| @@ -15,6 +16,7 @@ type MiniSearchArticlePageLogic struct { | @@ -15,6 +16,7 @@ type MiniSearchArticlePageLogic struct { | ||
| 15 | logx.Logger | 16 | logx.Logger |
| 16 | ctx context.Context | 17 | ctx context.Context |
| 17 | svcCtx *svc.ServiceContext | 18 | svcCtx *svc.ServiceContext |
| 19 | + userCache map[int64]*domain.User | ||
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic { | 22 | func NewMiniSearchArticlePageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSearchArticlePageLogic { |
| @@ -63,11 +65,13 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch | @@ -63,11 +65,13 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch | ||
| 63 | } | 65 | } |
| 64 | 66 | ||
| 65 | for i, val := range articleList { | 67 | for i, val := range articleList { |
| 68 | + author := l.getAuthor(conn, val.AuthorId) | ||
| 66 | item := types.MiniSearchArticleItem{ | 69 | item := types.MiniSearchArticleItem{ |
| 67 | ArticleId: val.Id, | 70 | ArticleId: val.Id, |
| 68 | Title: val.Title, | 71 | Title: val.Title, |
| 69 | - Author: val.Author.Name, | ||
| 70 | - Avatar: val.Author.Avatar, | 72 | + AuthorId: val.AuthorId, |
| 73 | + Author: author.Name, | ||
| 74 | + Avatar: author.Avatar, | ||
| 71 | Images: []string{}, | 75 | Images: []string{}, |
| 72 | CreatedAt: val.CreatedAt, | 76 | CreatedAt: val.CreatedAt, |
| 73 | MeReadFlag: 0, | 77 | MeReadFlag: 0, |
| @@ -84,3 +88,15 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch | @@ -84,3 +88,15 @@ func (l *MiniSearchArticlePageLogic) MiniSearchArticlePage(req *types.MiniSearch | ||
| 84 | 88 | ||
| 85 | return resp, nil | 89 | return resp, nil |
| 86 | } | 90 | } |
| 91 | + | ||
| 92 | +func (l *MiniSearchArticlePageLogic) getAuthor(conn transaction.Conn, userid int64) domain.User { | ||
| 93 | + if u, ok := l.userCache[userid]; ok { | ||
| 94 | + return *u | ||
| 95 | + } | ||
| 96 | + toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid) | ||
| 97 | + if err == nil { | ||
| 98 | + l.userCache[toUser.Id] = toUser | ||
| 99 | + return *toUser | ||
| 100 | + } | ||
| 101 | + return domain.User{} | ||
| 102 | +} |
| @@ -90,6 +90,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | @@ -90,6 +90,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | ||
| 90 | Height: h, | 90 | Height: h, |
| 91 | }) | 91 | }) |
| 92 | } | 92 | } |
| 93 | + | ||
| 93 | //检查文章可被哪些人查看 | 94 | //检查文章可被哪些人查看 |
| 94 | whoRead := []int64{} | 95 | whoRead := []int64{} |
| 95 | if len(req.WhoRead) > 0 { | 96 | if len(req.WhoRead) > 0 { |
| @@ -44,6 +44,8 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * | @@ -44,6 +44,8 @@ func (l *MiniUserNewsLogic) MiniUserNews(req *types.MiniUserNewsRequest) (resp * | ||
| 44 | ) | 44 | ) |
| 45 | if req.AuthorId > 0 { | 45 | if req.AuthorId > 0 { |
| 46 | users = []int64{req.AuthorId} | 46 | users = []int64{req.AuthorId} |
| 47 | + } else { | ||
| 48 | + users = append(users, user.Id) | ||
| 47 | } | 49 | } |
| 48 | if _, articles, err = l.svcCtx.ArticleRepository.FindAuthorsLatestArticle(l.ctx, conn, user.CompanyId, users, user.Id, req.LastArticleId, req.Size); err != nil { | 50 | if _, articles, err = l.svcCtx.ArticleRepository.FindAuthorsLatestArticle(l.ctx, conn, user.CompanyId, users, user.Id, req.LastArticleId, req.Size); err != nil { |
| 49 | return nil, xerr.NewErrMsgErr("获取快讯异常", err) | 51 | return nil, xerr.NewErrMsgErr("获取快讯异常", err) |
| @@ -1315,6 +1315,7 @@ type MiniSearchArticleResponse struct { | @@ -1315,6 +1315,7 @@ type MiniSearchArticleResponse struct { | ||
| 1315 | type MiniSearchArticleItem struct { | 1315 | type MiniSearchArticleItem struct { |
| 1316 | ArticleId int64 `json:"articleId"` | 1316 | ArticleId int64 `json:"articleId"` |
| 1317 | Title string `json:"title"` | 1317 | Title string `json:"title"` |
| 1318 | + AuthorId int64 `json:"authorId"` | ||
| 1318 | Author string `json:"author"` // 发布人 | 1319 | Author string `json:"author"` // 发布人 |
| 1319 | Avatar string `json:"avatar"` // 发布人的头像 | 1320 | Avatar string `json:"avatar"` // 发布人的头像 |
| 1320 | Images []string `json:"images"` | 1321 | Images []string `json:"images"` |
| @@ -176,7 +176,7 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex | @@ -176,7 +176,7 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex | ||
| 176 | queryFunc := func() (interface{}, error) { | 176 | queryFunc := func() (interface{}, error) { |
| 177 | tx = tx.Model(&ms). | 177 | tx = tx.Model(&ms). |
| 178 | Where("company_id=?", companyId). | 178 | Where("company_id=?", companyId). |
| 179 | - Where("author_id in (?)", append(authors, whoRead)). // 包含自己的文章 | 179 | + Where("author_id in (?)", authors). // 包含自己的文章 |
| 180 | Where(fmt.Sprintf("author_id = %d or target_user=0 or who_read @>'[%d]'", whoRead, whoRead)). | 180 | Where(fmt.Sprintf("author_id = %d or target_user=0 or who_read @>'[%d]'", whoRead, whoRead)). |
| 181 | Where("show = 1") | 181 | Where("show = 1") |
| 182 | if lastId > 0 { | 182 | if lastId > 0 { |
-
请 注册 或 登录 后发表评论