Merge branch 'dev-tangxvhui' into dev
正在显示
13 个修改的文件
包含
463 行增加
和
3 行删除
| @@ -55,7 +55,7 @@ type ( | @@ -55,7 +55,7 @@ type ( | ||
| 55 | CountRead int `json:"countRead"` // 浏览数量 | 55 | CountRead int `json:"countRead"` // 浏览数量 |
| 56 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 56 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) |
| 57 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) | 57 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) |
| 58 | - MeLoveFlag int `json:"meLoveFlag"` //当前人员对文章的点赞标识 | 58 | + MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) |
| 59 | } | 59 | } |
| 60 | ArticleSection { | 60 | ArticleSection { |
| 61 | Id int64 `json:"id"` //段落id | 61 | Id int64 `json:"id"` //段落id |
| @@ -23,6 +23,18 @@ service Core { | @@ -23,6 +23,18 @@ service Core { | ||
| 23 | @doc "小程序填写文章的评论" | 23 | @doc "小程序填写文章的评论" |
| 24 | @handler MiniCreateArticleComment | 24 | @handler MiniCreateArticleComment |
| 25 | post /article_comment (MiniCreateArticleCommentRequest) returns (MiniCreateArticleCommentResponse) | 25 | post /article_comment (MiniCreateArticleCommentRequest) returns (MiniCreateArticleCommentResponse) |
| 26 | + | ||
| 27 | + @doc "小程序展示文章的评论列表" | ||
| 28 | + @handler MiniListArticleComment | ||
| 29 | + post /article_comment/list (MiniListArticleCommentRequest) returns (MiniListArticleCommentResponse) | ||
| 30 | + | ||
| 31 | + @doc "小程序展示单个文章的评论" | ||
| 32 | + @handler MiniGetArticleComment | ||
| 33 | + get /article_comment/:id (MiniGetArticleCommentRequest) returns (MiniGetArticleCommentResponse) | ||
| 34 | + | ||
| 35 | + @doc "小程序展示删除文章评论" | ||
| 36 | + @handler MiniDeleteArticleComment | ||
| 37 | + delete /article_comment/:id (MiniDeleteArticleCommentRequest) returns (MiniDeleteArticleCommentResponse) | ||
| 26 | } | 38 | } |
| 27 | 39 | ||
| 28 | // | 40 | // |
| @@ -72,5 +84,68 @@ type ( | @@ -72,5 +84,68 @@ type ( | ||
| 72 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 | 84 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 |
| 73 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | 85 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 |
| 74 | AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | 86 | AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 |
| 87 | + CreatedAt int64 `json:"createdAt"` // | ||
| 88 | + } | ||
| 89 | +) | ||
| 90 | + | ||
| 91 | +// 小程序获取文章的评论列表 | ||
| 92 | +type ( | ||
| 93 | + MiniListArticleCommentRequest { | ||
| 94 | + Page int64 `json:"page"` | ||
| 95 | + Size int64 `json:"size"` | ||
| 96 | + CompanyId int64 `json:",optional"` | ||
| 97 | + SectionId int64 `json:"sectionId"` | ||
| 98 | + } | ||
| 99 | + MiniListArticleCommentResponse { | ||
| 100 | + Total int64 `json:"total"` | ||
| 101 | + List []ArticleCommentAndReply `json:"list"` | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + ArticleCommentAndReply { | ||
| 105 | + Comment ArticleCommentItem `json:"comment"` //评论 | ||
| 106 | + Reply []ArticleCommentItem `json:"reply"` //回复的评论 | ||
| 107 | + TotalReply int64 `json:"totalReply"` //回复的评论数量 | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + ArticleCommentItem { | ||
| 111 | + Id int64 `json:"id"` | ||
| 112 | + Pid int64 `json:"pid"` | ||
| 113 | + TopId int64 `json:"topId"` | ||
| 114 | + ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 115 | + SectionId int64 `json:"sectionId"` // 段落id | ||
| 116 | + FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
| 117 | + FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
| 118 | + ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
| 119 | + ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
| 120 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
| 121 | + CountReply int `json:"countReply"` // 回复数量 | ||
| 122 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
| 123 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
| 124 | + AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | ||
| 125 | + CreatedAt int64 `json:"createdAt"` // | ||
| 126 | + MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) | ||
| 127 | + } | ||
| 128 | +) | ||
| 129 | + | ||
| 130 | +// 小程序获取单个文章的评论 | ||
| 131 | +type ( | ||
| 132 | + MiniGetArticleCommentRequest { | ||
| 133 | + CommentId int64 `path:"commentId"` | ||
| 134 | + CompanyId int64 `json:",optional"` | ||
| 135 | + } | ||
| 136 | + MiniGetArticleCommentResponse { | ||
| 137 | + ArticleCommentAndReply | ||
| 138 | + } | ||
| 139 | +) | ||
| 140 | + | ||
| 141 | +// 小程序删除单个文章的评论 | ||
| 142 | +type ( | ||
| 143 | + MiniDeleteArticleCommentRequest { | ||
| 144 | + CommentId int64 `json:"commentId"` | ||
| 145 | + UserId int64 `json:",optional"` | ||
| 146 | + CompanyId int64 `json:",optional"` | ||
| 147 | + } | ||
| 148 | + MiniDeleteArticleCommentResponse { | ||
| 149 | + Id int64 `json:"id"` | ||
| 75 | } | 150 | } |
| 76 | ) | 151 | ) |
| 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 MiniDeleteArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 16 | + var req types.MiniDeleteArticleCommentRequest | ||
| 17 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 19 | + return | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + l := comment.NewMiniDeleteArticleCommentLogic(r.Context(), svcCtx) | ||
| 23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
| 24 | + req.CompanyId = token.CompanyId | ||
| 25 | + req.UserId = token.UserId | ||
| 26 | + resp, err := l.MiniDeleteArticleComment(&req) | ||
| 27 | + result.HttpResult(r, w, resp, err) | ||
| 28 | + } | ||
| 29 | +} |
| 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 MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 16 | + var req types.MiniGetArticleCommentRequest | ||
| 17 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 19 | + return | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + l := comment.NewMiniGetArticleCommentLogic(r.Context(), svcCtx) | ||
| 23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
| 24 | + req.CompanyId = token.CompanyId | ||
| 25 | + resp, err := l.MiniGetArticleComment(&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 MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 16 | + var req types.MiniListArticleCommentRequest | ||
| 17 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
| 19 | + return | ||
| 20 | + } | ||
| 21 | + l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx) | ||
| 22 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
| 23 | + req.CompanyId = token.CompanyId | ||
| 24 | + resp, err := l.MiniListArticleComment(&req) | ||
| 25 | + result.HttpResult(r, w, resp, err) | ||
| 26 | + } | ||
| 27 | +} |
| @@ -30,6 +30,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -30,6 +30,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 30 | Path: "/article_comment", | 30 | Path: "/article_comment", |
| 31 | Handler: comment.MiniCreateArticleCommentHandler(serverCtx), | 31 | Handler: comment.MiniCreateArticleCommentHandler(serverCtx), |
| 32 | }, | 32 | }, |
| 33 | + { | ||
| 34 | + Method: http.MethodPost, | ||
| 35 | + Path: "/article_comment/list", | ||
| 36 | + Handler: comment.MiniListArticleCommentHandler(serverCtx), | ||
| 37 | + }, | ||
| 38 | + { | ||
| 39 | + Method: http.MethodGet, | ||
| 40 | + Path: "/article_comment/:id", | ||
| 41 | + Handler: comment.MiniGetArticleCommentHandler(serverCtx), | ||
| 42 | + }, | ||
| 43 | + { | ||
| 44 | + Method: http.MethodDelete, | ||
| 45 | + Path: "/article_comment/:id", | ||
| 46 | + Handler: comment.MiniDeleteArticleCommentHandler(serverCtx), | ||
| 47 | + }, | ||
| 33 | }, | 48 | }, |
| 34 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | 49 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), |
| 35 | rest.WithPrefix("/v1/mini"), | 50 | rest.WithPrefix("/v1/mini"), |
| @@ -149,11 +149,18 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -149,11 +149,18 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 149 | } | 149 | } |
| 150 | //保存数据 | 150 | //保存数据 |
| 151 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 151 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
| 152 | - // 增加平评论计数 | 152 | + // 增加文章评论计数 |
| 153 | err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo) | 153 | err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo) |
| 154 | if err != nil { | 154 | if err != nil { |
| 155 | return err | 155 | return err |
| 156 | } | 156 | } |
| 157 | + //增加评论回复计数 | ||
| 158 | + if pComment != nil { | ||
| 159 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment) | ||
| 160 | + if err != nil { | ||
| 161 | + return err | ||
| 162 | + } | ||
| 163 | + } | ||
| 157 | //保存评论 | 164 | //保存评论 |
| 158 | _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) | 165 | _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) |
| 159 | if err != nil { | 166 | if err != nil { |
| @@ -193,6 +200,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -193,6 +200,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 193 | CountUserLove: 0, | 200 | CountUserLove: 0, |
| 194 | CountAdminLove: 0, | 201 | CountAdminLove: 0, |
| 195 | AtWho: []types.CommentAuthor{}, | 202 | AtWho: []types.CommentAuthor{}, |
| 203 | + CreatedAt: newComment.CreatedAt, | ||
| 196 | } | 204 | } |
| 197 | 205 | ||
| 198 | for _, val := range newComment.AtWho { | 206 | for _, val := range newComment.AtWho { |
| 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 | + | ||
| 9 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type MiniDeleteArticleCommentLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewMiniDeleteArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniDeleteArticleCommentLogic { | ||
| 19 | + return &MiniDeleteArticleCommentLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.MiniDeleteArticleCommentRequest) (resp *types.MiniDeleteArticleCommentResponse, err error) { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return | ||
| 30 | +} |
| 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/domain" | ||
| 9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
| 10 | + | ||
| 11 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 12 | +) | ||
| 13 | + | ||
| 14 | +type MiniGetArticleCommentLogic struct { | ||
| 15 | + logx.Logger | ||
| 16 | + ctx context.Context | ||
| 17 | + svcCtx *svc.ServiceContext | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic { | ||
| 21 | + return &MiniGetArticleCommentLogic{ | ||
| 22 | + Logger: logx.WithContext(ctx), | ||
| 23 | + ctx: ctx, | ||
| 24 | + svcCtx: svcCtx, | ||
| 25 | + } | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) { | ||
| 29 | + var conn = l.svcCtx.DefaultDBConn() | ||
| 30 | + //获取主评论 | ||
| 31 | + commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId) | ||
| 32 | + if err != nil { | ||
| 33 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
| 34 | + } | ||
| 35 | + if commentInfo.CompanyId != req.CompanyId { | ||
| 36 | + return nil, xerr.NewErrMsg("没有查看权限") | ||
| 37 | + } | ||
| 38 | + queryOption := domain.NewQueryOptions().MustWithKV("topId", commentInfo.Id).WithFindOnly() | ||
| 39 | + //获取回复的评论 | ||
| 40 | + _, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption) | ||
| 41 | + | ||
| 42 | + if err != nil { | ||
| 43 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
| 44 | + } | ||
| 45 | + //TODO 获取我点赞的评论 | ||
| 46 | + | ||
| 47 | + //混合数据 | ||
| 48 | + commentResp := types.ArticleCommentItem{ | ||
| 49 | + Id: commentInfo.Id, | ||
| 50 | + Pid: commentInfo.Pid, | ||
| 51 | + TopId: commentInfo.TopId, | ||
| 52 | + ArtitcleId: commentInfo.ArticleId, | ||
| 53 | + SectionId: commentInfo.ArticleId, | ||
| 54 | + FromUserId: commentInfo.FromUserId, | ||
| 55 | + FromUser: types.CommentAuthor{ | ||
| 56 | + Id: commentInfo.FromUser.Id, | ||
| 57 | + Name: commentInfo.FromUser.Name, | ||
| 58 | + Avatar: commentInfo.FromUser.Avatar, | ||
| 59 | + Position: commentInfo.FromUser.Position, | ||
| 60 | + Company: commentInfo.FromUser.Company, | ||
| 61 | + }, | ||
| 62 | + ToUserId: commentInfo.ToUserId, | ||
| 63 | + ToUser: types.CommentAuthor{ | ||
| 64 | + Id: commentInfo.ToUser.Id, | ||
| 65 | + Name: commentInfo.ToUser.Name, | ||
| 66 | + Avatar: commentInfo.ToUser.Avatar, | ||
| 67 | + Position: commentInfo.ToUser.Position, | ||
| 68 | + Company: commentInfo.ToUser.Company, | ||
| 69 | + }, | ||
| 70 | + SectionContent: commentInfo.SectionContent, | ||
| 71 | + CountReply: commentInfo.CountReply, | ||
| 72 | + CountUserLove: commentInfo.CountUserLove, | ||
| 73 | + CountAdminLove: commentInfo.CountAdminLove, | ||
| 74 | + AtWho: []types.CommentAuthor{}, | ||
| 75 | + CreatedAt: commentInfo.CreatedAt, | ||
| 76 | + } | ||
| 77 | + for _, val := range commentInfo.AtWho { | ||
| 78 | + commentResp.AtWho = append(commentResp.AtWho, types.CommentAuthor{ | ||
| 79 | + Id: val.Id, | ||
| 80 | + Name: val.Name, | ||
| 81 | + Avatar: val.Avatar, | ||
| 82 | + Position: val.Position, | ||
| 83 | + Company: val.Company, | ||
| 84 | + }) | ||
| 85 | + } | ||
| 86 | + allReply := []types.ArticleCommentItem{} | ||
| 87 | + for _, val := range replyCommenList { | ||
| 88 | + reply := types.ArticleCommentItem{ | ||
| 89 | + Id: val.Id, | ||
| 90 | + Pid: val.Pid, | ||
| 91 | + TopId: val.TopId, | ||
| 92 | + ArtitcleId: val.ArticleId, | ||
| 93 | + SectionId: val.ArticleId, | ||
| 94 | + FromUserId: val.FromUserId, | ||
| 95 | + FromUser: types.CommentAuthor{ | ||
| 96 | + Id: val.FromUser.Id, | ||
| 97 | + Name: val.FromUser.Name, | ||
| 98 | + Avatar: val.FromUser.Avatar, | ||
| 99 | + Position: val.FromUser.Position, | ||
| 100 | + Company: val.FromUser.Company, | ||
| 101 | + }, | ||
| 102 | + ToUserId: val.ToUserId, | ||
| 103 | + ToUser: types.CommentAuthor{ | ||
| 104 | + Id: val.ToUser.Id, | ||
| 105 | + Name: val.ToUser.Name, | ||
| 106 | + Avatar: val.ToUser.Avatar, | ||
| 107 | + Position: val.ToUser.Position, | ||
| 108 | + Company: val.ToUser.Company, | ||
| 109 | + }, | ||
| 110 | + SectionContent: val.SectionContent, | ||
| 111 | + CountReply: val.CountReply, | ||
| 112 | + CountUserLove: val.CountUserLove, | ||
| 113 | + CountAdminLove: val.CountAdminLove, | ||
| 114 | + AtWho: []types.CommentAuthor{}, | ||
| 115 | + CreatedAt: val.CreatedAt, | ||
| 116 | + MeLoveFlag: 0, | ||
| 117 | + } | ||
| 118 | + for _, val2 := range val.AtWho { | ||
| 119 | + reply.AtWho = append(reply.AtWho, types.CommentAuthor{ | ||
| 120 | + Id: val2.Id, | ||
| 121 | + Name: val2.Name, | ||
| 122 | + Avatar: val2.Avatar, | ||
| 123 | + Position: val2.Position, | ||
| 124 | + Company: val2.Company, | ||
| 125 | + }) | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + resp = &types.MiniGetArticleCommentResponse{ | ||
| 129 | + ArticleCommentAndReply: types.ArticleCommentAndReply{ | ||
| 130 | + Comment: commentResp, | ||
| 131 | + Reply: allReply, | ||
| 132 | + TotalReply: int64(len(replyCommenList)), | ||
| 133 | + }, | ||
| 134 | + } | ||
| 135 | + return | ||
| 136 | +} |
| 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 | + | ||
| 9 | + "github.com/zeromicro/go-zero/core/logx" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type MiniListArticleCommentLogic struct { | ||
| 13 | + logx.Logger | ||
| 14 | + ctx context.Context | ||
| 15 | + svcCtx *svc.ServiceContext | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListArticleCommentLogic { | ||
| 19 | + return &MiniListArticleCommentLogic{ | ||
| 20 | + Logger: logx.WithContext(ctx), | ||
| 21 | + ctx: ctx, | ||
| 22 | + svcCtx: svcCtx, | ||
| 23 | + } | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) { | ||
| 27 | + // todo: add your logic here and delete this line | ||
| 28 | + | ||
| 29 | + return | ||
| 30 | +} |
| @@ -41,6 +41,63 @@ type MiniCreateArticleCommentResponse struct { | @@ -41,6 +41,63 @@ type MiniCreateArticleCommentResponse struct { | ||
| 41 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 | 41 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 |
| 42 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | 42 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 |
| 43 | AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | 43 | AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 |
| 44 | + CreatedAt int64 `json:"createdAt"` // | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +type MiniListArticleCommentRequest struct { | ||
| 48 | + Page int64 `json:"page"` | ||
| 49 | + Size int64 `json:"size"` | ||
| 50 | + CompanyId int64 `json:",optional"` | ||
| 51 | + SectionId int64 `json:"sectionId"` | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +type MiniListArticleCommentResponse struct { | ||
| 55 | + Total int64 `json:"total"` | ||
| 56 | + List []ArticleCommentAndReply `json:"list"` | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +type ArticleCommentAndReply struct { | ||
| 60 | + Comment ArticleCommentItem `json:"comment"` //评论 | ||
| 61 | + Reply []ArticleCommentItem `json:"reply"` //回复的评论 | ||
| 62 | + TotalReply int64 `json:"totalReply"` //回复的评论数量 | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +type ArticleCommentItem struct { | ||
| 66 | + Id int64 `json:"id"` | ||
| 67 | + Pid int64 `json:"pid"` | ||
| 68 | + TopId int64 `json:"topId"` | ||
| 69 | + ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 70 | + SectionId int64 `json:"sectionId"` // 段落id | ||
| 71 | + FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
| 72 | + FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
| 73 | + ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
| 74 | + ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
| 75 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
| 76 | + CountReply int `json:"countReply"` // 回复数量 | ||
| 77 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
| 78 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
| 79 | + AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | ||
| 80 | + CreatedAt int64 `json:"createdAt"` // | ||
| 81 | + MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +type MiniGetArticleCommentRequest struct { | ||
| 85 | + CommentId int64 `path:"commentId"` | ||
| 86 | + CompanyId int64 `json:",optional"` | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +type MiniGetArticleCommentResponse struct { | ||
| 90 | + ArticleCommentAndReply | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +type MiniDeleteArticleCommentRequest struct { | ||
| 94 | + CommentId int64 `json:"commentId"` | ||
| 95 | + UserId int64 `json:",optional"` | ||
| 96 | + CompanyId int64 `json:",optional"` | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +type MiniDeleteArticleCommentResponse struct { | ||
| 100 | + Id int64 `json:"id"` | ||
| 44 | } | 101 | } |
| 45 | 102 | ||
| 46 | type MessageSystemRequest struct { | 103 | type MessageSystemRequest struct { |
| @@ -520,7 +577,7 @@ type MiniArticleGetResponse struct { | @@ -520,7 +577,7 @@ type MiniArticleGetResponse struct { | ||
| 520 | CountRead int `json:"countRead"` // 浏览数量 | 577 | CountRead int `json:"countRead"` // 浏览数量 |
| 521 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 578 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) |
| 522 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) | 579 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) |
| 523 | - MeLoveFlag int `json:"meLoveFlag"` //当前人员对文章的点赞标识 | 580 | + MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) |
| 524 | } | 581 | } |
| 525 | 582 | ||
| 526 | type ArticleSection struct { | 583 | type ArticleSection struct { |
| @@ -120,6 +120,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans | @@ -120,6 +120,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans | ||
| 120 | ) | 120 | ) |
| 121 | queryFunc := func() (interface{}, error) { | 121 | queryFunc := func() (interface{}, error) { |
| 122 | tx = tx.Model(&ms).Order("id desc") | 122 | tx = tx.Model(&ms).Order("id desc") |
| 123 | + if v, ok := queryOptions["topId"]; ok { | ||
| 124 | + tx = tx.Where("top_id", v) | ||
| 125 | + } | ||
| 123 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 126 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 124 | return dms, tx.Error | 127 | return dms, tx.Error |
| 125 | } | 128 | } |
| @@ -215,6 +218,27 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co | @@ -215,6 +218,27 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co | ||
| 215 | 218 | ||
| 216 | } | 219 | } |
| 217 | 220 | ||
| 221 | +// 点赞数量变动 | ||
| 222 | +func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error { | ||
| 223 | + var ( | ||
| 224 | + err error | ||
| 225 | + m *models.ArticleComment | ||
| 226 | + tx = conn.DB() | ||
| 227 | + ) | ||
| 228 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 229 | + return err | ||
| 230 | + } | ||
| 231 | + queryFunc := func() (interface{}, error) { | ||
| 232 | + tx = tx.Model(m).Update("count_reply", gorm.Expr("count_reply+?", incr)) | ||
| 233 | + return nil, tx.Error | ||
| 234 | + } | ||
| 235 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 236 | + return err | ||
| 237 | + } | ||
| 238 | + return nil | ||
| 239 | + | ||
| 240 | +} | ||
| 241 | + | ||
| 218 | func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { | 242 | func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { |
| 219 | return &ArticleCommentRepository{CachedRepository: cache} | 243 | return &ArticleCommentRepository{CachedRepository: cache} |
| 220 | } | 244 | } |
| @@ -48,4 +48,5 @@ type ArticleCommentRepository interface { | @@ -48,4 +48,5 @@ type ArticleCommentRepository interface { | ||
| 48 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) | 48 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) |
| 49 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) | 49 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) |
| 50 | IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动 | 50 | IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动 |
| 51 | + IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error // 评论回复数量变动 | ||
| 51 | } | 52 | } |
-
请 注册 或 登录 后发表评论