正在显示
13 个修改的文件
包含
633 行增加
和
1 行删除
@@ -56,6 +56,17 @@ service Core { | @@ -56,6 +56,17 @@ service Core { | ||
56 | @handler SystemArticleCommentSearch | 56 | @handler SystemArticleCommentSearch |
57 | post /article_comment/search (SystemArticleCommentSearchRequest) returns (SystemArticleCommentSearchResponse) | 57 | post /article_comment/search (SystemArticleCommentSearchRequest) returns (SystemArticleCommentSearchResponse) |
58 | 58 | ||
59 | + @doc "管理后台查看所有的评论" | ||
60 | + @handler SystemListAticleComment | ||
61 | + post /article_comment/list (SystemListCommentRequest)returns (SystemListCommentResponse) | ||
62 | + | ||
63 | + @doc "管理后台评论的详情" | ||
64 | + @handler SystemGetAticleComment | ||
65 | + get /article_comment/:id (SystemGetCommentRequest)returns (SystemGetCommentResponse) | ||
66 | + | ||
67 | + @doc "管理后台变更评论的显示状态" | ||
68 | + @handler SystemEditAticleCommentShow | ||
69 | + post /article_comment/edit_show (SystemEditCommentShowRequest)returns (SystemEditCommentShowResponse) | ||
59 | } | 70 | } |
60 | 71 | ||
61 | //评论的填写人 | 72 | //评论的填写人 |
@@ -240,3 +251,69 @@ type ( | @@ -240,3 +251,69 @@ type ( | ||
240 | Show int `json:"show"` // 显示状态 | 251 | Show int `json:"show"` // 显示状态 |
241 | } | 252 | } |
242 | ) | 253 | ) |
254 | + | ||
255 | +// 管理后台 评论管理列表 | ||
256 | +type ( | ||
257 | + SystemListCommentRequest { | ||
258 | + Page int `json:"page"` | ||
259 | + Size int `json:"size"` | ||
260 | + CompanyId int64 `json:",optional"` // | ||
261 | + TopId int64 `json:"topId"` // 文章顶层ID | ||
262 | + FromUser string `json:"fromUser,optional"` // 用户 | ||
263 | + Show int `json:"show,optional"` // 显示状态 | ||
264 | + BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 | ||
265 | + EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间 | ||
266 | + ArticleTitle string `json:"articleTitle,optional"` // | ||
267 | + Content string `json:"content,optional"` // | ||
268 | + } | ||
269 | + SystemListCommentResponse { | ||
270 | + Total int `json:"total"` | ||
271 | + List []SystemCommentItem `json:"list"` | ||
272 | + } | ||
273 | + SystemCommentItem { | ||
274 | + Id int64 `json:"id"` //评论id | ||
275 | + ArticleTitle string `json:"articleTitle"` //文章标题 | ||
276 | + FromUserId int64 `json:"fromUserId"` //填写评论的人 | ||
277 | + FromUser CommentAuthor `json:"fromUser"` //填写评论的人 | ||
278 | + CreatedAt int64 `json:"createdAt"` //评论的填写时间 | ||
279 | + Content string `json:"content"` //评论的内容 | ||
280 | + Show int `json:"show"` //是否展示 [1显示] [2不显示] | ||
281 | + CountReply int `json:"countReplay"` //回复数量 | ||
282 | + CountUserLove int `json:"countUserLove"` //用户点赞数量 | ||
283 | + CountAdminLove int `json:"countAdminLove"` //运营点赞数量 | ||
284 | + } | ||
285 | +) | ||
286 | + | ||
287 | +// 管理后台获取评论详情 | ||
288 | +type ( | ||
289 | + SystemGetCommentRequest { | ||
290 | + CompanyId int64 `path:",optional"` | ||
291 | + Id int64 `path:"id"` | ||
292 | + } | ||
293 | + | ||
294 | + SystemGetCommentResponse { | ||
295 | + Id int64 `json:"id"` //评论id | ||
296 | + ArticleTitle string `json:"articleTitle"` //文章标题 | ||
297 | + FromUserId int64 `json:"fromUserId"` //填写评论的人 | ||
298 | + FromUser CommentAuthor `json:"fromUser"` //填写评论的人 | ||
299 | + CreatedAt int64 `json:"createdAt"` //评论的填写时间 | ||
300 | + SectionContent string `json:"sectionContent"` //引用的段落内容 | ||
301 | + Content string `json:"content"` // 评论的内容 | ||
302 | + Show int `json:"show"` //是否展示 [1显示] [2不显示] | ||
303 | + CountReply int `json:"countReplay"` //回复数量 | ||
304 | + CountUserLove int `json:"countUserLove"` //用户点赞数量 | ||
305 | + CountAdminLove int `json:"countAdminLove"` //运营点赞数量 | ||
306 | + } | ||
307 | +) | ||
308 | + | ||
309 | +type ( | ||
310 | + SystemEditCommentShowRequest { | ||
311 | + CompanyId int64 `json:",optional"` | ||
312 | + Id []int64 `json:"id"` | ||
313 | + Show int `json:"show"` | ||
314 | + } | ||
315 | + | ||
316 | + SystemEditCommentShowResponse { | ||
317 | + Id []int64 `json:"id"` | ||
318 | + } | ||
319 | +) |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
12 | +) | ||
13 | + | ||
14 | +func SystemEditAticleCommentShowHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
16 | + var req types.SystemEditCommentShowRequest | ||
17 | + if err := httpx.Parse(r, &req); err != nil { | ||
18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
19 | + return | ||
20 | + } | ||
21 | + | ||
22 | + l := comment.NewSystemEditAticleCommentShowLogic(r.Context(), svcCtx) | ||
23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
24 | + req.CompanyId = token.CompanyId | ||
25 | + resp, err := l.SystemEditAticleCommentShow(&req) | ||
26 | + result.HttpResult(r, w, resp, err) | ||
27 | + } | ||
28 | +} |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
12 | +) | ||
13 | + | ||
14 | +func SystemGetAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
16 | + var req types.SystemGetCommentRequest | ||
17 | + if err := httpx.Parse(r, &req); err != nil { | ||
18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
19 | + return | ||
20 | + } | ||
21 | + | ||
22 | + l := comment.NewSystemGetAticleCommentLogic(r.Context(), svcCtx) | ||
23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
24 | + req.CompanyId = token.CompanyId | ||
25 | + resp, err := l.SystemGetAticleComment(&req) | ||
26 | + result.HttpResult(r, w, resp, err) | ||
27 | + } | ||
28 | +} |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
12 | +) | ||
13 | + | ||
14 | +func SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
16 | + var req types.SystemListCommentRequest | ||
17 | + if err := httpx.Parse(r, &req); err != nil { | ||
18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
19 | + return | ||
20 | + } | ||
21 | + | ||
22 | + l := comment.NewSystemListAticleCommentLogic(r.Context(), svcCtx) | ||
23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
24 | + req.CompanyId = token.CompanyId | ||
25 | + resp, err := l.SystemListAticleComment(&req) | ||
26 | + result.HttpResult(r, w, resp, err) | ||
27 | + } | ||
28 | +} |
@@ -69,6 +69,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -69,6 +69,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
69 | Path: "/article_comment/search", | 69 | Path: "/article_comment/search", |
70 | Handler: comment.SystemArticleCommentSearchHandler(serverCtx), | 70 | Handler: comment.SystemArticleCommentSearchHandler(serverCtx), |
71 | }, | 71 | }, |
72 | + { | ||
73 | + Method: http.MethodPost, | ||
74 | + Path: "/article_comment/list", | ||
75 | + Handler: comment.SystemListAticleCommentHandler(serverCtx), | ||
76 | + }, | ||
77 | + { | ||
78 | + Method: http.MethodGet, | ||
79 | + Path: "/article_comment/:id", | ||
80 | + Handler: comment.SystemGetAticleCommentHandler(serverCtx), | ||
81 | + }, | ||
82 | + { | ||
83 | + Method: http.MethodPost, | ||
84 | + Path: "/article_comment/edit_show", | ||
85 | + Handler: comment.SystemEditAticleCommentShowHandler(serverCtx), | ||
86 | + }, | ||
72 | }..., | 87 | }..., |
73 | ), | 88 | ), |
74 | rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), | 89 | rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
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" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
11 | + | ||
12 | + "github.com/zeromicro/go-zero/core/logx" | ||
13 | +) | ||
14 | + | ||
15 | +type SystemEditAticleCommentShowLogic struct { | ||
16 | + logx.Logger | ||
17 | + ctx context.Context | ||
18 | + svcCtx *svc.ServiceContext | ||
19 | +} | ||
20 | + | ||
21 | +func NewSystemEditAticleCommentShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemEditAticleCommentShowLogic { | ||
22 | + return &SystemEditAticleCommentShowLogic{ | ||
23 | + Logger: logx.WithContext(ctx), | ||
24 | + ctx: ctx, | ||
25 | + svcCtx: svcCtx, | ||
26 | + } | ||
27 | +} | ||
28 | + | ||
29 | +func (l *SystemEditAticleCommentShowLogic) SystemEditAticleCommentShow(req *types.SystemEditCommentShowRequest) (resp *types.SystemEditCommentShowResponse, err error) { | ||
30 | + | ||
31 | + resp = &types.SystemEditCommentShowResponse{ | ||
32 | + Id: []int64{}, | ||
33 | + } | ||
34 | + if req.Show == 1 { | ||
35 | + for _, val := range req.Id { | ||
36 | + err = l.enableShow(val, req.CompanyId) | ||
37 | + if err != nil { | ||
38 | + err = xerr.NewErrMsgErr("操作失败", err) | ||
39 | + } else { | ||
40 | + resp.Id = append(resp.Id, val) | ||
41 | + } | ||
42 | + } | ||
43 | + } | ||
44 | + if req.Show == 2 { | ||
45 | + for _, val := range req.Id { | ||
46 | + err = l.disableShow(val, req.CompanyId) | ||
47 | + if err != nil { | ||
48 | + err = xerr.NewErrMsgErr("操作失败", err) | ||
49 | + } else { | ||
50 | + resp.Id = append(resp.Id, val) | ||
51 | + } | ||
52 | + } | ||
53 | + } | ||
54 | + | ||
55 | + return | ||
56 | +} | ||
57 | + | ||
58 | +func (l *SystemEditAticleCommentShowLogic) disableShow(commentId int64, companyId int64) error { | ||
59 | + var conn = l.svcCtx.DefaultDBConn() | ||
60 | + commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId) | ||
61 | + if err != nil { | ||
62 | + return xerr.NewErrMsgErr("删除评论信息失败", err) | ||
63 | + } | ||
64 | + if commetInfo.CompanyId != commentId { | ||
65 | + return xerr.NewErrMsg("没有操作权限") | ||
66 | + } | ||
67 | + if commetInfo.Show == domain.CommentShowDisable { | ||
68 | + return nil | ||
69 | + } | ||
70 | + commetInfo.Show = domain.CommentShowDisable | ||
71 | + // 变更回复数量 | ||
72 | + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | ||
73 | + _, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo) | ||
74 | + if err != nil { | ||
75 | + return err | ||
76 | + } | ||
77 | + // 减少上级评论的回复数量 | ||
78 | + if commetInfo.Pid != 0 { | ||
79 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid) | ||
80 | + if err != nil { | ||
81 | + return err | ||
82 | + } | ||
83 | + } | ||
84 | + // 减少最顶层的评论回复计数 | ||
85 | + if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId { | ||
86 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.TopId) | ||
87 | + if err != nil { | ||
88 | + return err | ||
89 | + } | ||
90 | + } | ||
91 | + //减少加段落评论计数 | ||
92 | + if commetInfo.SectionId > 0 { | ||
93 | + err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId) | ||
94 | + if err != nil { | ||
95 | + return err | ||
96 | + } | ||
97 | + } | ||
98 | + // 减少文章的评论数 | ||
99 | + err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId) | ||
100 | + if err != nil { | ||
101 | + return err | ||
102 | + } | ||
103 | + return nil | ||
104 | + }, true) | ||
105 | + | ||
106 | + if err != nil { | ||
107 | + return xerr.NewErrMsgErr("删除评论信息失败", err) | ||
108 | + } | ||
109 | + return nil | ||
110 | +} | ||
111 | + | ||
112 | +func (l *SystemEditAticleCommentShowLogic) enableShow(commentId int64, companyId int64) error { | ||
113 | + var conn = l.svcCtx.DefaultDBConn() | ||
114 | + commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, commentId) | ||
115 | + if err != nil { | ||
116 | + return xerr.NewErrMsgErr("删除评论信息失败", err) | ||
117 | + } | ||
118 | + if commetInfo.CompanyId != commentId { | ||
119 | + return xerr.NewErrMsg("没有操作权限") | ||
120 | + } | ||
121 | + if commetInfo.Show == domain.CommentShowEnable { | ||
122 | + return nil | ||
123 | + } | ||
124 | + commetInfo.Show = domain.CommentShowEnable | ||
125 | + // 变更回复数量 | ||
126 | + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | ||
127 | + _, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo) | ||
128 | + if err != nil { | ||
129 | + return err | ||
130 | + } | ||
131 | + // 增加上级评论的回复数量 | ||
132 | + if commetInfo.Pid != 0 { | ||
133 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, commetInfo.Pid) | ||
134 | + if err != nil { | ||
135 | + return err | ||
136 | + } | ||
137 | + } | ||
138 | + // 增加最顶层的评论回复计数 | ||
139 | + if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId { | ||
140 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, commetInfo.TopId) | ||
141 | + if err != nil { | ||
142 | + return err | ||
143 | + } | ||
144 | + } | ||
145 | + //增加加段落评论计数 | ||
146 | + if commetInfo.SectionId > 0 { | ||
147 | + err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, 1, commetInfo.SectionId) | ||
148 | + if err != nil { | ||
149 | + return err | ||
150 | + } | ||
151 | + } | ||
152 | + // 增加文章的评论数 | ||
153 | + err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, commetInfo.ArticleId) | ||
154 | + if err != nil { | ||
155 | + return err | ||
156 | + } | ||
157 | + return nil | ||
158 | + }, true) | ||
159 | + | ||
160 | + if err != nil { | ||
161 | + return xerr.NewErrMsgErr("删除评论信息失败", err) | ||
162 | + } | ||
163 | + return nil | ||
164 | +} |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
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" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
9 | + | ||
10 | + "github.com/zeromicro/go-zero/core/logx" | ||
11 | +) | ||
12 | + | ||
13 | +type SystemGetAticleCommentLogic struct { | ||
14 | + logx.Logger | ||
15 | + ctx context.Context | ||
16 | + svcCtx *svc.ServiceContext | ||
17 | +} | ||
18 | + | ||
19 | +func NewSystemGetAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemGetAticleCommentLogic { | ||
20 | + return &SystemGetAticleCommentLogic{ | ||
21 | + Logger: logx.WithContext(ctx), | ||
22 | + ctx: ctx, | ||
23 | + svcCtx: svcCtx, | ||
24 | + } | ||
25 | +} | ||
26 | + | ||
27 | +func (l *SystemGetAticleCommentLogic) SystemGetAticleComment(req *types.SystemGetCommentRequest) (resp *types.SystemGetCommentResponse, err error) { | ||
28 | + var conn = l.svcCtx.DefaultDBConn() | ||
29 | + | ||
30 | + commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.Id) | ||
31 | + if err != nil { | ||
32 | + return nil, xerr.NewErrMsgErr("获取评论详情失败", err) | ||
33 | + } | ||
34 | + if commentInfo.CompanyId != req.CompanyId { | ||
35 | + return nil, xerr.NewErrMsg("没有查看权限") | ||
36 | + } | ||
37 | + resp = &types.SystemGetCommentResponse{ | ||
38 | + Id: commentInfo.Id, | ||
39 | + FromUserId: commentInfo.FromUserId, | ||
40 | + FromUser: types.CommentAuthor{ | ||
41 | + Id: commentInfo.FromUserId, | ||
42 | + Name: commentInfo.FromUser.Name, | ||
43 | + Avatar: commentInfo.FromUser.Avatar, | ||
44 | + Position: commentInfo.FromUser.Position, | ||
45 | + Company: commentInfo.FromUser.Company, | ||
46 | + }, | ||
47 | + CreatedAt: commentInfo.CreatedAt, | ||
48 | + SectionContent: commentInfo.SectionContent, | ||
49 | + Content: commentInfo.Content, | ||
50 | + Show: int(commentInfo.Show), | ||
51 | + CountReply: commentInfo.CountReply, | ||
52 | + CountUserLove: commentInfo.CountUserLove, | ||
53 | + CountAdminLove: commentInfo.CountAdminLove, | ||
54 | + } | ||
55 | + return resp, nil | ||
56 | +} |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
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" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
9 | + | ||
10 | + "github.com/zeromicro/go-zero/core/logx" | ||
11 | +) | ||
12 | + | ||
13 | +type SystemListAticleCommentLogic struct { | ||
14 | + logx.Logger | ||
15 | + ctx context.Context | ||
16 | + svcCtx *svc.ServiceContext | ||
17 | +} | ||
18 | + | ||
19 | +func NewSystemListAticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemListAticleCommentLogic { | ||
20 | + return &SystemListAticleCommentLogic{ | ||
21 | + Logger: logx.WithContext(ctx), | ||
22 | + ctx: ctx, | ||
23 | + svcCtx: svcCtx, | ||
24 | + } | ||
25 | +} | ||
26 | + | ||
27 | +// 管理后台评论列表 | ||
28 | +func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.SystemListCommentRequest) (resp *types.SystemListCommentResponse, err error) { | ||
29 | + var conn = l.svcCtx.DefaultDBConn() | ||
30 | + | ||
31 | + cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size, | ||
32 | + req.ArticleTitle, req.Content, req.FromUser, req.Show, | ||
33 | + ) | ||
34 | + if err != nil { | ||
35 | + return nil, xerr.NewErrMsgErr("获取评论详情失败", err) | ||
36 | + } | ||
37 | + | ||
38 | + resp = &types.SystemListCommentResponse{ | ||
39 | + Total: cnt, | ||
40 | + List: make([]types.SystemCommentItem, len(commentList)), | ||
41 | + } | ||
42 | + | ||
43 | + for i, val := range commentList { | ||
44 | + resp.List[i] = types.SystemCommentItem{ | ||
45 | + Id: val.Id, | ||
46 | + ArticleTitle: val.ArticleTitle, | ||
47 | + FromUserId: val.FromUserId, | ||
48 | + FromUser: types.CommentAuthor{ | ||
49 | + Id: val.FromUser.Id, | ||
50 | + Name: val.FromUser.Name, | ||
51 | + Avatar: val.FromUser.Avatar, | ||
52 | + Position: val.FromUser.Position, | ||
53 | + Company: val.FromUser.Company, | ||
54 | + }, | ||
55 | + CreatedAt: val.CreatedAt, | ||
56 | + Content: val.Content, | ||
57 | + Show: val.Show, | ||
58 | + CountReply: val.CountReply, | ||
59 | + CountUserLove: val.CountUserLove, | ||
60 | + CountAdminLove: val.CountAdminLove, | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + return resp, nil | ||
65 | +} |
@@ -168,6 +168,66 @@ type SystemArticleCommentSearchItem struct { | @@ -168,6 +168,66 @@ type SystemArticleCommentSearchItem struct { | ||
168 | Show int `json:"show"` // 显示状态 | 168 | Show int `json:"show"` // 显示状态 |
169 | } | 169 | } |
170 | 170 | ||
171 | +type SystemListCommentRequest struct { | ||
172 | + Page int `json:"page"` | ||
173 | + Size int `json:"size"` | ||
174 | + CompanyId int64 `json:",optional"` // | ||
175 | + TopId int64 `json:"topId"` // 文章顶层ID | ||
176 | + FromUser string `json:"fromUser,optional"` // 用户 | ||
177 | + Show int `json:"show,optional"` // 显示状态 | ||
178 | + BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 | ||
179 | + EndTime int64 `json:"endTime,optional"` // 填写评论的结束时间 | ||
180 | + ArticleTitle string `json:"articleTitle,optional"` // | ||
181 | + Content string `json:"content,optional"` // | ||
182 | +} | ||
183 | + | ||
184 | +type SystemListCommentResponse struct { | ||
185 | + Total int `json:"total"` | ||
186 | + List []SystemCommentItem `json:"list"` | ||
187 | +} | ||
188 | + | ||
189 | +type SystemCommentItem struct { | ||
190 | + Id int64 `json:"id"` //评论id | ||
191 | + ArticleTitle string `json:"articleTitle"` //文章标题 | ||
192 | + FromUserId int64 `json:"fromUserId"` //填写评论的人 | ||
193 | + FromUser CommentAuthor `json:"fromUser"` //填写评论的人 | ||
194 | + CreatedAt int64 `json:"createdAt"` //评论的填写时间 | ||
195 | + Content string `json:"content"` //评论的内容 | ||
196 | + Show int `json:"show"` //是否展示 [1显示] [2不显示] | ||
197 | + CountReply int `json:"countReplay"` //回复数量 | ||
198 | + CountUserLove int `json:"countUserLove"` //用户点赞数量 | ||
199 | + CountAdminLove int `json:"countAdminLove"` //运营点赞数量 | ||
200 | +} | ||
201 | + | ||
202 | +type SystemGetCommentRequest struct { | ||
203 | + CompanyId int64 `path:",optional"` | ||
204 | + Id int64 `path:"id"` | ||
205 | +} | ||
206 | + | ||
207 | +type SystemGetCommentResponse struct { | ||
208 | + Id int64 `json:"id"` //评论id | ||
209 | + ArticleTitle string `json:"articleTitle"` //文章标题 | ||
210 | + FromUserId int64 `json:"fromUserId"` //填写评论的人 | ||
211 | + FromUser CommentAuthor `json:"fromUser"` //填写评论的人 | ||
212 | + CreatedAt int64 `json:"createdAt"` //评论的填写时间 | ||
213 | + SectionContent string `json:"sectionContent"` //引用的段落内容 | ||
214 | + Content string `json:"content"` // 评论的内容 | ||
215 | + Show int `json:"show"` //是否展示 [1显示] [2不显示] | ||
216 | + CountReply int `json:"countReplay"` //回复数量 | ||
217 | + CountUserLove int `json:"countUserLove"` //用户点赞数量 | ||
218 | + CountAdminLove int `json:"countAdminLove"` //运营点赞数量 | ||
219 | +} | ||
220 | + | ||
221 | +type SystemEditCommentShowRequest struct { | ||
222 | + CompanyId int64 `json:",optional"` | ||
223 | + Id []int64 `json:"id"` | ||
224 | + Show int `json:"show"` | ||
225 | +} | ||
226 | + | ||
227 | +type SystemEditCommentShowResponse struct { | ||
228 | + Id []int64 `json:"id"` | ||
229 | +} | ||
230 | + | ||
171 | type MessageSystemRequest struct { | 231 | type MessageSystemRequest struct { |
172 | Page int `json:"page"` | 232 | Page int `json:"page"` |
173 | Size int `json:"size"` | 233 | Size int `json:"size"` |
@@ -70,3 +70,16 @@ func (m *ArticleComment) CachePrimaryKeyFunc() string { | @@ -70,3 +70,16 @@ func (m *ArticleComment) CachePrimaryKeyFunc() string { | ||
70 | } | 70 | } |
71 | return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | 71 | return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") |
72 | } | 72 | } |
73 | + | ||
74 | +type ArticleCommentShow struct { | ||
75 | + ArticleTitle string //文章标题 | ||
76 | + Id int64 //评论id | ||
77 | + FromUserId int64 // 评论填写人的id | ||
78 | + FromUser domain.UserSimple `gorm:"type:jsonb;serializer:json"` | ||
79 | + Content string // 评论内容 | ||
80 | + CountReply int // 回复数量 | ||
81 | + CountUserLove int // 用户点赞数量 | ||
82 | + CountAdminLove int // 运营点赞数量 | ||
83 | + Show int // 评论的展示状态(0显示、1不显示) | ||
84 | + CreatedAt int64 // 评论的创建时间 | ||
85 | +} |
@@ -325,6 +325,88 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con | @@ -325,6 +325,88 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con | ||
325 | } | 325 | } |
326 | return dms, nil | 326 | return dms, nil |
327 | } | 327 | } |
328 | + | ||
329 | +func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int, | ||
330 | + articleTitle string, contentLike string, fromUserName string, show int) (int, []*domain.ArticleCommentShow, error) { | ||
331 | + sqlStr := `select | ||
332 | +article.title as article_title , | ||
333 | +article_comment.id , | ||
334 | +article_comment.from_user_id , | ||
335 | +article_comment.from_user, | ||
336 | +article_comment."content" , | ||
337 | +article_comment.created_at , | ||
338 | +article_comment.count_reply , | ||
339 | +article_comment.count_user_love , | ||
340 | +article_comment.count_admin_love , | ||
341 | +article_comment."show" | ||
342 | +from article_comment | ||
343 | +join article on article.id = article_comment.article_id | ||
344 | +where 1=1 ` | ||
345 | + if size <= 0 { | ||
346 | + size = 20 | ||
347 | + } | ||
348 | + if page <= 0 { | ||
349 | + page = 1 | ||
350 | + } | ||
351 | + | ||
352 | + where := "" | ||
353 | + condition := []interface{}{} | ||
354 | + | ||
355 | + if len(articleTitle) > 0 { | ||
356 | + where += ` and article.title like ? ` | ||
357 | + condition = append(condition, "%"+articleTitle+"%") | ||
358 | + } | ||
359 | + if len(contentLike) > 0 { | ||
360 | + where += ` and article_comment."content" like ? ` | ||
361 | + condition = append(condition, "%"+contentLike+"%") | ||
362 | + } | ||
363 | + | ||
364 | + if len(fromUserName) > 0 { | ||
365 | + where += ` and article_comment.from_user ->>'name' like ? ` | ||
366 | + condition = append(condition, "%"+fromUserName+"%") | ||
367 | + } | ||
368 | + if show > 0 { | ||
369 | + where += ` and article_comment."show" =? ` | ||
370 | + condition = append(condition, show) | ||
371 | + } | ||
372 | + | ||
373 | + countSql := sqlStr + where | ||
374 | + | ||
375 | + var cnt int | ||
376 | + db := conn.DB() | ||
377 | + result := db.Raw(countSql, condition...).Scan(&cnt) | ||
378 | + if result.Error != nil { | ||
379 | + return 0, nil, result.Error | ||
380 | + } | ||
381 | + | ||
382 | + dataSql := sqlStr + where + ` order by article_comment.id desc limit ? offset ? ` | ||
383 | + condition = append(condition, size, (page-1)*size) | ||
384 | + | ||
385 | + ms := []models.ArticleCommentShow{} | ||
386 | + result = db.Raw(dataSql, condition...).Scan(&ms) | ||
387 | + if result.Error != nil { | ||
388 | + return 0, nil, result.Error | ||
389 | + } | ||
390 | + | ||
391 | + d := []*domain.ArticleCommentShow{} | ||
392 | + for _, val := range ms { | ||
393 | + d = append(d, &domain.ArticleCommentShow{ | ||
394 | + ArticleTitle: val.ArticleTitle, | ||
395 | + Id: val.Id, | ||
396 | + FromUserId: val.FromUserId, | ||
397 | + FromUser: val.FromUser, | ||
398 | + Content: val.Content, | ||
399 | + CountReply: val.CountReply, | ||
400 | + CountUserLove: val.CountUserLove, | ||
401 | + CountAdminLove: val.CountAdminLove, | ||
402 | + Show: val.Show, | ||
403 | + CreatedAt: val.CreatedAt, | ||
404 | + }) | ||
405 | + } | ||
406 | + return cnt, d, nil | ||
407 | + | ||
408 | +} | ||
409 | + | ||
328 | func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { | 410 | func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { |
329 | return &ArticleCommentRepository{CachedRepository: cache} | 411 | return &ArticleCommentRepository{CachedRepository: cache} |
330 | } | 412 | } |
@@ -312,7 +312,7 @@ func (repository *ArticleRepository) CustomSearchBy(ctx context.Context, conn tr | @@ -312,7 +312,7 @@ func (repository *ArticleRepository) CustomSearchBy(ctx context.Context, conn tr | ||
312 | tx = tx.Where("article_and_tag.tag_id=?", tagId) | 312 | tx = tx.Where("article_and_tag.tag_id=?", tagId) |
313 | } else if len(tagCategory) > 0 { | 313 | } else if len(tagCategory) > 0 { |
314 | tx = tx.Joins(`join article_and_tag on article.id = article_and_tag.article_id`) | 314 | tx = tx.Joins(`join article_and_tag on article.id = article_and_tag.article_id`) |
315 | - tx = tx.Where(`article_and_tag.tag_id =any(select article_tag.id from article_tag where category =%s )`, tagCategory) | 315 | + tx = tx.Where(`article_and_tag.tag_id =any(select article_tag.id from article_tag where category =? )`, tagCategory) |
316 | } | 316 | } |
317 | if len(titleLike) > 0 { | 317 | if len(titleLike) > 0 { |
318 | tx = tx.Where("article.title like ?", "%"+titleLike+"%") | 318 | tx = tx.Where("article.title like ?", "%"+titleLike+"%") |
@@ -50,6 +50,19 @@ func (show CommentShow) Named() string { | @@ -50,6 +50,19 @@ func (show CommentShow) Named() string { | ||
50 | return "" | 50 | return "" |
51 | } | 51 | } |
52 | 52 | ||
53 | +type ArticleCommentShow struct { | ||
54 | + ArticleTitle string // 文章标题 | ||
55 | + Id int64 // 评论id | ||
56 | + FromUserId int64 // 评论填写人的id | ||
57 | + FromUser UserSimple // 评论填写人 | ||
58 | + Content string // 评论内容 | ||
59 | + CountReply int // 回复数量 | ||
60 | + CountUserLove int // 用户点赞数量 | ||
61 | + CountAdminLove int // 运营点赞数量 | ||
62 | + Show int // 评论的展示状态(0显示、1不显示) | ||
63 | + CreatedAt int64 // 评论的创建时间 | ||
64 | +} | ||
65 | + | ||
53 | type ArticleCommentRepository interface { | 66 | type ArticleCommentRepository interface { |
54 | Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | 67 | Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) |
55 | Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | 68 | Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) |
@@ -60,4 +73,7 @@ type ArticleCommentRepository interface { | @@ -60,4 +73,7 @@ type ArticleCommentRepository interface { | ||
60 | IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error //点赞数量变动 | 73 | IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error //点赞数量变动 |
61 | IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error // 评论回复数量变动 | 74 | IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commentId int64) error // 评论回复数量变动 |
62 | Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error) | 75 | Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error) |
76 | + // 特定的查询 | ||
77 | + CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int, | ||
78 | + articleTitle string, contentLike string, fromUserName string, show int) (int, []*ArticleCommentShow, error) | ||
63 | } | 79 | } |
-
请 注册 或 登录 后发表评论