Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev
正在显示
5 个修改的文件
包含
103 行增加
和
73 行删除
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | 服务端域名 http://sumifcc-discuss-test.sumifcc.com/ | 5 | 服务端域名 http://sumifcc-discuss-test.sumifcc.com/ |
| 6 | 日志地址 https://sumifcc-discuss-test.sumifcc.com/v1/log/access | 6 | 日志地址 https://sumifcc-discuss-test.sumifcc.com/v1/log/access |
| 7 | 管理后台“易数家“前端入口:https://digital-front-platform-dev.fjmaimaimai.com/ | 7 | 管理后台“易数家“前端入口:https://digital-front-platform-dev.fjmaimaimai.com/ |
| 8 | - 跳转后的实际管理后台地址: | 8 | + 跳转后的实际管理后台地址: https://sumifcc-x-front-test.sumifcc.com |
| 9 | 9 | ||
| 10 | ### 可设置环境变量 | 10 | ### 可设置环境变量 |
| 11 | - DataSource | 11 | - DataSource |
| @@ -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 | } |
| @@ -113,7 +113,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi | @@ -113,7 +113,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi | ||
| 113 | return nil, xerr.NewErrMsgErr("取消点赞标识失败", err) | 113 | return nil, xerr.NewErrMsgErr("取消点赞标识失败", err) |
| 114 | } | 114 | } |
| 115 | articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId) | 115 | articleInfo, err = l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId) |
| 116 | - if err == nil { | 116 | + if err != nil { |
| 117 | return nil, xerr.NewErrMsgErr("获取点赞数量失败", err) | 117 | return nil, xerr.NewErrMsgErr("获取点赞数量失败", err) |
| 118 | } | 118 | } |
| 119 | resp = &types.MiniSetUserLikeResponse{ | 119 | resp = &types.MiniSetUserLikeResponse{ |
| @@ -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 MiniGetArticleCommentLogic struct { | @@ -15,6 +16,7 @@ type MiniGetArticleCommentLogic 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]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 { |
| @@ -22,12 +24,17 @@ func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceConte | @@ -22,12 +24,17 @@ func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceConte | ||
| 22 | Logger: logx.WithContext(ctx), | 24 | Logger: logx.WithContext(ctx), |
| 23 | ctx: ctx, | 25 | ctx: ctx, |
| 24 | svcCtx: svcCtx, | 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,7 +71,6 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | @@ -60,7 +71,6 @@ 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, | 76 | Id: commentInfo.Id, |
| @@ -69,21 +79,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | @@ -69,21 +79,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | ||
| 69 | ArtitcleId: commentInfo.ArticleId, | 79 | ArtitcleId: commentInfo.ArticleId, |
| 70 | SectionId: commentInfo.ArticleId, | 80 | SectionId: commentInfo.ArticleId, |
| 71 | FromUserId: commentInfo.FromUserId, | 81 | 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 | - }, | 82 | + FromUser: l.getCommentAuthor(conn, commentInfo.FromUserId, companyInfo.Name), |
| 79 | ToUserId: commentInfo.ToUserId, | 83 | 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 | - }, | 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, |
| @@ -116,22 +114,10 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | @@ -116,22 +114,10 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | ||
| 116 | ArtitcleId: val.ArticleId, | 114 | ArtitcleId: val.ArticleId, |
| 117 | SectionId: val.SectionId, | 115 | SectionId: val.SectionId, |
| 118 | FromUserId: val.FromUserId, | 116 | 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 | - }, | 117 | + FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name), |
| 126 | ToUserId: val.ToUserId, | 118 | 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 | - }, | ||
| 134 | - SectionContent: val.SectionContent, | 119 | + ToUser: l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name), |
| 120 | + SectionContent: "", | ||
| 135 | CountReply: val.CountReply, | 121 | CountReply: val.CountReply, |
| 136 | CountUserLove: val.CountUserLove, | 122 | CountUserLove: val.CountUserLove, |
| 137 | CountAdminLove: val.CountAdminLove, | 123 | CountAdminLove: val.CountAdminLove, |
| @@ -139,7 +125,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | @@ -139,7 +125,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | ||
| 139 | MatchUrl: map[string]string{}, | 125 | MatchUrl: map[string]string{}, |
| 140 | CreatedAt: val.CreatedAt, | 126 | CreatedAt: val.CreatedAt, |
| 141 | MeLoveFlag: 0, | 127 | MeLoveFlag: 0, |
| 128 | + Content: val.Content, | ||
| 142 | } | 129 | } |
| 130 | + | ||
| 143 | if _, ok := flagMap[val.Id]; ok { | 131 | if _, ok := flagMap[val.Id]; ok { |
| 144 | reply.MeLoveFlag = 1 | 132 | reply.MeLoveFlag = 1 |
| 145 | } | 133 | } |
| @@ -163,3 +151,22 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | @@ -163,3 +151,22 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt | ||
| 163 | } | 151 | } |
| 164 | return | 152 | return |
| 165 | } | 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 | ||
| @@ -15,6 +16,7 @@ type MiniListArticleCommentLogic struct { | @@ -15,6 +16,7 @@ type MiniListArticleCommentLogic 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]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 { |
| @@ -22,6 +24,7 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont | @@ -22,6 +24,7 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont | ||
| 22 | Logger: logx.WithContext(ctx), | 24 | Logger: logx.WithContext(ctx), |
| 23 | ctx: ctx, | 25 | ctx: ctx, |
| 24 | svcCtx: svcCtx, | 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) |
| @@ -82,21 +88,9 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList | @@ -82,21 +88,9 @@ func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniList | ||
| 82 | ArtitcleId: val.ArticleId, | 88 | ArtitcleId: val.ArticleId, |
| 83 | SectionId: val.SectionId, | 89 | SectionId: val.SectionId, |
| 84 | FromUserId: val.FromUserId, | 90 | 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 | - }, | 91 | + FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name), |
| 92 | ToUserId: val.ToUserId, | 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 | - }, | 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). |
| @@ -159,22 +156,10 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag | @@ -159,22 +156,10 @@ func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlag | ||
| 159 | ArtitcleId: val.ArticleId, | 156 | ArtitcleId: val.ArticleId, |
| 160 | SectionId: val.SectionId, | 157 | SectionId: val.SectionId, |
| 161 | FromUserId: val.FromUserId, | 158 | 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 | - }, | 159 | + FromUser: l.getCommentAuthor(conn, val.FromUserId, companyInfo.Name), |
| 169 | ToUserId: val.ToUserId, | 160 | 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 | - }, | ||
| 177 | - SectionContent: val.SectionContent, | 161 | + ToUser: l.getCommentAuthor(conn, val.ToUserId, companyInfo.Name), |
| 162 | + SectionContent: "", //不设置值 | ||
| 178 | CountReply: val.CountReply, | 163 | CountReply: val.CountReply, |
| 179 | CountUserLove: val.CountUserLove, | 164 | CountUserLove: val.CountUserLove, |
| 180 | CountAdminLove: val.CountAdminLove, | 165 | CountAdminLove: val.CountAdminLove, |
| @@ -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 | +} |
-
请 注册 或 登录 后发表评论