作者 tangxvhui

Merge branch 'dev' into test

@@ -30,7 +30,10 @@ func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi @@ -30,7 +30,10 @@ func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi
30 func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, err error) { 30 func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (resp *types.MiniArticleGetResponse, err error) {
31 // 获取文章内容 31 // 获取文章内容
32 var conn = l.svcCtx.DefaultDBConn() 32 var conn = l.svcCtx.DefaultDBConn()
33 - 33 + companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
  34 + if err != nil {
  35 + return nil, xerr.NewErrMsgErr("读取公司数据失败", err)
  36 + }
34 articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id) 37 articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id)
35 if err != nil { 38 if err != nil {
36 return nil, xerr.NewErrMsgErr("读取文章内容失败", err) 39 return nil, xerr.NewErrMsgErr("读取文章内容失败", err)
@@ -66,6 +69,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( @@ -66,6 +69,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
66 } 69 }
67 return resp, nil 70 return resp, nil
68 } 71 }
  72 +
69 queryOption := domain.NewQueryOptions(). 73 queryOption := domain.NewQueryOptions().
70 WithFindOnly(). 74 WithFindOnly().
71 MustWithKV("articleId", articleInfo.Id) 75 MustWithKV("articleId", articleInfo.Id)
@@ -74,6 +78,10 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( @@ -74,6 +78,10 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
74 if err != nil { 78 if err != nil {
75 return nil, xerr.NewErrMsgErr("读取文章内容失败", err) 79 return nil, xerr.NewErrMsgErr("读取文章内容失败", err)
76 } 80 }
  81 +
  82 + //获取作者信息
  83 + author, _ := l.svcCtx.UserRepository.FindOne(l.ctx, conn, int64(req.UserId))
  84 +
77 var meLoveFlag int 85 var meLoveFlag int
78 if req.UserId > 0 { 86 if req.UserId > 0 {
79 // 获取我对文章的点赞标识 87 // 获取我对文章的点赞标识
@@ -120,10 +128,10 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( @@ -120,10 +128,10 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
120 AuthorId: articleInfo.AuthorId, 128 AuthorId: articleInfo.AuthorId,
121 Author: types.ArticleAuthor{ 129 Author: types.ArticleAuthor{
122 Id: articleInfo.Author.Id, 130 Id: articleInfo.Author.Id,
123 - Name: articleInfo.Author.Name,  
124 - Avatar: articleInfo.Author.Avatar,  
125 - Position: articleInfo.Author.Position,  
126 - Company: articleInfo.Author.Company, 131 + Name: "",
  132 + Avatar: "",
  133 + Position: "",
  134 + Company: companyInfo.Name,
127 }, 135 },
128 CreatedAt: articleInfo.CreatedAt, 136 CreatedAt: articleInfo.CreatedAt,
129 Section: articleSection, 137 Section: articleSection,
@@ -148,7 +156,15 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( @@ -148,7 +156,15 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
148 if len(backupList) > 0 { 156 if len(backupList) > 0 {
149 resp.Edit = 1 157 resp.Edit = 1
150 } 158 }
151 - 159 + if author != nil {
  160 + resp.Author = types.ArticleAuthor{
  161 + Id: articleInfo.Author.Id,
  162 + Name: author.Name,
  163 + Avatar: author.Avatar,
  164 + Position: author.Position,
  165 + Company: companyInfo.Name,
  166 + }
  167 + }
152 for k, v := range articleInfo.MatchUrl { 168 for k, v := range articleInfo.MatchUrl {
153 resp.MatchUrl[k] = v 169 resp.MatchUrl[k] = v
154 } 170 }
@@ -158,5 +174,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( @@ -158,5 +174,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
158 if follow != nil { 174 if follow != nil {
159 resp.MeFollowFlag = 1 175 resp.MeFollowFlag = 1
160 } 176 }
  177 + if resp.AuthorId == int64(req.UserId) {
  178 + // 作者本人在查看
  179 + resp.MeFollowFlag = 1
  180 + }
161 return 181 return
162 } 182 }
@@ -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
@@ -13,21 +14,27 @@ import ( @@ -13,21 +14,27 @@ import (
13 14
14 type MiniGetArticleCommentLogic struct { 15 type MiniGetArticleCommentLogic struct {
15 logx.Logger 16 logx.Logger
16 - ctx context.Context  
17 - svcCtx *svc.ServiceContext 17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 + userCache map[int64]types.CommentAuthor
18 } 20 }
19 21
20 func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic { 22 func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic {
21 return &MiniGetArticleCommentLogic{ 23 return &MiniGetArticleCommentLogic{
22 - Logger: logx.WithContext(ctx),  
23 - ctx: ctx,  
24 - svcCtx: svcCtx, 24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + userCache: make(map[int64]types.CommentAuthor),
25 } 28 }
26 } 29 }
27 30
28 // 获取单条评论详情 31 // 获取单条评论详情
29 func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) { 32 func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) {
30 var conn = l.svcCtx.DefaultDBConn() 33 var conn = l.svcCtx.DefaultDBConn()
  34 + companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
  35 + if err != nil {
  36 + return nil, xerr.NewErrMsgErr("读取公司数据失败", err)
  37 + }
31 //获取主评论 38 //获取主评论
32 commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId) 39 commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId)
33 if err != nil { 40 if err != nil {
@@ -38,10 +45,14 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -38,10 +45,14 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
38 } 45 }
39 46
40 if commentInfo.Show == domain.CommentShowDisable { 47 if commentInfo.Show == domain.CommentShowDisable {
41 - return nil, xerr.NewErrMsg("没有查看权限") 48 + return nil, xerr.NewErrMsg("具体评论已被关闭")
42 } 49 }
43 - queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("topId", commentInfo.Id).MustWithKV("show", domain.CommentShowEnable)  
44 - //获取回复的评论 50 +
  51 + queryOption := domain.NewQueryOptions().
  52 + WithFindOnly().
  53 + MustWithKV("topId", commentInfo.Id).
  54 + MustWithKV("show", domain.CommentShowEnable)
  55 + // 获取回复的评论
45 _, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption) 56 _, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
46 57
47 if err != nil { 58 if err != nil {
@@ -60,30 +71,17 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -60,30 +71,17 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
60 for _, val := range userFlagList { 71 for _, val := range userFlagList {
61 flagMap[val.CommentId] = struct{}{} 72 flagMap[val.CommentId] = struct{}{}
62 } 73 }
63 -  
64 //混合数据 74 //混合数据
65 commentResp := types.ArticleCommentItem{ 75 commentResp := types.ArticleCommentItem{
66 - Id: commentInfo.Id,  
67 - Pid: commentInfo.Pid,  
68 - TopId: commentInfo.TopId,  
69 - ArtitcleId: commentInfo.ArticleId,  
70 - SectionId: commentInfo.ArticleId,  
71 - FromUserId: commentInfo.FromUserId,  
72 - FromUser: types.CommentAuthor{  
73 - Id: commentInfo.FromUser.Id,  
74 - Name: commentInfo.FromUser.Name,  
75 - Avatar: commentInfo.FromUser.Avatar,  
76 - Position: commentInfo.FromUser.Position,  
77 - Company: commentInfo.FromUser.Company,  
78 - },  
79 - ToUserId: commentInfo.ToUserId,  
80 - ToUser: types.CommentAuthor{  
81 - Id: commentInfo.ToUser.Id,  
82 - Name: commentInfo.ToUser.Name,  
83 - Avatar: commentInfo.ToUser.Avatar,  
84 - Position: commentInfo.ToUser.Position,  
85 - Company: commentInfo.ToUser.Company,  
86 - }, 76 + Id: commentInfo.Id,
  77 + Pid: commentInfo.Pid,
  78 + TopId: commentInfo.TopId,
  79 + ArtitcleId: commentInfo.ArticleId,
  80 + SectionId: commentInfo.ArticleId,
  81 + FromUserId: commentInfo.FromUserId,
  82 + FromUser: l.getCommentAuthor(conn, commentInfo.FromUserId, companyInfo.Name),
  83 + ToUserId: commentInfo.ToUserId,
  84 + ToUser: l.getCommentAuthor(conn, commentInfo.ToUserId, companyInfo.Name),
87 SectionContent: commentInfo.SectionContent, 85 SectionContent: commentInfo.SectionContent,
88 CountReply: commentInfo.CountReply, 86 CountReply: commentInfo.CountReply,
89 CountUserLove: commentInfo.CountUserLove, 87 CountUserLove: commentInfo.CountUserLove,
@@ -110,27 +108,15 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -110,27 +108,15 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
110 allReply := []types.ArticleCommentItem{} 108 allReply := []types.ArticleCommentItem{}
111 for _, val := range replyCommenList { 109 for _, val := range replyCommenList {
112 reply := types.ArticleCommentItem{ 110 reply := types.ArticleCommentItem{
113 - Id: val.Id,  
114 - Pid: val.Pid,  
115 - TopId: val.TopId,  
116 - ArtitcleId: val.ArticleId,  
117 - SectionId: val.SectionId,  
118 - FromUserId: val.FromUserId,  
119 - FromUser: types.CommentAuthor{  
120 - Id: val.FromUser.Id,  
121 - Name: val.FromUser.Name,  
122 - Avatar: val.FromUser.Avatar,  
123 - Position: val.FromUser.Position,  
124 - Company: val.FromUser.Company,  
125 - },  
126 - ToUserId: val.ToUserId,  
127 - ToUser: types.CommentAuthor{  
128 - Id: val.ToUser.Id,  
129 - Name: val.ToUser.Name,  
130 - Avatar: val.ToUser.Avatar,  
131 - Position: val.ToUser.Position,  
132 - Company: val.ToUser.Company,  
133 - }, 111 + Id: val.Id,
  112 + Pid: val.Pid,
  113 + TopId: val.TopId,
  114 + ArtitcleId: val.ArticleId,
  115 + SectionId: val.SectionId,
  116 + FromUserId: val.FromUserId,
  117 + FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name),
  118 + ToUserId: val.ToUserId,
  119 + ToUser: l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name),
134 SectionContent: "", 120 SectionContent: "",
135 CountReply: val.CountReply, 121 CountReply: val.CountReply,
136 CountUserLove: val.CountUserLove, 122 CountUserLove: val.CountUserLove,
@@ -141,6 +127,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -141,6 +127,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
141 MeLoveFlag: 0, 127 MeLoveFlag: 0,
142 Content: val.Content, 128 Content: val.Content,
143 } 129 }
  130 +
144 if _, ok := flagMap[val.Id]; ok { 131 if _, ok := flagMap[val.Id]; ok {
145 reply.MeLoveFlag = 1 132 reply.MeLoveFlag = 1
146 } 133 }
@@ -164,3 +151,22 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -164,3 +151,22 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
164 } 151 }
165 return 152 return
166 } 153 }
  154 +
  155 +func (l *MiniGetArticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor {
  156 + if u, ok := l.userCache[userid]; ok {
  157 + return u
  158 + }
  159 + toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
  160 + if err == nil {
  161 + commentToUser := types.CommentAuthor{
  162 + Id: toUser.Id,
  163 + Name: toUser.Name,
  164 + Avatar: toUser.Avatar,
  165 + Position: toUser.Position,
  166 + Company: companyName,
  167 + }
  168 + l.userCache[toUser.Id] = commentToUser
  169 + return commentToUser
  170 + }
  171 + return types.CommentAuthor{}
  172 +}
@@ -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
@@ -13,15 +14,17 @@ import ( @@ -13,15 +14,17 @@ import (
13 14
14 type MiniListArticleCommentLogic struct { 15 type MiniListArticleCommentLogic struct {
15 logx.Logger 16 logx.Logger
16 - ctx context.Context  
17 - svcCtx *svc.ServiceContext 17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 + userCache map[int64]types.CommentAuthor
18 } 20 }
19 21
20 func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListArticleCommentLogic { 22 func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListArticleCommentLogic {
21 return &MiniListArticleCommentLogic{ 23 return &MiniListArticleCommentLogic{
22 - Logger: logx.WithContext(ctx),  
23 - ctx: ctx,  
24 - svcCtx: svcCtx, 24 + Logger: logx.WithContext(ctx),
  25 + ctx: ctx,
  26 + svcCtx: svcCtx,
  27 + userCache: make(map[int64]types.CommentAuthor),
25 } 28 }
26 } 29 }
27 30
@@ -29,6 +32,10 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont @@ -29,6 +32,10 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont
29 func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) { 32 func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
30 // 先获取最顶层的评论 33 // 先获取最顶层的评论
31 var conn = l.svcCtx.DefaultDBConn() 34 var conn = l.svcCtx.DefaultDBConn()
  35 + companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, req.CompanyId)
  36 + if err != nil {
  37 + return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
  38 + }
32 if req.Size > 40 { 39 if req.Size > 40 {
33 req.Size = 40 40 req.Size = 40
34 } 41 }
@@ -54,7 +61,6 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList @@ -54,7 +61,6 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList
54 } 61 }
55 return 62 return
56 } 63 }
57 -  
58 queryOption = domain.NewQueryOptions().WithFindOnly(). 64 queryOption = domain.NewQueryOptions().WithFindOnly().
59 MustWithKV("articleId", req.ArticleId). 65 MustWithKV("articleId", req.ArticleId).
60 MustWithKV("userId", req.UserId) 66 MustWithKV("userId", req.UserId)
@@ -76,27 +82,15 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList @@ -76,27 +82,15 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList
76 for i, val := range commentList { 82 for i, val := range commentList {
77 item := types.ArticleCommentAndReply{ 83 item := types.ArticleCommentAndReply{
78 Comment: types.ArticleCommentItem{ 84 Comment: types.ArticleCommentItem{
79 - Id: val.Id,  
80 - Pid: val.Pid,  
81 - TopId: val.TopId,  
82 - ArtitcleId: val.ArticleId,  
83 - SectionId: val.SectionId,  
84 - FromUserId: val.FromUserId,  
85 - FromUser: types.CommentAuthor{  
86 - Id: val.FromUser.Id,  
87 - Name: val.FromUser.Name,  
88 - Avatar: val.FromUser.Avatar,  
89 - Position: val.FromUser.Position,  
90 - Company: val.FromUser.Company,  
91 - },  
92 - ToUserId: val.ToUserId,  
93 - ToUser: types.CommentAuthor{  
94 - Id: val.ToUser.Id,  
95 - Name: val.ToUser.Name,  
96 - Avatar: val.ToUser.Avatar,  
97 - Position: val.ToUser.Position,  
98 - Company: val.ToUser.Company,  
99 - }, 85 + Id: val.Id,
  86 + Pid: val.Pid,
  87 + TopId: val.TopId,
  88 + ArtitcleId: val.ArticleId,
  89 + SectionId: val.SectionId,
  90 + FromUserId: val.FromUserId,
  91 + FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name),
  92 + ToUserId: val.ToUserId,
  93 + ToUser: l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name),
100 SectionContent: val.SectionContent, 94 SectionContent: val.SectionContent,
101 CountReply: val.CountReply, 95 CountReply: val.CountReply,
102 CountUserLove: val.CountUserLove, 96 CountUserLove: val.CountUserLove,
@@ -126,7 +120,6 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList @@ -126,7 +120,6 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList
126 120
127 //获取回复的评论 121 //获取回复的评论
128 cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap) 122 cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap)
129 -  
130 resp.List[i] = item 123 resp.List[i] = item
131 resp.List[i].Reply = reply 124 resp.List[i].Reply = reply
132 resp.List[i].TotalReply = cntReply 125 resp.List[i].TotalReply = cntReply
@@ -137,6 +130,10 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList @@ -137,6 +130,10 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList
137 // listCommentReply 130 // listCommentReply
138 func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) { 131 func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
139 var conn = l.svcCtx.DefaultDBConn() 132 var conn = l.svcCtx.DefaultDBConn()
  133 + companyInfo, err := l.svcCtx.CompanyRepository.FindOne(l.ctx, conn, commentId)
  134 + if err != nil {
  135 + return 0, []types.ArticleCommentItem{}
  136 + }
140 queryOption := domain.NewQueryOptions(). 137 queryOption := domain.NewQueryOptions().
141 WithOffsetLimit(1, 2). 138 WithOffsetLimit(1, 2).
142 MustWithKV("topId", commentId). 139 MustWithKV("topId", commentId).
@@ -153,27 +150,15 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag @@ -153,27 +150,15 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag
153 150
154 for _, val := range commentList { 151 for _, val := range commentList {
155 item := types.ArticleCommentItem{ 152 item := types.ArticleCommentItem{
156 - Id: val.Id,  
157 - Pid: val.Pid,  
158 - TopId: val.TopId,  
159 - ArtitcleId: val.ArticleId,  
160 - SectionId: val.SectionId,  
161 - FromUserId: val.FromUserId,  
162 - FromUser: types.CommentAuthor{  
163 - Id: val.FromUser.Id,  
164 - Name: val.FromUser.Name,  
165 - Avatar: val.FromUser.Avatar,  
166 - Position: val.FromUser.Position,  
167 - Company: val.FromUser.Company,  
168 - },  
169 - ToUserId: val.ToUserId,  
170 - ToUser: types.CommentAuthor{  
171 - Id: val.ToUser.Id,  
172 - Name: val.ToUser.Name,  
173 - Avatar: val.ToUser.Avatar,  
174 - Position: val.ToUser.Position,  
175 - Company: val.ToUser.Company,  
176 - }, 153 + Id: val.Id,
  154 + Pid: val.Pid,
  155 + TopId: val.TopId,
  156 + ArtitcleId: val.ArticleId,
  157 + SectionId: val.SectionId,
  158 + FromUserId: val.FromUserId,
  159 + FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name),
  160 + ToUserId: val.ToUserId,
  161 + ToUser: l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name),
177 SectionContent: "", //不设置值 162 SectionContent: "", //不设置值
178 CountReply: val.CountReply, 163 CountReply: val.CountReply,
179 CountUserLove: val.CountUserLove, 164 CountUserLove: val.CountUserLove,
@@ -184,7 +169,6 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag @@ -184,7 +169,6 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag
184 MeLoveFlag: 0, 169 MeLoveFlag: 0,
185 Content: val.Content, 170 Content: val.Content,
186 } 171 }
187 -  
188 if _, ok := loveFlagMap[val.Id]; ok { 172 if _, ok := loveFlagMap[val.Id]; ok {
189 item.MeLoveFlag = 1 173 item.MeLoveFlag = 1
190 } 174 }
@@ -201,3 +185,22 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag @@ -201,3 +185,22 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag
201 } 185 }
202 return cnt, replyList 186 return cnt, replyList
203 } 187 }
  188 +
  189 +func (l *MiniListArticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor {
  190 + if u, ok := l.userCache[userid]; ok {
  191 + return u
  192 + }
  193 + toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid)
  194 + if err == nil {
  195 + commentToUser := types.CommentAuthor{
  196 + Id: toUser.Id,
  197 + Name: toUser.Name,
  198 + Avatar: toUser.Avatar,
  199 + Position: toUser.Position,
  200 + Company: companyName,
  201 + }
  202 + l.userCache[toUser.Id] = commentToUser
  203 + return commentToUser
  204 + }
  205 + return types.CommentAuthor{}
  206 +}