正在显示
6 个修改的文件
包含
50 行增加
和
35 行删除
@@ -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" |
@@ -12,15 +13,17 @@ import ( | @@ -12,15 +13,17 @@ import ( | ||
12 | 13 | ||
13 | type SystemListAticleCommentLogic struct { | 14 | type SystemListAticleCommentLogic struct { |
14 | logx.Logger | 15 | logx.Logger |
15 | - ctx context.Context | ||
16 | - svcCtx *svc.ServiceContext | 16 | + ctx context.Context |
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 { |
20 | return &SystemListAticleCommentLogic{ | 22 | return &SystemListAticleCommentLogic{ |
21 | - Logger: logx.WithContext(ctx), | ||
22 | - ctx: ctx, | ||
23 | - svcCtx: svcCtx, | 23 | + Logger: logx.WithContext(ctx), |
24 | + ctx: ctx, | ||
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) |
@@ -42,18 +45,12 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System | @@ -42,18 +45,12 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System | ||
42 | 45 | ||
43 | for i, val := range commentList { | 46 | for i, val := range commentList { |
44 | resp.List[i] = types.SystemCommentItem{ | 47 | resp.List[i] = types.SystemCommentItem{ |
45 | - Id: val.Id, | ||
46 | - Pid: val.Pid, | ||
47 | - TopId: val.TopId, | ||
48 | - ArticleTitle: val.ArticleTitle, | ||
49 | - 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 | - }, | 48 | + Id: val.Id, |
49 | + Pid: val.Pid, | ||
50 | + TopId: val.TopId, | ||
51 | + ArticleTitle: val.ArticleTitle, | ||
52 | + FromUserId: val.FromUserId, | ||
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, |
@@ -55,15 +55,14 @@ type ArticleCommentShow struct { | @@ -55,15 +55,14 @@ type ArticleCommentShow struct { | ||
55 | Id int64 // 评论id | 55 | Id int64 // 评论id |
56 | Pid int64 | 56 | Pid int64 |
57 | TopId int64 | 57 | TopId int64 |
58 | - ArticleTitle string // 文章标题 | ||
59 | - FromUserId int64 // 评论填写人的id | ||
60 | - FromUser UserSimple // 评论填写人 | ||
61 | - Content string // 评论内容 | ||
62 | - CountReply int // 回复数量 | ||
63 | - CountUserLove int // 用户点赞数量 | ||
64 | - CountAdminLove int // 运营点赞数量 | ||
65 | - Show int // 评论的展示状态(0显示、1不显示) | ||
66 | - CreatedAt int64 // 评论的创建时间 | 58 | + ArticleTitle string // 文章标题 |
59 | + FromUserId int64 // 评论填写人的id | ||
60 | + Content string // 评论内容 | ||
61 | + CountReply int // 回复数量 | ||
62 | + CountUserLove int // 用户点赞数量 | ||
63 | + CountAdminLove int // 运营点赞数量 | ||
64 | + Show int // 评论的展示状态(0显示、1不显示) | ||
65 | + CreatedAt int64 // 评论的创建时间 | ||
67 | } | 66 | } |
68 | 67 | ||
69 | type ArticleCommentRepository interface { | 68 | type ArticleCommentRepository interface { |
@@ -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 | } |
-
请 注册 或 登录 后发表评论