正在显示
6 个修改的文件
包含
32 行增加
和
17 行删除
@@ -293,7 +293,7 @@ type ( | @@ -293,7 +293,7 @@ type ( | ||
293 | Size int `json:"size"` | 293 | Size int `json:"size"` |
294 | CompanyId int64 `json:",optional"` // | 294 | CompanyId int64 `json:",optional"` // |
295 | TopId int64 `json:"topId,optional"` // 评论的顶层ID | 295 | TopId int64 `json:"topId,optional"` // 评论的顶层ID |
296 | - FromUser string `json:"fromUser,optional"` // 用户 | 296 | + FromUserId int64 `json:"fromUserId,optional"` // 用户 |
297 | Show int `json:"show,optional"` // 显示状态 | 297 | Show int `json:"show,optional"` // 显示状态 |
298 | BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 | 298 | BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 |
299 | EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间 | 299 | EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间 |
@@ -11,6 +11,7 @@ import ( | @@ -11,6 +11,7 @@ import ( | ||
11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | 11 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" |
12 | ) | 12 | ) |
13 | 13 | ||
14 | +// 管理后台的评论列表 | ||
14 | func SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | 15 | func SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { |
15 | return func(w http.ResponseWriter, r *http.Request) { | 16 | return func(w http.ResponseWriter, r *http.Request) { |
16 | var req types.SystemListCommentRequest | 17 | var req types.SystemListCommentRequest |
@@ -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/pkg/xerr" | 9 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" |
9 | 10 | ||
10 | "github.com/zeromicro/go-zero/core/logx" | 11 | "github.com/zeromicro/go-zero/core/logx" |
@@ -14,6 +15,7 @@ type SystemListAticleCommentLogic struct { | @@ -14,6 +15,7 @@ type SystemListAticleCommentLogic struct { | ||
14 | logx.Logger | 15 | logx.Logger |
15 | ctx context.Context | 16 | ctx context.Context |
16 | svcCtx *svc.ServiceContext | 17 | svcCtx *svc.ServiceContext |
18 | + userCache map[int64]types.CommentAuthor | ||
17 | } | 19 | } |
18 | 20 | ||
19 | func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListAticleCommentLogic { | 21 | func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListAticleCommentLogic { |
@@ -21,6 +23,7 @@ func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCon | @@ -21,6 +23,7 @@ func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCon | ||
21 | Logger: logx.WithContext(ctx), | 23 | Logger: logx.WithContext(ctx), |
22 | ctx: ctx, | 24 | ctx: ctx, |
23 | svcCtx: svcCtx, | 25 | svcCtx: svcCtx, |
26 | + userCache: make(map[int64]types.CommentAuthor), | ||
24 | } | 27 | } |
25 | } | 28 | } |
26 | 29 | ||
@@ -29,7 +32,7 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System | @@ -29,7 +32,7 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System | ||
29 | var conn = l.svcCtx.DefaultDBConn() | 32 | var conn = l.svcCtx.DefaultDBConn() |
30 | 33 | ||
31 | cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size, | 34 | cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size, |
32 | - req.TopId, req.ArticleTitle, req.Content, req.FromUser, req.Show, [2]int64{req.BeginTime, req.EndTime}, | 35 | + req.TopId, req.ArticleTitle, req.Content, req.FromUserId, req.Show, [2]int64{req.BeginTime, req.EndTime}, |
33 | ) | 36 | ) |
34 | if err != nil { | 37 | if err != nil { |
35 | return nil, xerr.NewErrMsgErr("获取评论列表失败", err) | 38 | return nil, xerr.NewErrMsgErr("获取评论列表失败", err) |
@@ -47,13 +50,7 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System | @@ -47,13 +50,7 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System | ||
47 | TopId: val.TopId, | 50 | TopId: val.TopId, |
48 | ArticleTitle: val.ArticleTitle, | 51 | ArticleTitle: val.ArticleTitle, |
49 | FromUserId: val.FromUserId, | 52 | FromUserId: val.FromUserId, |
50 | - FromUser: types.CommentAuthor{ | ||
51 | - Id: val.FromUser.Id, | ||
52 | - Name: val.FromUser.Name, | ||
53 | - Avatar: val.FromUser.Avatar, | ||
54 | - Position: val.FromUser.Position, | ||
55 | - Company: val.FromUser.Company, | ||
56 | - }, | 53 | + FromUser: l.getCommentAuthor(conn, val.FromUserId, ""), |
57 | CreatedAt: val.CreatedAt, | 54 | CreatedAt: val.CreatedAt, |
58 | Content: val.Content, | 55 | Content: val.Content, |
59 | Show: val.Show, | 56 | Show: val.Show, |
@@ -65,3 +62,22 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System | @@ -65,3 +62,22 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System | ||
65 | 62 | ||
66 | return resp, nil | 63 | return resp, nil |
67 | } | 64 | } |
65 | + | ||
66 | +func (l *SystemListAticleCommentLogic) getCommentAuthor(conn transaction.Conn, userid int64, companyName string) types.CommentAuthor { | ||
67 | + if u, ok := l.userCache[userid]; ok { | ||
68 | + return u | ||
69 | + } | ||
70 | + toUser, err := l.svcCtx.UserRepository.FindOne(l.ctx, conn, userid) | ||
71 | + if err == nil { | ||
72 | + commentToUser := types.CommentAuthor{ | ||
73 | + Id: toUser.Id, | ||
74 | + Name: toUser.Name, | ||
75 | + Avatar: toUser.Avatar, | ||
76 | + Position: toUser.Position, | ||
77 | + Company: companyName, | ||
78 | + } | ||
79 | + l.userCache[toUser.Id] = commentToUser | ||
80 | + return commentToUser | ||
81 | + } | ||
82 | + return types.CommentAuthor{} | ||
83 | +} |
@@ -203,7 +203,7 @@ type SystemListCommentRequest struct { | @@ -203,7 +203,7 @@ type SystemListCommentRequest struct { | ||
203 | Size int `json:"size"` | 203 | Size int `json:"size"` |
204 | CompanyId int64 `json:",optional"` // | 204 | CompanyId int64 `json:",optional"` // |
205 | TopId int64 `json:"topId,optional"` // 评论的顶层ID | 205 | TopId int64 `json:"topId,optional"` // 评论的顶层ID |
206 | - FromUser string `json:"fromUser,optional"` // 用户 | 206 | + FromUserId int64 `json:"fromUserId,optional"` // 用户 |
207 | Show int `json:"show,optional"` // 显示状态 | 207 | Show int `json:"show,optional"` // 显示状态 |
208 | BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 | 208 | BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 |
209 | EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间 | 209 | EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间 |
@@ -337,7 +337,7 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con | @@ -337,7 +337,7 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con | ||
337 | } | 337 | } |
338 | 338 | ||
339 | func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int, | 339 | func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int, |
340 | - topId int64, articleTitle string, contentLike string, fromUserName string, show int, createdAtRange [2]int64) (int, []*domain.ArticleCommentShow, error) { | 340 | + topId int64, articleTitle string, contentLike string, fromUserId int64, show int, createdAtRange [2]int64) (int, []*domain.ArticleCommentShow, error) { |
341 | 341 | ||
342 | if size <= 0 { | 342 | if size <= 0 { |
343 | size = 20 | 343 | size = 20 |
@@ -358,9 +358,9 @@ func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, | @@ -358,9 +358,9 @@ func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, | ||
358 | condition = append(condition, "%"+contentLike+"%") | 358 | condition = append(condition, "%"+contentLike+"%") |
359 | } | 359 | } |
360 | 360 | ||
361 | - if len(fromUserName) > 0 { | ||
362 | - where += ` and article_comment.from_user ->>'name' like ? ` | ||
363 | - condition = append(condition, "%"+fromUserName+"%") | 361 | + if fromUserId > 0 { |
362 | + where += ` and article_comment.from_user_id = ? ` | ||
363 | + condition = append(condition, fromUserId) | ||
364 | } | 364 | } |
365 | if show > 0 { | 365 | if show > 0 { |
366 | where += ` and article_comment."show" =? ` | 366 | where += ` and article_comment."show" =? ` |
@@ -425,7 +425,6 @@ func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, | @@ -425,7 +425,6 @@ func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, | ||
425 | ArticleTitle: val.ArticleTitle, | 425 | ArticleTitle: val.ArticleTitle, |
426 | Id: val.Id, | 426 | Id: val.Id, |
427 | FromUserId: val.FromUserId, | 427 | FromUserId: val.FromUserId, |
428 | - FromUser: val.FromUser, | ||
429 | Content: val.Content, | 428 | Content: val.Content, |
430 | CountReply: val.CountReply, | 429 | CountReply: val.CountReply, |
431 | CountUserLove: val.CountUserLove, | 430 | CountUserLove: val.CountUserLove, |
@@ -57,7 +57,6 @@ type ArticleCommentShow struct { | @@ -57,7 +57,6 @@ type ArticleCommentShow struct { | ||
57 | TopId int64 | 57 | TopId int64 |
58 | ArticleTitle string // 文章标题 | 58 | ArticleTitle string // 文章标题 |
59 | FromUserId int64 // 评论填写人的id | 59 | FromUserId int64 // 评论填写人的id |
60 | - FromUser UserSimple // 评论填写人 | ||
61 | Content string // 评论内容 | 60 | Content string // 评论内容 |
62 | CountReply int // 回复数量 | 61 | CountReply int // 回复数量 |
63 | CountUserLove int // 用户点赞数量 | 62 | CountUserLove int // 用户点赞数量 |
@@ -78,5 +77,5 @@ type ArticleCommentRepository interface { | @@ -78,5 +77,5 @@ type ArticleCommentRepository interface { | ||
78 | Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error) | 77 | Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error) |
79 | // 特定的查询 | 78 | // 特定的查询 |
80 | CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int, | 79 | CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int, |
81 | - topId int64, articleTitle string, contentLike string, fromUserName string, show int, createdAtRange [2]int64) (int, []*ArticleCommentShow, error) | 80 | + topId int64, articleTitle string, contentLike string, fromUserId int64, show int, createdAtRange [2]int64) (int, []*ArticleCommentShow, error) |
82 | } | 81 | } |
-
请 注册 或 登录 后发表评论