Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev
正在显示
23 个修改的文件
包含
707 行增加
和
104 行删除
| @@ -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 | // |
| @@ -38,39 +50,107 @@ type ( | @@ -38,39 +50,107 @@ type ( | ||
| 38 | 50 | ||
| 39 | //评论的填写人 | 51 | //评论的填写人 |
| 40 | type CommentAuthor { | 52 | type CommentAuthor { |
| 41 | - Id int64 `json:"id"` // 人员id | ||
| 42 | - Name string `json:"name"` // 人员的名字 | ||
| 43 | - Avatar string `json:"avatar"` // 人员头像URL | ||
| 44 | - Position string `json:"position"` // 职位 | ||
| 45 | - Company string `json:"company"` // 公司 | 53 | + Id int64 `json:"id"` // 人员id |
| 54 | + Name string `json:"name"` // 人员的名字 | ||
| 55 | + Avatar string `json:"avatar,optional"` // 人员头像URL | ||
| 56 | + Position string `json:"position,optional"` // 职位 | ||
| 57 | + Company string `json:"company,optional"` // 公司 | ||
| 46 | } | 58 | } |
| 47 | 59 | ||
| 48 | // 小程序填写文章的评论 | 60 | // 小程序填写文章的评论 |
| 49 | type ( | 61 | type ( |
| 50 | MiniCreateArticleCommentRequest { | 62 | MiniCreateArticleCommentRequest { |
| 51 | - ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 52 | - SectionId int64 `json:"sectionId"` // 段落id | ||
| 53 | - FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取 | ||
| 54 | - CompanyId int64 `json:",optional"` // 服务端自动获取 | ||
| 55 | - Pid int64 `json:"commnet"` // 回复那个评论的id | ||
| 56 | - Content string `json:"content"` // 评论的内容 | ||
| 57 | - AtWho []int64 `json:"atWho"` // 填写评论时@的人 | 63 | + ArtitcleId int64 `json:"articleId"` // 文章id |
| 64 | + SectionId int64 `json:"sectionId"` // 段落id | ||
| 65 | + FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取 | ||
| 66 | + CompanyId int64 `json:",optional"` // 服务端自动获取 | ||
| 67 | + Pid int64 `json:"pid"` // 回复那个评论的id | ||
| 68 | + Content string `json:"content"` // 评论的内容 | ||
| 69 | + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 | ||
| 58 | } | 70 | } |
| 59 | 71 | ||
| 72 | + CommentAtWho { | ||
| 73 | + Id int64 `json:"id"` | ||
| 74 | + Name string `json:"name,optional"` | ||
| 75 | + } | ||
| 60 | MiniCreateArticleCommentResponse { | 76 | MiniCreateArticleCommentResponse { |
| 61 | - Id int64 `json:"id"` | ||
| 62 | - Pid int64 `json:"pid"` | ||
| 63 | - TopId int64 `json:"topId"` | ||
| 64 | - ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 65 | - SectionId int64 `json:"sectionId"` // 段落id | ||
| 66 | - FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
| 67 | - FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
| 68 | - ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
| 69 | - ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
| 70 | - SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
| 71 | - CountReply int `json:"countReply"` // 回复数量 | ||
| 72 | - CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
| 73 | - CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
| 74 | - AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | 77 | + Id int64 `json:"id"` |
| 78 | + Pid int64 `json:"pid"` | ||
| 79 | + TopId int64 `json:"topId"` | ||
| 80 | + ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 81 | + SectionId int64 `json:"sectionId"` // 段落id | ||
| 82 | + FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
| 83 | + FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
| 84 | + ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
| 85 | + ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
| 86 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
| 87 | + CountReply int `json:"countReply"` // 回复数量 | ||
| 88 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
| 89 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
| 90 | + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 | ||
| 91 | + CreatedAt int64 `json:"createdAt"` // | ||
| 92 | + } | ||
| 93 | +) | ||
| 94 | + | ||
| 95 | +// 小程序获取文章的评论列表 | ||
| 96 | +type ( | ||
| 97 | + MiniListArticleCommentRequest { | ||
| 98 | + Page int64 `json:"page"` | ||
| 99 | + Size int64 `json:"size"` | ||
| 100 | + CompanyId int64 `json:",optional"` | ||
| 101 | + SectionId int64 `json:"sectionId"` | ||
| 102 | + } | ||
| 103 | + MiniListArticleCommentResponse { | ||
| 104 | + Total int64 `json:"total"` | ||
| 105 | + List []ArticleCommentAndReply `json:"list"` | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + ArticleCommentAndReply { | ||
| 109 | + Comment ArticleCommentItem `json:"comment"` //评论 | ||
| 110 | + Reply []ArticleCommentItem `json:"reply"` //回复的评论 | ||
| 111 | + TotalReply int64 `json:"totalReply"` //回复的评论数量 | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + ArticleCommentItem { | ||
| 115 | + Id int64 `json:"id"` | ||
| 116 | + Pid int64 `json:"pid"` | ||
| 117 | + TopId int64 `json:"topId"` | ||
| 118 | + ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 119 | + SectionId int64 `json:"sectionId"` // 段落id | ||
| 120 | + FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
| 121 | + FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
| 122 | + ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
| 123 | + ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
| 124 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
| 125 | + CountReply int `json:"countReply"` // 回复数量 | ||
| 126 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
| 127 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
| 128 | + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 | ||
| 129 | + CreatedAt int64 `json:"createdAt"` // | ||
| 130 | + MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) | ||
| 131 | + } | ||
| 132 | +) | ||
| 133 | + | ||
| 134 | +// 小程序获取单个文章的评论 | ||
| 135 | +type ( | ||
| 136 | + MiniGetArticleCommentRequest { | ||
| 137 | + CommentId int64 `path:"id"` | ||
| 138 | + CompanyId int64 `path:",optional"` | ||
| 139 | + UserId int64 `path:",optional"` | ||
| 140 | + } | ||
| 141 | + MiniGetArticleCommentResponse { | ||
| 142 | + ArticleCommentAndReply | ||
| 143 | + } | ||
| 144 | +) | ||
| 145 | + | ||
| 146 | +// 小程序删除单个文章的评论 | ||
| 147 | +type ( | ||
| 148 | + MiniDeleteArticleCommentRequest { | ||
| 149 | + CommentId int64 `path:"id"` | ||
| 150 | + UserId int64 `path:",optional"` | ||
| 151 | + CompanyId int64 `path:",optional"` | ||
| 152 | + } | ||
| 153 | + MiniDeleteArticleCommentResponse { | ||
| 154 | + Id int64 `json:"id"` | ||
| 75 | } | 155 | } |
| 76 | ) | 156 | ) |
| @@ -48,6 +48,7 @@ type ( | @@ -48,6 +48,7 @@ type ( | ||
| 48 | DepartmentUpdateRequest { | 48 | DepartmentUpdateRequest { |
| 49 | Id int64 `path:"id"` | 49 | Id int64 `path:"id"` |
| 50 | Name string `json:"name"` | 50 | Name string `json:"name"` |
| 51 | + Ids []int64 `json:"ids"` // 用户ID | ||
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | DepartmentListRequest { | 54 | DepartmentListRequest { |
| 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"), |
| @@ -26,6 +26,7 @@ func NewMiniArticleMarkUserReadLogic(ctx context.Context, svcCtx *svc.ServiceCon | @@ -26,6 +26,7 @@ func NewMiniArticleMarkUserReadLogic(ctx context.Context, svcCtx *svc.ServiceCon | ||
| 26 | } | 26 | } |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | +// 记录人员浏览的文章 | ||
| 29 | func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniArticleMarkUserReadRequest) (resp *types.MiniArticleMarkUserReadResponse, err error) { | 30 | func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniArticleMarkUserReadRequest) (resp *types.MiniArticleMarkUserReadResponse, err error) { |
| 30 | var conn = l.svcCtx.DefaultDBConn() | 31 | var conn = l.svcCtx.DefaultDBConn() |
| 31 | 32 | ||
| @@ -84,7 +85,7 @@ func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniAr | @@ -84,7 +85,7 @@ func (l *MiniArticleMarkUserReadLogic) MiniArticleMarkUserRead(req *types.MiniAr | ||
| 84 | return err | 85 | return err |
| 85 | } | 86 | } |
| 86 | //增加浏览计数 | 87 | //增加浏览计数 |
| 87 | - err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo) | 88 | + err = l.svcCtx.ArticleRepository.IncreaseCountRead(ctx, c, 1, articleInfo.Id) |
| 88 | return err | 89 | return err |
| 89 | }, true) | 90 | }, true) |
| 90 | if err != nil { | 91 | if err != nil { |
| @@ -28,6 +28,7 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) | @@ -28,6 +28,7 @@ func NewMiniCreateArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) | ||
| 28 | } | 28 | } |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | +// 创建新文章 | ||
| 31 | func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) { | 32 | func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateRequest) (resp *types.MiniArticleCreateResponse, err error) { |
| 32 | var conn = l.svcCtx.DefaultDBConn() | 33 | var conn = l.svcCtx.DefaultDBConn() |
| 33 | // 检查发布人 | 34 | // 检查发布人 |
| @@ -26,6 +26,7 @@ func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi | @@ -26,6 +26,7 @@ func NewMiniGetArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Mi | ||
| 26 | } | 26 | } |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | +// 小程序端展示文章内容 | ||
| 29 | 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) { |
| 30 | // 获取文章内容 | 31 | // 获取文章内容 |
| 31 | var conn = l.svcCtx.DefaultDBConn() | 32 | var conn = l.svcCtx.DefaultDBConn() |
| @@ -88,10 +89,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -88,10 +89,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
| 88 | Title: articleInfo.Title, | 89 | Title: articleInfo.Title, |
| 89 | AuthorId: articleInfo.AuthorId, | 90 | AuthorId: articleInfo.AuthorId, |
| 90 | Author: types.ArticleAuthor{ | 91 | Author: types.ArticleAuthor{ |
| 91 | - Id: articleInfo.Author.Id, | ||
| 92 | - Name: articleInfo.Author.Name, | ||
| 93 | - Avatar: articleInfo.Author.Avatar, | ||
| 94 | - // Group: articleInfo.Author.Group, | 92 | + Id: articleInfo.Author.Id, |
| 93 | + Name: articleInfo.Author.Name, | ||
| 94 | + Avatar: articleInfo.Author.Avatar, | ||
| 95 | Position: articleInfo.Author.Position, | 95 | Position: articleInfo.Author.Position, |
| 96 | Company: articleInfo.Author.Company, | 96 | Company: articleInfo.Author.Company, |
| 97 | }, | 97 | }, |
| @@ -93,7 +93,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi | @@ -93,7 +93,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi | ||
| 93 | return err | 93 | return err |
| 94 | } | 94 | } |
| 95 | // 减少文章的点赞数量 | 95 | // 减少文章的点赞数量 |
| 96 | - err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo) | 96 | + err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, -1, articleInfo.Id) |
| 97 | if err != nil { | 97 | if err != nil { |
| 98 | return err | 98 | return err |
| 99 | } | 99 | } |
| @@ -166,7 +166,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi | @@ -166,7 +166,7 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi | ||
| 166 | return err | 166 | return err |
| 167 | } | 167 | } |
| 168 | // 减少评论的点赞数量 | 168 | // 减少评论的点赞数量 |
| 169 | - err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo) | 169 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, -1, commentInfo.Id) |
| 170 | if err != nil { | 170 | if err != nil { |
| 171 | return err | 171 | return err |
| 172 | } | 172 | } |
| @@ -239,7 +239,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ | @@ -239,7 +239,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ | ||
| 239 | return err | 239 | return err |
| 240 | } | 240 | } |
| 241 | // 增加文章的点赞数量 | 241 | // 增加文章的点赞数量 |
| 242 | - err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo) | 242 | + err = l.svcCtx.ArticleRepository.IncreaseCountLove(ctx, c, 1, articleInfo.Id) |
| 243 | if err != nil { | 243 | if err != nil { |
| 244 | return err | 244 | return err |
| 245 | } | 245 | } |
| @@ -320,7 +320,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ | @@ -320,7 +320,7 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ | ||
| 320 | return err | 320 | return err |
| 321 | } | 321 | } |
| 322 | // 增加评论的点赞数量 | 322 | // 增加评论的点赞数量 |
| 323 | - err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo) | 323 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountUserLove(ctx, c, 1, commentInfo.Id) |
| 324 | if err != nil { | 324 | if err != nil { |
| 325 | return err | 325 | return err |
| 326 | } | 326 | } |
| @@ -49,7 +49,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -49,7 +49,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 49 | return nil, xerr.NewErrMsg("没有评论权限") | 49 | return nil, xerr.NewErrMsg("没有评论权限") |
| 50 | } | 50 | } |
| 51 | //查看评论权限, | 51 | //查看评论权限, |
| 52 | - //临时注释 | 52 | + //TODO 临时注释 |
| 53 | // if len(articleInfo.WhoReview) > 0 { | 53 | // if len(articleInfo.WhoReview) > 0 { |
| 54 | // ok := lo.IndexOf(articleInfo.WhoReview, req.FromUserId) | 54 | // ok := lo.IndexOf(articleInfo.WhoReview, req.FromUserId) |
| 55 | // if ok < 0 { | 55 | // if ok < 0 { |
| @@ -84,14 +84,17 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -84,14 +84,17 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 84 | } | 84 | } |
| 85 | var atWhoList []*domain.User | 85 | var atWhoList []*domain.User |
| 86 | if len(req.AtWho) > 0 { | 86 | if len(req.AtWho) > 0 { |
| 87 | - queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", req.AtWho) | 87 | + uids := []int64{} |
| 88 | + for _, val := range req.AtWho { | ||
| 89 | + uids = append(uids, val.Id) | ||
| 90 | + } | ||
| 91 | + queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", uids) | ||
| 88 | _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption) | 92 | _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption) |
| 89 | if err != nil { | 93 | if err != nil { |
| 90 | return nil, xerr.NewErrMsgErr("检查@的人员失败", err) | 94 | return nil, xerr.NewErrMsgErr("检查@的人员失败", err) |
| 91 | } | 95 | } |
| 92 | } | 96 | } |
| 93 | // 处理文本内容 | 97 | // 处理文本内容 |
| 94 | - // content:= | ||
| 95 | content := template.HTMLEscapeString(req.Content) | 98 | content := template.HTMLEscapeString(req.Content) |
| 96 | 99 | ||
| 97 | newComment := domain.ArticleComment{ | 100 | newComment := domain.ArticleComment{ |
| @@ -149,11 +152,25 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -149,11 +152,25 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 149 | } | 152 | } |
| 150 | //保存数据 | 153 | //保存数据 |
| 151 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 154 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
| 152 | - // 增加平评论计数 | ||
| 153 | - err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo) | 155 | + // 增加文章评论计数 |
| 156 | + err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo.Id) | ||
| 154 | if err != nil { | 157 | if err != nil { |
| 155 | return err | 158 | return err |
| 156 | } | 159 | } |
| 160 | + //增加评论回复计数 | ||
| 161 | + if pComment != nil { | ||
| 162 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment.Id) | ||
| 163 | + if err != nil { | ||
| 164 | + return err | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + // 增加最顶层的评论回复计数 | ||
| 168 | + if newComment.TopId != 0 && newComment.Pid != newComment.TopId { | ||
| 169 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, newComment.TopId) | ||
| 170 | + if err != nil { | ||
| 171 | + return err | ||
| 172 | + } | ||
| 173 | + } | ||
| 157 | //保存评论 | 174 | //保存评论 |
| 158 | _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) | 175 | _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) |
| 159 | if err != nil { | 176 | if err != nil { |
| @@ -171,7 +188,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -171,7 +188,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 171 | Pid: newComment.Pid, | 188 | Pid: newComment.Pid, |
| 172 | TopId: newComment.TopId, | 189 | TopId: newComment.TopId, |
| 173 | ArtitcleId: newComment.ArticleId, | 190 | ArtitcleId: newComment.ArticleId, |
| 174 | - SectionId: newComment.ArticleId, | 191 | + SectionId: newComment.SectionId, |
| 175 | FromUserId: newComment.FromUserId, | 192 | FromUserId: newComment.FromUserId, |
| 176 | FromUser: types.CommentAuthor{ | 193 | FromUser: types.CommentAuthor{ |
| 177 | Id: newComment.FromUser.Id, | 194 | Id: newComment.FromUser.Id, |
| @@ -192,16 +209,14 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -192,16 +209,14 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
| 192 | CountReply: 0, | 209 | CountReply: 0, |
| 193 | CountUserLove: 0, | 210 | CountUserLove: 0, |
| 194 | CountAdminLove: 0, | 211 | CountAdminLove: 0, |
| 195 | - AtWho: []types.CommentAuthor{}, | 212 | + AtWho: []types.CommentAtWho{}, |
| 213 | + CreatedAt: newComment.CreatedAt, | ||
| 196 | } | 214 | } |
| 197 | 215 | ||
| 198 | for _, val := range newComment.AtWho { | 216 | for _, val := range newComment.AtWho { |
| 199 | - resp.AtWho = append(resp.AtWho, types.CommentAuthor{ | ||
| 200 | - Id: val.Id, | ||
| 201 | - Name: val.Name, | ||
| 202 | - Avatar: val.Avatar, | ||
| 203 | - Position: val.Position, | ||
| 204 | - Company: val.Company, | 217 | + resp.AtWho = append(resp.AtWho, types.CommentAtWho{ |
| 218 | + Id: val.Id, | ||
| 219 | + Name: val.Name, | ||
| 205 | }) | 220 | }) |
| 206 | } | 221 | } |
| 207 | 222 |
| 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 MiniDeleteArticleCommentLogic struct { | ||
| 16 | + logx.Logger | ||
| 17 | + ctx context.Context | ||
| 18 | + svcCtx *svc.ServiceContext | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +func NewMiniDeleteArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniDeleteArticleCommentLogic { | ||
| 22 | + return &MiniDeleteArticleCommentLogic{ | ||
| 23 | + Logger: logx.WithContext(ctx), | ||
| 24 | + ctx: ctx, | ||
| 25 | + svcCtx: svcCtx, | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// 小程序端人人员删除评论 | ||
| 30 | +func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.MiniDeleteArticleCommentRequest) (resp *types.MiniDeleteArticleCommentResponse, err error) { | ||
| 31 | + var conn = l.svcCtx.DefaultDBConn() | ||
| 32 | + commetInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId) | ||
| 33 | + if err != nil { | ||
| 34 | + return nil, xerr.NewErrMsgErr("删除评论信息失败", err) | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + if commetInfo.FromUserId != req.UserId { | ||
| 38 | + return nil, xerr.NewErrMsg("没有操作权限") | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + commetInfo.Show = domain.CommentShowDisable | ||
| 42 | + | ||
| 43 | + // 变更回复数量 | ||
| 44 | + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | ||
| 45 | + _, err = l.svcCtx.ArticleCommentRepository.Update(ctx, c, commetInfo) | ||
| 46 | + if err != nil { | ||
| 47 | + return err | ||
| 48 | + } | ||
| 49 | + // 减少上级评论的回复数量 | ||
| 50 | + if commetInfo.Pid != 0 { | ||
| 51 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.Pid) | ||
| 52 | + if err != nil { | ||
| 53 | + return err | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + // 减少最顶层的评论回复计数 | ||
| 57 | + if commetInfo.TopId != 0 && commetInfo.Pid != commetInfo.TopId { | ||
| 58 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, -1, commetInfo.TopId) | ||
| 59 | + if err != nil { | ||
| 60 | + return err | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + return nil | ||
| 64 | + }, true) | ||
| 65 | + | ||
| 66 | + if err != nil { | ||
| 67 | + return nil, xerr.NewErrMsgErr("删除评论信息失败", err) | ||
| 68 | + } | ||
| 69 | + resp = &types.MiniDeleteArticleCommentResponse{Id: commetInfo.Id} | ||
| 70 | + return resp, nil | ||
| 71 | +} |
| 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 | +// 获取单条评论详情 | ||
| 29 | +func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) { | ||
| 30 | + var conn = l.svcCtx.DefaultDBConn() | ||
| 31 | + //获取主评论 | ||
| 32 | + commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId) | ||
| 33 | + if err != nil { | ||
| 34 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
| 35 | + } | ||
| 36 | + if commentInfo.CompanyId != req.CompanyId { | ||
| 37 | + return nil, xerr.NewErrMsg("没有查看权限") | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + if commentInfo.Show == domain.CommentShowDisable { | ||
| 41 | + return nil, xerr.NewErrMsg("没有查看权限") | ||
| 42 | + } | ||
| 43 | + queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("topId", commentInfo.Id).MustWithKV("show", domain.CommentShowEnable) | ||
| 44 | + //获取回复的评论 | ||
| 45 | + _, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption) | ||
| 46 | + | ||
| 47 | + if err != nil { | ||
| 48 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
| 49 | + } | ||
| 50 | + queryOption = domain.NewQueryOptions().WithFindOnly(). | ||
| 51 | + MustWithKV("articleId", commentInfo.ArticleId). | ||
| 52 | + MustWithKV("userId", req.UserId) | ||
| 53 | + // 获取我点赞的评论 | ||
| 54 | + _, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption) | ||
| 55 | + if err != nil { | ||
| 56 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
| 57 | + } | ||
| 58 | + // 我点赞的 | ||
| 59 | + flagMap := map[int64]struct{}{} | ||
| 60 | + for _, val := range userFlagList { | ||
| 61 | + flagMap[val.CommentId] = struct{}{} | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + //混合数据 | ||
| 65 | + commentResp := types.ArticleCommentItem{ | ||
| 66 | + Id: commentInfo.Id, | ||
| 67 | + Pid: commentInfo.Pid, | ||
| 68 | + TopId: commentInfo.TopId, | ||
| 69 | + ArtitcleId: commentInfo.ArticleId, | ||
| 70 | + SectionId: commentInfo.ArticleId, | ||
| 71 | + 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 | + }, | ||
| 79 | + 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 | + }, | ||
| 87 | + SectionContent: commentInfo.SectionContent, | ||
| 88 | + CountReply: commentInfo.CountReply, | ||
| 89 | + CountUserLove: commentInfo.CountUserLove, | ||
| 90 | + CountAdminLove: commentInfo.CountAdminLove, | ||
| 91 | + AtWho: []types.CommentAtWho{}, | ||
| 92 | + CreatedAt: commentInfo.CreatedAt, | ||
| 93 | + MeLoveFlag: 0, | ||
| 94 | + } | ||
| 95 | + if _, ok := flagMap[commentInfo.Id]; ok { | ||
| 96 | + commentResp.MeLoveFlag = 1 | ||
| 97 | + } | ||
| 98 | + for _, val := range commentInfo.AtWho { | ||
| 99 | + commentResp.AtWho = append(commentResp.AtWho, types.CommentAtWho{ | ||
| 100 | + Id: val.Id, | ||
| 101 | + Name: val.Name, | ||
| 102 | + }) | ||
| 103 | + } | ||
| 104 | + // 回复的评论 | ||
| 105 | + allReply := []types.ArticleCommentItem{} | ||
| 106 | + for _, val := range replyCommenList { | ||
| 107 | + reply := types.ArticleCommentItem{ | ||
| 108 | + Id: val.Id, | ||
| 109 | + Pid: val.Pid, | ||
| 110 | + TopId: val.TopId, | ||
| 111 | + ArtitcleId: val.ArticleId, | ||
| 112 | + SectionId: val.SectionId, | ||
| 113 | + FromUserId: val.FromUserId, | ||
| 114 | + FromUser: types.CommentAuthor{ | ||
| 115 | + Id: val.FromUser.Id, | ||
| 116 | + Name: val.FromUser.Name, | ||
| 117 | + Avatar: val.FromUser.Avatar, | ||
| 118 | + Position: val.FromUser.Position, | ||
| 119 | + Company: val.FromUser.Company, | ||
| 120 | + }, | ||
| 121 | + ToUserId: val.ToUserId, | ||
| 122 | + ToUser: types.CommentAuthor{ | ||
| 123 | + Id: val.ToUser.Id, | ||
| 124 | + Name: val.ToUser.Name, | ||
| 125 | + Avatar: val.ToUser.Avatar, | ||
| 126 | + Position: val.ToUser.Position, | ||
| 127 | + Company: val.ToUser.Company, | ||
| 128 | + }, | ||
| 129 | + SectionContent: val.SectionContent, | ||
| 130 | + CountReply: val.CountReply, | ||
| 131 | + CountUserLove: val.CountUserLove, | ||
| 132 | + CountAdminLove: val.CountAdminLove, | ||
| 133 | + AtWho: []types.CommentAtWho{}, | ||
| 134 | + CreatedAt: val.CreatedAt, | ||
| 135 | + MeLoveFlag: 0, | ||
| 136 | + } | ||
| 137 | + if _, ok := flagMap[val.Id]; ok { | ||
| 138 | + reply.MeLoveFlag = 1 | ||
| 139 | + } | ||
| 140 | + for _, val2 := range val.AtWho { | ||
| 141 | + reply.AtWho = append(reply.AtWho, types.CommentAtWho{ | ||
| 142 | + Id: val2.Id, | ||
| 143 | + Name: val2.Name, | ||
| 144 | + }) | ||
| 145 | + } | ||
| 146 | + allReply = append(allReply, reply) | ||
| 147 | + } | ||
| 148 | + resp = &types.MiniGetArticleCommentResponse{ | ||
| 149 | + ArticleCommentAndReply: types.ArticleCommentAndReply{ | ||
| 150 | + Comment: commentResp, | ||
| 151 | + Reply: allReply, | ||
| 152 | + TotalReply: int64(len(replyCommenList)), | ||
| 153 | + }, | ||
| 154 | + } | ||
| 155 | + return | ||
| 156 | +} |
| 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 | +} |
| @@ -31,14 +31,14 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types | @@ -31,14 +31,14 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types | ||
| 31 | var userToken = contextdata.GetUserTokenFromCtx(l.ctx) | 31 | var userToken = contextdata.GetUserTokenFromCtx(l.ctx) |
| 32 | var conn = l.svcCtx.DefaultDBConn() | 32 | var conn = l.svcCtx.DefaultDBConn() |
| 33 | 33 | ||
| 34 | - _, list, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | ||
| 35 | - WithOffsetLimit(1, 1).WithFindOnly(). | 34 | + total, _, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
| 35 | + WithCountOnly(). | ||
| 36 | WithKV("companyId", userToken.CompanyId). | 36 | WithKV("companyId", userToken.CompanyId). |
| 37 | WithKV("name", req.Name)) | 37 | WithKV("name", req.Name)) |
| 38 | if err != nil { | 38 | if err != nil { |
| 39 | return nil, err | 39 | return nil, err |
| 40 | } | 40 | } |
| 41 | - if len(list) > 0 { | 41 | + if total > 0 { |
| 42 | return nil, xerr.NewErrMsg("该分组名称已存在(不能重复)") | 42 | return nil, xerr.NewErrMsg("该分组名称已存在(不能重复)") |
| 43 | } | 43 | } |
| 44 | 44 |
| @@ -31,15 +31,15 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re | @@ -31,15 +31,15 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re | ||
| 31 | var userToken = contextdata.GetUserTokenFromCtx(l.ctx) | 31 | var userToken = contextdata.GetUserTokenFromCtx(l.ctx) |
| 32 | var conn = l.svcCtx.DefaultDBConn() | 32 | var conn = l.svcCtx.DefaultDBConn() |
| 33 | 33 | ||
| 34 | - _, list, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | ||
| 35 | - WithOffsetLimit(1, 1).WithCountOnly(). | 34 | + total, _, err := l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.NewQueryOptions(). |
| 35 | + WithCountOnly(). | ||
| 36 | WithKV("companyId", userToken.CompanyId). | 36 | WithKV("companyId", userToken.CompanyId). |
| 37 | WithKV("notId", req.Id). // 排除自己 | 37 | WithKV("notId", req.Id). // 排除自己 |
| 38 | WithKV("name", req.Name)) | 38 | WithKV("name", req.Name)) |
| 39 | if err != nil { | 39 | if err != nil { |
| 40 | return nil, err | 40 | return nil, err |
| 41 | } | 41 | } |
| 42 | - if len(list) > 0 { | 42 | + if total > 0 { |
| 43 | return nil, xerr.NewErrMsg("该分组名称已存在(不能重复)") | 43 | return nil, xerr.NewErrMsg("该分组名称已存在(不能重复)") |
| 44 | } | 44 | } |
| 45 | 45 | ||
| @@ -49,10 +49,59 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re | @@ -49,10 +49,59 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re | ||
| 49 | } | 49 | } |
| 50 | one.Name = req.Name | 50 | one.Name = req.Name |
| 51 | 51 | ||
| 52 | + // 更新分组中的用户Id | ||
| 53 | + var newIdMap = map[int64]int{} | ||
| 54 | + for i := range req.Ids { | ||
| 55 | + newIdMap[req.Ids[i]] = 0 | ||
| 56 | + } | ||
| 57 | + | ||
| 52 | // 更新 | 58 | // 更新 |
| 53 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 59 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
| 54 | _, err = l.svcCtx.DepartmentRepository.UpdateWithVersion(l.ctx, conn, one) | 60 | _, err = l.svcCtx.DepartmentRepository.UpdateWithVersion(l.ctx, conn, one) |
| 55 | - return err | 61 | + if err != nil { |
| 62 | + return err | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + // 获取公司下的所有用户 | ||
| 66 | + _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). | ||
| 67 | + WithFindOnly(). | ||
| 68 | + WithKV(" companyId", one.CompanyId)) | ||
| 69 | + if err != nil { | ||
| 70 | + return err | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + var findIndex = func(ids []int64, id int64) int { | ||
| 74 | + for i, _ := range ids { | ||
| 75 | + if ids[i] == id { | ||
| 76 | + return i | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + return -1 | ||
| 80 | + } | ||
| 81 | + for i := range users { | ||
| 82 | + var user = users[i] | ||
| 83 | + if _, ok := newIdMap[user.Id]; ok { | ||
| 84 | + var targetIndex = findIndex(user.Departments, req.Id) | ||
| 85 | + if targetIndex == -1 { // 归属分组不存在,则新增 | ||
| 86 | + user.Departments = append(user.Departments) | ||
| 87 | + _, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user) | ||
| 88 | + if err != nil { | ||
| 89 | + return err | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + } else { | ||
| 93 | + var targetIndex = findIndex(user.Departments, req.Id) | ||
| 94 | + if targetIndex != -1 { // 归属分组存在,则移除 | ||
| 95 | + user.Departments = append(user.Departments[:targetIndex], user.Departments[targetIndex+1:]...) // 移除分组ID | ||
| 96 | + _, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user) | ||
| 97 | + if err != nil { | ||
| 98 | + return err | ||
| 99 | + } | ||
| 100 | + } | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + return nil | ||
| 56 | }, true) | 105 | }, true) |
| 57 | if err != nil { | 106 | if err != nil { |
| 58 | return nil, xerr.NewErrMsgErr("分组修改失败", err) | 107 | return nil, xerr.NewErrMsgErr("分组修改失败", err) |
| @@ -9,38 +9,101 @@ type MiniArticleCommentAtUserResponse struct { | @@ -9,38 +9,101 @@ type MiniArticleCommentAtUserResponse struct { | ||
| 9 | } | 9 | } |
| 10 | 10 | ||
| 11 | type CommentAuthor struct { | 11 | type CommentAuthor struct { |
| 12 | - Id int64 `json:"id"` // 人员id | ||
| 13 | - Name string `json:"name"` // 人员的名字 | ||
| 14 | - Avatar string `json:"avatar"` // 人员头像URL | ||
| 15 | - Position string `json:"position"` // 职位 | ||
| 16 | - Company string `json:"company"` // 公司 | 12 | + Id int64 `json:"id"` // 人员id |
| 13 | + Name string `json:"name"` // 人员的名字 | ||
| 14 | + Avatar string `json:"avatar,optional"` // 人员头像URL | ||
| 15 | + Position string `json:"position,optional"` // 职位 | ||
| 16 | + Company string `json:"company,optional"` // 公司 | ||
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | type MiniCreateArticleCommentRequest struct { | 19 | type MiniCreateArticleCommentRequest struct { |
| 20 | - ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 21 | - SectionId int64 `json:"sectionId"` // 段落id | ||
| 22 | - FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取 | ||
| 23 | - CompanyId int64 `json:",optional"` // 服务端自动获取 | ||
| 24 | - Pid int64 `json:"commnet"` // 回复那个评论的id | ||
| 25 | - Content string `json:"content"` // 评论的内容 | ||
| 26 | - AtWho []int64 `json:"atWho"` // 填写评论时@的人 | 20 | + ArtitcleId int64 `json:"articleId"` // 文章id |
| 21 | + SectionId int64 `json:"sectionId"` // 段落id | ||
| 22 | + FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取 | ||
| 23 | + CompanyId int64 `json:",optional"` // 服务端自动获取 | ||
| 24 | + Pid int64 `json:"pid"` // 回复那个评论的id | ||
| 25 | + Content string `json:"content"` // 评论的内容 | ||
| 26 | + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +type CommentAtWho struct { | ||
| 30 | + Id int64 `json:"id"` | ||
| 31 | + Name string `json:"name,optional"` | ||
| 27 | } | 32 | } |
| 28 | 33 | ||
| 29 | type MiniCreateArticleCommentResponse struct { | 34 | type MiniCreateArticleCommentResponse struct { |
| 30 | - Id int64 `json:"id"` | ||
| 31 | - Pid int64 `json:"pid"` | ||
| 32 | - TopId int64 `json:"topId"` | ||
| 33 | - ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 34 | - SectionId int64 `json:"sectionId"` // 段落id | ||
| 35 | - FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
| 36 | - FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
| 37 | - ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
| 38 | - ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
| 39 | - SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
| 40 | - CountReply int `json:"countReply"` // 回复数量 | ||
| 41 | - CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
| 42 | - CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
| 43 | - AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | 35 | + Id int64 `json:"id"` |
| 36 | + Pid int64 `json:"pid"` | ||
| 37 | + TopId int64 `json:"topId"` | ||
| 38 | + ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 39 | + SectionId int64 `json:"sectionId"` // 段落id | ||
| 40 | + FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
| 41 | + FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
| 42 | + ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
| 43 | + ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
| 44 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
| 45 | + CountReply int `json:"countReply"` // 回复数量 | ||
| 46 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
| 47 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
| 48 | + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 | ||
| 49 | + CreatedAt int64 `json:"createdAt"` // | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +type MiniListArticleCommentRequest struct { | ||
| 53 | + Page int64 `json:"page"` | ||
| 54 | + Size int64 `json:"size"` | ||
| 55 | + CompanyId int64 `json:",optional"` | ||
| 56 | + SectionId int64 `json:"sectionId"` | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +type MiniListArticleCommentResponse struct { | ||
| 60 | + Total int64 `json:"total"` | ||
| 61 | + List []ArticleCommentAndReply `json:"list"` | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +type ArticleCommentAndReply struct { | ||
| 65 | + Comment ArticleCommentItem `json:"comment"` //评论 | ||
| 66 | + Reply []ArticleCommentItem `json:"reply"` //回复的评论 | ||
| 67 | + TotalReply int64 `json:"totalReply"` //回复的评论数量 | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | +type ArticleCommentItem struct { | ||
| 71 | + Id int64 `json:"id"` | ||
| 72 | + Pid int64 `json:"pid"` | ||
| 73 | + TopId int64 `json:"topId"` | ||
| 74 | + ArtitcleId int64 `json:"articleId"` // 文章id | ||
| 75 | + SectionId int64 `json:"sectionId"` // 段落id | ||
| 76 | + FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
| 77 | + FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
| 78 | + ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
| 79 | + ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
| 80 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
| 81 | + CountReply int `json:"countReply"` // 回复数量 | ||
| 82 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
| 83 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
| 84 | + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 | ||
| 85 | + CreatedAt int64 `json:"createdAt"` // | ||
| 86 | + MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +type MiniGetArticleCommentRequest struct { | ||
| 90 | + CommentId int64 `path:"id"` | ||
| 91 | + CompanyId int64 `path:",optional"` | ||
| 92 | + UserId int64 `path:",optional"` | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +type MiniGetArticleCommentResponse struct { | ||
| 96 | + ArticleCommentAndReply | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +type MiniDeleteArticleCommentRequest struct { | ||
| 100 | + CommentId int64 `path:"id"` | ||
| 101 | + UserId int64 `path:",optional"` | ||
| 102 | + CompanyId int64 `path:",optional"` | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | +type MiniDeleteArticleCommentResponse struct { | ||
| 106 | + Id int64 `json:"id"` | ||
| 44 | } | 107 | } |
| 45 | 108 | ||
| 46 | type MessageSystemRequest struct { | 109 | type MessageSystemRequest struct { |
| @@ -520,7 +583,7 @@ type MiniArticleGetResponse struct { | @@ -520,7 +583,7 @@ type MiniArticleGetResponse struct { | ||
| 520 | CountRead int `json:"countRead"` // 浏览数量 | 583 | CountRead int `json:"countRead"` // 浏览数量 |
| 521 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 584 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) |
| 522 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) | 585 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) |
| 523 | - MeLoveFlag int `json:"meLoveFlag"` //当前人员对文章的点赞标识 | 586 | + MeLoveFlag int `json:"meLoveFlag"` // 当前人员对文章的点赞标识 (0 没有点赞 1有点赞) |
| 524 | } | 587 | } |
| 525 | 588 | ||
| 526 | type ArticleSection struct { | 589 | type ArticleSection struct { |
| @@ -849,8 +912,9 @@ type DepartmentGetResponse struct { | @@ -849,8 +912,9 @@ type DepartmentGetResponse struct { | ||
| 849 | } | 912 | } |
| 850 | 913 | ||
| 851 | type DepartmentUpdateRequest struct { | 914 | type DepartmentUpdateRequest struct { |
| 852 | - Id int64 `path:"id"` | ||
| 853 | - Name string `json:"name"` | 915 | + Id int64 `path:"id"` |
| 916 | + Name string `json:"name"` | ||
| 917 | + Ids []int64 `json:"ids"` // 用户ID | ||
| 854 | } | 918 | } |
| 855 | 919 | ||
| 856 | type DepartmentListRequest struct { | 920 | type DepartmentListRequest struct { |
| @@ -9,6 +9,7 @@ import ( | @@ -9,6 +9,7 @@ import ( | ||
| 9 | "gorm.io/plugin/soft_delete" | 9 | "gorm.io/plugin/soft_delete" |
| 10 | ) | 10 | ) |
| 11 | 11 | ||
| 12 | +// 文章的所有标签 | ||
| 12 | type ArticleTag struct { | 13 | type ArticleTag struct { |
| 13 | Id int64 `gorm:"primaryKey"` // 唯一标识 | 14 | Id int64 `gorm:"primaryKey"` // 唯一标识 |
| 14 | CompanyId int64 | 15 | CompanyId int64 |
| @@ -21,9 +21,13 @@ func (repository *ArticleCommentRepository) Insert(ctx context.Context, conn tra | @@ -21,9 +21,13 @@ func (repository *ArticleCommentRepository) Insert(ctx context.Context, conn tra | ||
| 21 | m = &models.ArticleComment{} | 21 | m = &models.ArticleComment{} |
| 22 | tx = conn.DB() | 22 | tx = conn.DB() |
| 23 | ) | 23 | ) |
| 24 | + if len(dm.AtWho) == 0 { | ||
| 25 | + dm.AtWho = make([]domain.UserSimple, 0) | ||
| 26 | + } | ||
| 24 | if m, err = repository.DomainModelToModel(dm); err != nil { | 27 | if m, err = repository.DomainModelToModel(dm); err != nil { |
| 25 | return nil, err | 28 | return nil, err |
| 26 | } | 29 | } |
| 30 | + | ||
| 27 | if tx = tx.Model(m).Save(m); tx.Error != nil { | 31 | if tx = tx.Model(m).Save(m); tx.Error != nil { |
| 28 | return nil, tx.Error | 32 | return nil, tx.Error |
| 29 | } | 33 | } |
| @@ -120,6 +124,12 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans | @@ -120,6 +124,12 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans | ||
| 120 | ) | 124 | ) |
| 121 | queryFunc := func() (interface{}, error) { | 125 | queryFunc := func() (interface{}, error) { |
| 122 | tx = tx.Model(&ms).Order("id desc") | 126 | tx = tx.Model(&ms).Order("id desc") |
| 127 | + if v, ok := queryOptions["topId"]; ok { | ||
| 128 | + tx = tx.Where("top_id", v) | ||
| 129 | + } | ||
| 130 | + if v, ok := queryOptions["show"]; ok { | ||
| 131 | + tx = tx.Where("show", v) | ||
| 132 | + } | ||
| 123 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 133 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 124 | return dms, tx.Error | 134 | return dms, tx.Error |
| 125 | } | 135 | } |
| @@ -162,6 +172,7 @@ func (repository *ArticleCommentRepository) ModelToDomainModel(from *models.Arti | @@ -162,6 +172,7 @@ func (repository *ArticleCommentRepository) ModelToDomainModel(from *models.Arti | ||
| 162 | CountUserLove: from.CountUserLove, | 172 | CountUserLove: from.CountUserLove, |
| 163 | CountAdminLove: from.CountAdminLove, | 173 | CountAdminLove: from.CountAdminLove, |
| 164 | Show: domain.CommentShow(from.Show), | 174 | Show: domain.CommentShow(from.Show), |
| 175 | + AtWho: from.AtWho, | ||
| 165 | } | 176 | } |
| 166 | // err := copier.Copy(to, from) | 177 | // err := copier.Copy(to, from) |
| 167 | return to, nil | 178 | return to, nil |
| @@ -173,6 +184,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | @@ -173,6 +184,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | ||
| 173 | CompanyId: from.CompanyId, | 184 | CompanyId: from.CompanyId, |
| 174 | CreatedAt: from.CreatedAt, | 185 | CreatedAt: from.CreatedAt, |
| 175 | UpdatedAt: from.UpdatedAt, | 186 | UpdatedAt: from.UpdatedAt, |
| 187 | + IsDel: 0, | ||
| 176 | DeletedAt: from.DeletedAt, | 188 | DeletedAt: from.DeletedAt, |
| 177 | Version: from.Version, | 189 | Version: from.Version, |
| 178 | Pid: from.Pid, | 190 | Pid: from.Pid, |
| @@ -184,6 +196,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | @@ -184,6 +196,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | ||
| 184 | FromUser: from.FromUser, | 196 | FromUser: from.FromUser, |
| 185 | ToUserId: from.ToUser.Id, | 197 | ToUserId: from.ToUser.Id, |
| 186 | ToUser: from.ToUser, | 198 | ToUser: from.ToUser, |
| 199 | + AtWho: from.AtWho, | ||
| 187 | Content: from.Content, | 200 | Content: from.Content, |
| 188 | CountReply: from.CountReply, | 201 | CountReply: from.CountReply, |
| 189 | CountUserLove: from.CountUserLove, | 202 | CountUserLove: from.CountUserLove, |
| @@ -195,17 +208,34 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | @@ -195,17 +208,34 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | ||
| 195 | } | 208 | } |
| 196 | 209 | ||
| 197 | // 点赞数量变动 | 210 | // 点赞数量变动 |
| 198 | -func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error { | 211 | +func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commnetId int64) error { |
| 199 | var ( | 212 | var ( |
| 200 | err error | 213 | err error |
| 201 | m *models.ArticleComment | 214 | m *models.ArticleComment |
| 202 | tx = conn.DB() | 215 | tx = conn.DB() |
| 203 | ) | 216 | ) |
| 204 | - if m, err = repository.DomainModelToModel(dm); err != nil { | 217 | + m = &models.ArticleComment{Id: commnetId} |
| 218 | + queryFunc := func() (interface{}, error) { | ||
| 219 | + tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr)) | ||
| 220 | + return nil, tx.Error | ||
| 221 | + } | ||
| 222 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 205 | return err | 223 | return err |
| 206 | } | 224 | } |
| 225 | + return nil | ||
| 226 | + | ||
| 227 | +} | ||
| 228 | + | ||
| 229 | +// 点赞数量变动 | ||
| 230 | +func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, commnetId int64) error { | ||
| 231 | + var ( | ||
| 232 | + err error | ||
| 233 | + m *models.ArticleComment | ||
| 234 | + tx = conn.DB() | ||
| 235 | + ) | ||
| 236 | + m = &models.ArticleComment{Id: commnetId} | ||
| 207 | queryFunc := func() (interface{}, error) { | 237 | queryFunc := func() (interface{}, error) { |
| 208 | - tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr)) | 238 | + tx = tx.Model(m).Update("count_reply", gorm.Expr("count_reply+?", incr)) |
| 209 | return nil, tx.Error | 239 | return nil, tx.Error |
| 210 | } | 240 | } |
| 211 | if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | 241 | if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { |
| @@ -203,16 +203,14 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | @@ -203,16 +203,14 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | ||
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | // 点赞数量变动 | 205 | // 点赞数量变动 |
| 206 | -func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { | 206 | +func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error { |
| 207 | // | 207 | // |
| 208 | var ( | 208 | var ( |
| 209 | err error | 209 | err error |
| 210 | m *models.Article | 210 | m *models.Article |
| 211 | tx = conn.DB() | 211 | tx = conn.DB() |
| 212 | ) | 212 | ) |
| 213 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 214 | - return err | ||
| 215 | - } | 213 | + m = &models.Article{Id: articleId} |
| 216 | queryFunc := func() (interface{}, error) { | 214 | queryFunc := func() (interface{}, error) { |
| 217 | tx = tx.Model(m).Updates(map[string]interface{}{ | 215 | tx = tx.Model(m).Updates(map[string]interface{}{ |
| 218 | "count_love": gorm.Expr("count_love+?", incr), | 216 | "count_love": gorm.Expr("count_love+?", incr), |
| @@ -227,15 +225,13 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn | @@ -227,15 +225,13 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn | ||
| 227 | } | 225 | } |
| 228 | 226 | ||
| 229 | // 浏览数量变动 | 227 | // 浏览数量变动 |
| 230 | -func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { | 228 | +func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error { |
| 231 | var ( | 229 | var ( |
| 232 | err error | 230 | err error |
| 233 | m *models.Article | 231 | m *models.Article |
| 234 | tx = conn.DB() | 232 | tx = conn.DB() |
| 235 | ) | 233 | ) |
| 236 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 237 | - return err | ||
| 238 | - } | 234 | + m = &models.Article{Id: articleId} |
| 239 | queryFunc := func() (interface{}, error) { | 235 | queryFunc := func() (interface{}, error) { |
| 240 | tx = tx.Model(m).Updates(map[string]interface{}{ | 236 | tx = tx.Model(m).Updates(map[string]interface{}{ |
| 241 | "version": gorm.Expr("version+1"), | 237 | "version": gorm.Expr("version+1"), |
| @@ -250,15 +246,13 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn | @@ -250,15 +246,13 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn | ||
| 250 | } | 246 | } |
| 251 | 247 | ||
| 252 | // 评论数量变动 | 248 | // 评论数量变动 |
| 253 | -func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { | 249 | +func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error { |
| 254 | var ( | 250 | var ( |
| 255 | err error | 251 | err error |
| 256 | m *models.Article | 252 | m *models.Article |
| 257 | tx = conn.DB() | 253 | tx = conn.DB() |
| 258 | ) | 254 | ) |
| 259 | - if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 260 | - return err | ||
| 261 | - } | 255 | + m = &models.Article{Id: articleId} |
| 262 | queryFunc := func() (interface{}, error) { | 256 | queryFunc := func() (interface{}, error) { |
| 263 | tx = tx.Model(m).Updates(map[string]interface{}{ | 257 | tx = tx.Model(m).Updates(map[string]interface{}{ |
| 264 | "version": gorm.Expr("version+1"), | 258 | "version": gorm.Expr("version+1"), |
| @@ -38,9 +38,9 @@ type ArticleRepository interface { | @@ -38,9 +38,9 @@ type ArticleRepository interface { | ||
| 38 | UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) | 38 | UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Article) (*Article, error) |
| 39 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error) | 39 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Article, error) |
| 40 | Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error) | 40 | Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*Article, error) |
| 41 | - IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //点赞数量变动 | ||
| 42 | - IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //评论数量变动 | ||
| 43 | - IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *Article) error //浏览数量变动 | 41 | + IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //点赞数量变动 |
| 42 | + IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //评论数量变动 | ||
| 43 | + IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, articleId int64) error //浏览数量变动 | ||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | type ArticleTarget int | 46 | type ArticleTarget int |
| @@ -40,6 +40,16 @@ const ( | @@ -40,6 +40,16 @@ const ( | ||
| 40 | CommentShowDisable CommentShow = 1 | 40 | CommentShowDisable CommentShow = 1 |
| 41 | ) | 41 | ) |
| 42 | 42 | ||
| 43 | +func (show CommentShow) Named() string { | ||
| 44 | + switch show { | ||
| 45 | + case CommentShowEnable: | ||
| 46 | + return "显示" | ||
| 47 | + case CommentShowDisable: | ||
| 48 | + return "隐藏" | ||
| 49 | + } | ||
| 50 | + return "" | ||
| 51 | +} | ||
| 52 | + | ||
| 43 | type ArticleCommentRepository interface { | 53 | type ArticleCommentRepository interface { |
| 44 | Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | 54 | Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) |
| 45 | Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | 55 | Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) |
| @@ -47,5 +57,6 @@ type ArticleCommentRepository interface { | @@ -47,5 +57,6 @@ type ArticleCommentRepository interface { | ||
| 47 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | 57 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) |
| 48 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) | 58 | 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) | 59 | 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 //点赞数量变动 | 60 | + 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 // 评论回复数量变动 | ||
| 51 | } | 62 | } |
-
请 注册 或 登录 后发表评论