作者 yangfu

权限认证

正在显示 36 个修改的文件 包含 1113 行增加33 行删除
@@ -63,6 +63,15 @@ service Core { @@ -63,6 +63,15 @@ service Core {
63 @doc "小程序获取文章的编辑记录" 63 @doc "小程序获取文章的编辑记录"
64 @handler MiniArticleBackupSearch 64 @handler MiniArticleBackupSearch
65 post /article_backup/search (MiniArticleBackupSearchRequest) returns (MiniArticleBackupSearchResponse) 65 post /article_backup/search (MiniArticleBackupSearchRequest) returns (MiniArticleBackupSearchResponse)
  66 +
  67 +
  68 + @doc "小程序设置文章的定性标签"
  69 + @handler MiniArticleSetTag
  70 + post /article/set_tag (MiniArticleSetTagRequest) returns (MiniArticleSetTagResponse)
  71 +
  72 + @doc "小程序所有的定性标签"
  73 + @handler MiniAllArticleTag
  74 + get /article_tag/list/all (MiniAllArticleTagRequest) returns (MiniAllArticleTagResponse)
66 } 75 }
67 76
68 // 管理后台接口 77 // 管理后台接口
@@ -278,6 +278,39 @@ type ( @@ -278,6 +278,39 @@ type (
278 } 278 }
279 ) 279 )
280 280
  281 +//小程序端设置文章的定性标签
  282 +type (
  283 + MiniArticleSetTagRequest{
  284 + CompanyId int64 `json:",optional"` // 公司id
  285 + UserId int64 `json:",optional"` // 公司id
  286 + ArticleId int64 `json:"articleId"` // 文章id
  287 + TagId int64 `json:"tagId"` // 标签id
  288 + }
  289 + MiniArticleSetTagResponse{
  290 + Id int64 `json:"id"`
  291 + }
  292 +)
  293 +
  294 +
  295 +//小程序端获取所有的定性标签
  296 +type (
  297 + MiniAllArticleTagRequest{
  298 + CompanyId int64 `json:",optional"` // 公司id
  299 + UserId int64 `json:",optional"` // 公司id
  300 + ArticleId int64 `json:"articleId"` // 文章id
  301 + TagId int64 `json:"tagId"` // 标签id
  302 + }
  303 + MiniAllArticleTagResponse{
  304 + TagGroup []string `json:"tagGroup"`
  305 + Tags []ArticleTagItem `json:"tags"`
  306 + }
  307 +
  308 + ArticleTagItem {
  309 + Id int64 `json:"id"`
  310 + Group string `json:"group"`
  311 + Name string `json:"name"`
  312 + }
  313 +)
281 314
282 315
283 316
@@ -28,6 +28,10 @@ service Core { @@ -28,6 +28,10 @@ service Core {
28 @handler MiniListArticleComment 28 @handler MiniListArticleComment
29 post /article_comment/list (MiniListArticleCommentRequest) returns (MiniListArticleCommentResponse) 29 post /article_comment/list (MiniListArticleCommentRequest) returns (MiniListArticleCommentResponse)
30 30
  31 + @doc "小程序展示文章的评论列表TOP5"
  32 + @handler MiniTop5ArticleComment
  33 + post /article_comment/top5 (MiniTop5ArticleCommentRequest) returns (MiniTop5ArticleCommentResponse)
  34 +
31 @doc "小程序展示单个文章的评论" 35 @doc "小程序展示单个文章的评论"
32 @handler MiniGetArticleComment 36 @handler MiniGetArticleComment
33 get /article_comment/:id (MiniGetArticleCommentRequest) returns (MiniGetArticleCommentResponse) 37 get /article_comment/:id (MiniGetArticleCommentRequest) returns (MiniGetArticleCommentResponse)
@@ -35,6 +39,10 @@ service Core { @@ -35,6 +39,10 @@ service Core {
35 @doc "小程序展示删除文章评论" 39 @doc "小程序展示删除文章评论"
36 @handler MiniDeleteArticleComment 40 @handler MiniDeleteArticleComment
37 delete /article_comment/:id (MiniDeleteArticleCommentRequest) returns (MiniDeleteArticleCommentResponse) 41 delete /article_comment/:id (MiniDeleteArticleCommentRequest) returns (MiniDeleteArticleCommentResponse)
  42 +
  43 + @doc "小程序展示评论时@人可选列表"
  44 + @handler MiniArticleCommentAtWho
  45 + post /article_comment/at_who/list (MiniArticleCommentAtWhoRequest) returns (MiniArticleCommentAtWhoResponse)
38 } 46 }
39 47
40 // 48 //
@@ -95,10 +103,12 @@ type ( @@ -95,10 +103,12 @@ type (
95 // 小程序获取文章的评论列表 103 // 小程序获取文章的评论列表
96 type ( 104 type (
97 MiniListArticleCommentRequest { 105 MiniListArticleCommentRequest {
98 - Page int64 `json:"page"`  
99 - Size int64 `json:"size"` 106 + Page int `json:"page"`
  107 + Size int `json:"size"`
100 CompanyId int64 `json:",optional"` 108 CompanyId int64 `json:",optional"`
101 - SectionId int64 `json:"sectionId"` 109 + UserId int64 `json:",optional"`
  110 + ArticleId int64 `json:"articleId"`
  111 + SectionId int64 `json:"sectionId,optional"`
102 } 112 }
103 MiniListArticleCommentResponse { 113 MiniListArticleCommentResponse {
104 Total int64 `json:"total"` 114 Total int64 `json:"total"`
@@ -154,3 +164,29 @@ type ( @@ -154,3 +164,29 @@ type (
154 Id int64 `json:"id"` 164 Id int64 `json:"id"`
155 } 165 }
156 ) 166 )
  167 +
  168 +// 热门前5的评论列表
  169 +type (
  170 + MiniTop5ArticleCommentRequest {
  171 + CompanyId int64 `json:",optional"`
  172 + UserId int64 `json:",optional"`
  173 + ArticleId int64 `json:"articleId"`
  174 + }
  175 +
  176 + MiniTop5ArticleCommentResponse {
  177 + List []ArticleCommentItem `json:"list"`
  178 + }
  179 +)
  180 +
  181 +// 填写评论时选择@人
  182 +type (
  183 + MiniArticleCommentAtWhoRequest {
  184 + CompanyId int64 `json:",optional"`
  185 + UserId int64 `json:",optional"`
  186 + ArticleId int64 `json:"articleId"`
  187 + }
  188 +
  189 + MiniArticleCommentAtWhoResponse {
  190 + List []CommentAtWho `json:"list"`
  191 + }
  192 +)
@@ -30,6 +30,10 @@ service Core { @@ -30,6 +30,10 @@ service Core {
30 @doc "部门-更新" 30 @doc "部门-更新"
31 @handler systemUpdate 31 @handler systemUpdate
32 put /system/department/:id (DepartmentUpdateRequest) returns (DepartmentGetResponse) 32 put /system/department/:id (DepartmentUpdateRequest) returns (DepartmentGetResponse)
  33 +
  34 + @doc "部门-删除"
  35 + @handler systemDelete
  36 + delete /system/department/:id (DepartmentGetRequest) returns (DepartmentGetResponse)
33 } 37 }
34 38
35 type ( 39 type (
  1 +package article
  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/article"
  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 +)
  11 +
  12 +func MiniAllArticleTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.MiniAllArticleTagRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := article.NewMiniAllArticleTagLogic(r.Context(), svcCtx)
  21 + resp, err := l.MiniAllArticleTag(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
  1 +package article
  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/article"
  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 +)
  11 +
  12 +func MiniArticleSetTagHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.MiniArticleSetTagRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := article.NewMiniArticleSetTagLogic(r.Context(), svcCtx)
  21 + resp, err := l.MiniArticleSetTag(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  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 +)
  11 +
  12 +func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  13 + return func(w http.ResponseWriter, r *http.Request) {
  14 + var req types.MiniArticleCommentAtWhoRequest
  15 + if err := httpx.Parse(r, &req); err != nil {
  16 + httpx.ErrorCtx(r.Context(), w, err)
  17 + return
  18 + }
  19 +
  20 + l := comment.NewMiniArticleCommentAtWhoLogic(r.Context(), svcCtx)
  21 + resp, err := l.MiniArticleCommentAtWho(&req)
  22 + if err != nil {
  23 + httpx.ErrorCtx(r.Context(), w, err)
  24 + } else {
  25 + httpx.OkJsonCtx(r.Context(), w, resp)
  26 + }
  27 + }
  28 +}
@@ -22,6 +22,7 @@ func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -22,6 +22,7 @@ func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
22 l := comment.NewMiniGetArticleCommentLogic(r.Context(), svcCtx) 22 l := comment.NewMiniGetArticleCommentLogic(r.Context(), svcCtx)
23 token := contextdata.GetUserTokenFromCtx(r.Context()) 23 token := contextdata.GetUserTokenFromCtx(r.Context())
24 req.CompanyId = token.CompanyId 24 req.CompanyId = token.CompanyId
  25 + req.UserId = token.UserId
25 resp, err := l.MiniGetArticleComment(&req) 26 resp, err := l.MiniGetArticleComment(&req)
26 result.HttpResult(r, w, resp, err) 27 result.HttpResult(r, w, resp, err)
27 } 28 }
@@ -21,6 +21,7 @@ func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -21,6 +21,7 @@ func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
21 l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx) 21 l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx)
22 token := contextdata.GetUserTokenFromCtx(r.Context()) 22 token := contextdata.GetUserTokenFromCtx(r.Context())
23 req.CompanyId = token.CompanyId 23 req.CompanyId = token.CompanyId
  24 + req.UserId = token.UserId
24 resp, err := l.MiniListArticleComment(&req) 25 resp, err := l.MiniListArticleComment(&req)
25 result.HttpResult(r, w, resp, err) 26 result.HttpResult(r, w, resp, err)
26 } 27 }
  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 MiniTop5ArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  15 + return func(w http.ResponseWriter, r *http.Request) {
  16 + var req types.MiniTop5ArticleCommentRequest
  17 + if err := httpx.Parse(r, &req); err != nil {
  18 + httpx.ErrorCtx(r.Context(), w, err)
  19 + return
  20 + }
  21 +
  22 + l := comment.NewMiniTop5ArticleCommentLogic(r.Context(), svcCtx)
  23 + token := contextdata.GetUserTokenFromCtx(r.Context())
  24 + req.CompanyId = token.CompanyId
  25 + req.UserId = token.UserId
  26 + resp, err := l.MiniTop5ArticleComment(&req)
  27 + result.HttpResult(r, w, resp, err)
  28 + }
  29 +}
  1 +package department
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  5 + "net/http"
  6 +
  7 + "github.com/zeromicro/go-zero/rest/httpx"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/department"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  11 +)
  12 +
  13 +func SystemDeleteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.DepartmentGetRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := department.NewSystemDeleteLogic(r.Context(), svcCtx)
  22 + resp, err := l.SystemDelete(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
@@ -36,6 +36,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -36,6 +36,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
36 Handler: comment.MiniListArticleCommentHandler(serverCtx), 36 Handler: comment.MiniListArticleCommentHandler(serverCtx),
37 }, 37 },
38 { 38 {
  39 + Method: http.MethodPost,
  40 + Path: "/article_comment/top5",
  41 + Handler: comment.MiniTop5ArticleCommentHandler(serverCtx),
  42 + },
  43 + {
39 Method: http.MethodGet, 44 Method: http.MethodGet,
40 Path: "/article_comment/:id", 45 Path: "/article_comment/:id",
41 Handler: comment.MiniGetArticleCommentHandler(serverCtx), 46 Handler: comment.MiniGetArticleCommentHandler(serverCtx),
@@ -45,6 +50,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -45,6 +50,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
45 Path: "/article_comment/:id", 50 Path: "/article_comment/:id",
46 Handler: comment.MiniDeleteArticleCommentHandler(serverCtx), 51 Handler: comment.MiniDeleteArticleCommentHandler(serverCtx),
47 }, 52 },
  53 + {
  54 + Method: http.MethodPost,
  55 + Path: "/article_comment/at_who/list",
  56 + Handler: comment.MiniArticleCommentAtWhoHandler(serverCtx),
  57 + },
48 }, 58 },
49 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 59 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
50 rest.WithPrefix("/v1/mini"), 60 rest.WithPrefix("/v1/mini"),
@@ -334,6 +344,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -334,6 +344,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
334 Path: "/article_backup/search", 344 Path: "/article_backup/search",
335 Handler: article.MiniArticleBackupSearchHandler(serverCtx), 345 Handler: article.MiniArticleBackupSearchHandler(serverCtx),
336 }, 346 },
  347 + {
  348 + Method: http.MethodPost,
  349 + Path: "/article/set_tag",
  350 + Handler: article.MiniArticleSetTagHandler(serverCtx),
  351 + },
  352 + {
  353 + Method: http.MethodGet,
  354 + Path: "/article_tag/list/all",
  355 + Handler: article.MiniAllArticleTagHandler(serverCtx),
  356 + },
337 }, 357 },
338 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 358 rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
339 rest.WithPrefix("/v1/mini"), 359 rest.WithPrefix("/v1/mini"),
@@ -415,6 +435,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -415,6 +435,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
415 Path: "/system/department/:id", 435 Path: "/system/department/:id",
416 Handler: department.SystemUpdateHandler(serverCtx), 436 Handler: department.SystemUpdateHandler(serverCtx),
417 }, 437 },
  438 + {
  439 + Method: http.MethodDelete,
  440 + Path: "/system/department/:id",
  441 + Handler: department.SystemDeleteHandler(serverCtx),
  442 + },
418 }..., 443 }...,
419 ), 444 ),
420 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret), 445 rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
  1 +package article
  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 MiniAllArticleTagLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewMiniAllArticleTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniAllArticleTagLogic {
  19 + return &MiniAllArticleTagLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagRequest) (resp *types.MiniAllArticleTagResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
  1 +package article
  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 MiniArticleSetTagLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewMiniArticleSetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleSetTagLogic {
  19 + return &MiniArticleSetTagLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagRequest) (resp *types.MiniArticleSetTagResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
@@ -2,6 +2,7 @@ package article @@ -2,6 +2,7 @@ package article
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "text/template"
5 6
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/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -29,6 +30,10 @@ func NewMiniCreateArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceCont @@ -29,6 +30,10 @@ func NewMiniCreateArticleDraftLogic(ctx context.Context, svcCtx *svc.ServiceCont
29 func (l *MiniCreateArticleDraftLogic) MiniCreateArticleDraft(req *types.MiniArticleDraftCreateRequest) (resp *types.MiniArticleDraftCreateResponse, err error) { 30 func (l *MiniCreateArticleDraftLogic) MiniCreateArticleDraft(req *types.MiniArticleDraftCreateRequest) (resp *types.MiniArticleDraftCreateResponse, err error) {
30 var conn = l.svcCtx.DefaultDBConn() 31 var conn = l.svcCtx.DefaultDBConn()
31 32
  33 + for i := range req.Section {
  34 + req.Section[i] = template.HTMLEscapeString(req.Section[i])
  35 + }
  36 +
32 newDraft := domain.ArticleDraft{ 37 newDraft := domain.ArticleDraft{
33 Id: 0, 38 Id: 0,
34 CompanyId: req.CompanyId, 39 CompanyId: req.CompanyId,
@@ -3,6 +3,7 @@ package article @@ -3,6 +3,7 @@ package article
3 import ( 3 import (
4 "context" 4 "context"
5 "strings" 5 "strings"
  6 + "text/template"
6 7
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -124,6 +125,8 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR @@ -124,6 +125,8 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
124 if len(newStr) == 0 { 125 if len(newStr) == 0 {
125 continue 126 continue
126 } 127 }
  128 + newStr = template.HTMLEscapeString(newStr)
  129 +
127 newSection := domain.ArticleSection{ 130 newSection := domain.ArticleSection{
128 Id: 0, 131 Id: 0,
129 CompanyId: author.CompanyId, 132 CompanyId: author.CompanyId,
@@ -2,6 +2,7 @@ package article @@ -2,6 +2,7 @@ package article
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "text/template"
5 6
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/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -37,6 +38,10 @@ func (l *MiniUpdateArticleDraftLogic) MiniUpdateArticleDraft(req *types.MiniArti @@ -37,6 +38,10 @@ func (l *MiniUpdateArticleDraftLogic) MiniUpdateArticleDraft(req *types.MiniArti
37 return nil, xerr.NewErrMsg("更新草稿失败") 38 return nil, xerr.NewErrMsg("更新草稿失败")
38 } 39 }
39 } 40 }
  41 + for i := range req.Section {
  42 + req.Section[i] = template.HTMLEscapeString(req.Section[i])
  43 + }
  44 +
40 draftInfo.Content = req.Section 45 draftInfo.Content = req.Section
41 draftInfo.Title = req.Title 46 draftInfo.Title = req.Title
42 draftInfo.Location = domain.Location{ 47 draftInfo.Location = domain.Location{
  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 MiniArticleCommentAtWhoLogic struct {
  13 + logx.Logger
  14 + ctx context.Context
  15 + svcCtx *svc.ServiceContext
  16 +}
  17 +
  18 +func NewMiniArticleCommentAtWhoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniArticleCommentAtWhoLogic {
  19 + return &MiniArticleCommentAtWhoLogic{
  20 + Logger: logx.WithContext(ctx),
  21 + ctx: ctx,
  22 + svcCtx: svcCtx,
  23 + }
  24 +}
  25 +
  26 +func (l *MiniArticleCommentAtWhoLogic) MiniArticleCommentAtWho(req *types.MiniArticleCommentAtWhoRequest) (resp *types.MiniArticleCommentAtWhoResponse, err error) {
  27 + // todo: add your logic here and delete this line
  28 +
  29 + return
  30 +}
@@ -2,6 +2,7 @@ package comment @@ -2,6 +2,7 @@ package comment
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
5 6
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/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
@@ -49,7 +50,6 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -49,7 +50,6 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
49 return nil, xerr.NewErrMsg("没有评论权限") 50 return nil, xerr.NewErrMsg("没有评论权限")
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 {
@@ -83,12 +83,12 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -83,12 +83,12 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
83 } 83 }
84 } 84 }
85 var atWhoList []*domain.User 85 var atWhoList []*domain.User
  86 + var atWhoIds = make([]int64, 0)
86 if len(req.AtWho) > 0 { 87 if len(req.AtWho) > 0 {
87 - uids := []int64{}  
88 for _, val := range req.AtWho { 88 for _, val := range req.AtWho {
89 - uids = append(uids, val.Id) 89 + atWhoIds = append(atWhoIds, val.Id)
90 } 90 }
91 - queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", uids) 91 + queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", atWhoIds)
92 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption) 92 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
93 if err != nil { 93 if err != nil {
94 return nil, xerr.NewErrMsgErr("检查@的人员失败", err) 94 return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
@@ -152,11 +152,23 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -152,11 +152,23 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
152 } 152 }
153 //保存数据 153 //保存数据
154 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 {
  155 + //保存评论
  156 + _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment)
  157 + if err != nil {
  158 + return err
  159 + }
155 // 增加文章评论计数 160 // 增加文章评论计数
156 err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo.Id) 161 err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo.Id)
157 if err != nil { 162 if err != nil {
158 return err 163 return err
159 } 164 }
  165 + //增加段落评论计数
  166 + if newComment.SectionId > 0 {
  167 + err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, 1, newComment.SectionId)
  168 + if err != nil {
  169 + return err
  170 + }
  171 + }
160 //增加评论回复计数 172 //增加评论回复计数
161 if pComment != nil { 173 if pComment != nil {
162 err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment.Id) 174 err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment.Id)
@@ -171,11 +183,21 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -171,11 +183,21 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
171 return err 183 return err
172 } 184 }
173 } 185 }
174 - //保存评论  
175 - _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) 186 +
  187 + // 创建回复消息
  188 + var atAllIds = make([]int64, 0)
  189 + atAllIds = append(atAllIds, newComment.ToUserId)
  190 + atAllIds = append(atAllIds, atWhoIds...)
  191 + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
  192 + if pComment != nil {
  193 + err = messageLogic.CommentReply(c, pComment.ArticleId, pComment.SectionId, pComment.Id, req.Content, atAllIds) // 对评论回复
  194 + } else {
  195 + err = messageLogic.CommentArticle(c, req.ArtitcleId, req.SectionId, req.Content, atAllIds) // 对文章回复
  196 + }
176 if err != nil { 197 if err != nil {
177 return err 198 return err
178 } 199 }
  200 +
179 return nil 201 return nil
180 }, true) 202 }, true)
181 203
@@ -60,6 +60,18 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini @@ -60,6 +60,18 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini
60 return err 60 return err
61 } 61 }
62 } 62 }
  63 + //减少加段落评论计数
  64 + if commetInfo.SectionId > 0 {
  65 + err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId)
  66 + if err != nil {
  67 + return err
  68 + }
  69 + }
  70 + // 减少文章的评论数
  71 + err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId)
  72 + if err != nil {
  73 + return err
  74 + }
63 return nil 75 return nil
64 }, true) 76 }, true)
65 77
@@ -5,6 +5,8 @@ import ( @@ -5,6 +5,8 @@ import (
5 5
6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" 7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
8 10
9 "github.com/zeromicro/go-zero/core/logx" 11 "github.com/zeromicro/go-zero/core/logx"
10 ) 12 )
@@ -24,7 +26,166 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont @@ -24,7 +26,166 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont
24 } 26 }
25 27
26 func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) { 28 func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
27 - // todo: add your logic here and delete this line 29 + // 先获取最顶层的评论
  30 + var conn = l.svcCtx.DefaultDBConn()
  31 + if req.Page > 40 {
  32 + req.Page = 40
  33 + }
  34 +
  35 + queryOption := domain.NewQueryOptions().
  36 + WithOffsetLimit(req.Page, req.Size).
  37 + MustWithKV("topId", 0).
  38 + MustWithKV("articleId", req.ArticleId).
  39 + MustWithKV("sectionId", req.SectionId).
  40 + MustWithKV("show", domain.CommentShowEnable).
  41 + MustWithKV("companyId", req.CompanyId)
28 42
  43 + cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
  44 + if err != nil {
  45 + return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
  46 + }
  47 + if cnt == 0 {
  48 + resp = &types.MiniListArticleCommentResponse{
  49 + Total: 0,
  50 + List: make([]types.ArticleCommentAndReply, 0),
  51 + }
29 return 52 return
  53 + }
  54 +
  55 + queryOption = domain.NewQueryOptions().WithFindOnly().
  56 + MustWithKV("articleId", req.ArticleId).
  57 + MustWithKV("userId", req.UserId)
  58 + // 获取我点赞的评论
  59 + _, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
  60 + if err != nil {
  61 + return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
  62 + }
  63 + // 我点赞的
  64 + flagMap := map[int64]struct{}{}
  65 + for _, val := range userFlagList {
  66 + flagMap[val.CommentId] = struct{}{}
  67 + }
  68 + resp = &types.MiniListArticleCommentResponse{
  69 + Total: cnt,
  70 + List: make([]types.ArticleCommentAndReply, len(commentList)),
  71 + }
  72 + // 获取回复的评论
  73 + for i, val := range commentList {
  74 + item := types.ArticleCommentAndReply{
  75 + Comment: types.ArticleCommentItem{
  76 + Id: val.Id,
  77 + Pid: val.Pid,
  78 + TopId: val.TopId,
  79 + ArtitcleId: val.ArticleId,
  80 + SectionId: val.SectionId,
  81 + FromUserId: val.FromUserId,
  82 + FromUser: types.CommentAuthor{
  83 + Id: val.FromUser.Id,
  84 + Name: val.FromUser.Name,
  85 + Avatar: val.FromUser.Avatar,
  86 + Position: val.FromUser.Position,
  87 + Company: val.FromUser.Company,
  88 + },
  89 + ToUserId: val.ToUserId,
  90 + ToUser: types.CommentAuthor{
  91 + Id: val.ToUser.Id,
  92 + Name: val.ToUser.Name,
  93 + Avatar: val.ToUser.Avatar,
  94 + Position: val.ToUser.Position,
  95 + Company: val.ToUser.Company,
  96 + },
  97 + SectionContent: val.SectionContent,
  98 + CountReply: val.CountReply,
  99 + CountUserLove: val.CountUserLove,
  100 + CountAdminLove: val.CountAdminLove,
  101 + AtWho: []types.CommentAtWho{},
  102 + CreatedAt: val.CreatedAt,
  103 + MeLoveFlag: 0,
  104 + },
  105 + Reply: []types.ArticleCommentItem{},
  106 + TotalReply: int64(val.CountReply),
  107 + }
  108 +
  109 + if _, ok := flagMap[val.Id]; ok {
  110 + item.Comment.MeLoveFlag = 1
  111 + }
  112 +
  113 + for _, val2 := range val.AtWho {
  114 + item.Comment.AtWho = append(item.Comment.AtWho, types.CommentAtWho{
  115 + Id: val2.Id,
  116 + Name: val2.Name,
  117 + })
  118 + }
  119 +
  120 + //获取回复的评论
  121 + cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap)
  122 +
  123 + resp.List[i] = item
  124 + resp.List[i].Reply = reply
  125 + resp.List[i].TotalReply = cntReply
  126 + }
  127 + return resp, nil
  128 +}
  129 +
  130 +// listCommentReply
  131 +func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
  132 + var conn = l.svcCtx.DefaultDBConn()
  133 + queryOption := domain.NewQueryOptions().
  134 + WithOffsetLimit(1, 2).
  135 + MustWithKV("topId", commentId).
  136 + MustWithKV("show", domain.CommentShowEnable)
  137 +
  138 + cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
  139 + if err != nil {
  140 + return cnt, []types.ArticleCommentItem{}
  141 + }
  142 + if cnt == 0 {
  143 + replyList = []types.ArticleCommentItem{}
  144 + return cnt, replyList
  145 + }
  146 +
  147 + for _, val := range commentList {
  148 + item := types.ArticleCommentItem{
  149 + Id: val.Id,
  150 + Pid: val.Pid,
  151 + TopId: val.TopId,
  152 + ArtitcleId: val.ArticleId,
  153 + SectionId: val.SectionId,
  154 + FromUserId: val.FromUserId,
  155 + FromUser: types.CommentAuthor{
  156 + Id: val.FromUser.Id,
  157 + Name: val.FromUser.Name,
  158 + Avatar: val.FromUser.Avatar,
  159 + Position: val.FromUser.Position,
  160 + Company: val.FromUser.Company,
  161 + },
  162 + ToUserId: val.ToUserId,
  163 + ToUser: types.CommentAuthor{
  164 + Id: val.ToUser.Id,
  165 + Name: val.ToUser.Name,
  166 + Avatar: val.ToUser.Avatar,
  167 + Position: val.ToUser.Position,
  168 + Company: val.ToUser.Company,
  169 + },
  170 + SectionContent: val.SectionContent,
  171 + CountReply: val.CountReply,
  172 + CountUserLove: val.CountUserLove,
  173 + CountAdminLove: val.CountAdminLove,
  174 + AtWho: []types.CommentAtWho{},
  175 + CreatedAt: val.CreatedAt,
  176 + MeLoveFlag: 0,
  177 + }
  178 +
  179 + if _, ok := loveFlagMap[val.Id]; ok {
  180 + item.MeLoveFlag = 1
  181 + }
  182 + for _, val2 := range val.AtWho {
  183 + item.AtWho = append(item.AtWho, types.CommentAtWho{
  184 + Id: val2.Id,
  185 + Name: val2.Name,
  186 + })
  187 + }
  188 + replyList = append(replyList, item)
  189 + }
  190 + return cnt, replyList
30 } 191 }
  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 MiniTop5ArticleCommentLogic struct {
  15 + logx.Logger
  16 + ctx context.Context
  17 + svcCtx *svc.ServiceContext
  18 +}
  19 +
  20 +func NewMiniTop5ArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniTop5ArticleCommentLogic {
  21 + return &MiniTop5ArticleCommentLogic{
  22 + Logger: logx.WithContext(ctx),
  23 + ctx: ctx,
  24 + svcCtx: svcCtx,
  25 + }
  26 +}
  27 +
  28 +// 获取前5的评论
  29 +func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5ArticleCommentRequest) (resp *types.MiniTop5ArticleCommentResponse, err error) {
  30 + var conn = l.svcCtx.DefaultDBConn()
  31 + commentList, err := l.svcCtx.ArticleCommentRepository.Top5Comment(l.ctx, conn, req.CompanyId, req.ArticleId)
  32 + if err != nil {
  33 + return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
  34 + }
  35 +
  36 + queryOption := domain.NewQueryOptions().WithFindOnly().
  37 + MustWithKV("articleId", req.ArticleId).
  38 + MustWithKV("userId", req.UserId)
  39 + // 获取我点赞的评论
  40 + _, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
  41 + if err != nil {
  42 + return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
  43 + }
  44 + // 我点赞的
  45 + flagMap := map[int64]struct{}{}
  46 + for _, val := range userFlagList {
  47 + flagMap[val.CommentId] = struct{}{}
  48 + }
  49 +
  50 + resp = &types.MiniTop5ArticleCommentResponse{
  51 + List: make([]types.ArticleCommentItem, len(commentList)),
  52 + }
  53 + for i, val := range commentList {
  54 + item := types.ArticleCommentItem{
  55 + Id: val.Id,
  56 + Pid: val.Pid,
  57 + TopId: val.TopId,
  58 + ArtitcleId: val.ArticleId,
  59 + SectionId: val.SectionId,
  60 + FromUserId: val.FromUserId,
  61 + FromUser: types.CommentAuthor{
  62 + Id: val.FromUser.Id,
  63 + Name: val.FromUser.Name,
  64 + Avatar: val.FromUser.Avatar,
  65 + Position: val.FromUser.Position,
  66 + Company: val.FromUser.Company,
  67 + },
  68 + ToUserId: val.ToUserId,
  69 + ToUser: types.CommentAuthor{
  70 + Id: val.ToUser.Id,
  71 + Name: val.ToUser.Name,
  72 + Avatar: val.ToUser.Avatar,
  73 + Position: val.ToUser.Position,
  74 + Company: val.ToUser.Company,
  75 + },
  76 + SectionContent: val.SectionContent,
  77 + CountReply: val.CountReply,
  78 + CountUserLove: val.CountUserLove,
  79 + CountAdminLove: val.CountAdminLove,
  80 + AtWho: []types.CommentAtWho{},
  81 + CreatedAt: val.CreatedAt,
  82 + MeLoveFlag: 0,
  83 + }
  84 +
  85 + if _, ok := flagMap[val.Id]; ok {
  86 + item.MeLoveFlag = 1
  87 + }
  88 + for _, val2 := range val.AtWho {
  89 + item.AtWho = append(item.AtWho, types.CommentAtWho{
  90 + Id: val2.Id,
  91 + Name: val2.Name,
  92 + })
  93 + }
  94 + resp.List[i] = item
  95 + }
  96 + return
  97 +}
@@ -48,7 +48,7 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types @@ -48,7 +48,7 @@ func (l *SystemAddLogic) SystemAdd(req *types.DepartmentAddRequest) (resp *types
48 CompanyId: userToken.CompanyId, 48 CompanyId: userToken.CompanyId,
49 Name: req.Name, 49 Name: req.Name,
50 } 50 }
51 - err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { 51 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
52 _, err = l.svcCtx.DepartmentRepository.Insert(l.ctx, conn, insert) 52 _, err = l.svcCtx.DepartmentRepository.Insert(l.ctx, conn, insert)
53 if err != nil { 53 if err != nil {
54 return err 54 return err
  1 +package department
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  8 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  9 +
  10 + "github.com/zeromicro/go-zero/core/logx"
  11 +)
  12 +
  13 +type SystemDeleteLogic struct {
  14 + logx.Logger
  15 + ctx context.Context
  16 + svcCtx *svc.ServiceContext
  17 +}
  18 +
  19 +func NewSystemDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemDeleteLogic {
  20 + return &SystemDeleteLogic{
  21 + Logger: logx.WithContext(ctx),
  22 + ctx: ctx,
  23 + svcCtx: svcCtx,
  24 + }
  25 +}
  26 +
  27 +func (l *SystemDeleteLogic) SystemDelete(req *types.DepartmentGetRequest) (resp *types.DepartmentGetResponse, err error) {
  28 + var conn = l.svcCtx.DefaultDBConn()
  29 +
  30 + one, err := l.svcCtx.DepartmentRepository.FindOne(l.ctx, conn, req.Id)
  31 + if err != nil {
  32 + return nil, err
  33 + }
  34 +
  35 + // 获取公司下的所有用户
  36 + _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
  37 + WithFindOnly().
  38 + WithKV(" companyId", one.CompanyId))
  39 + if err != nil {
  40 + return nil, err
  41 + }
  42 +
  43 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
  44 + _, err = l.svcCtx.DepartmentRepository.Delete(l.ctx, conn, one)
  45 + if err != nil {
  46 + return err
  47 + }
  48 +
  49 + // 移除用户中关联的分组
  50 + if len(users) > 0 {
  51 + var findIndex = func(ids []int64, id int64) int {
  52 + for i, _ := range ids {
  53 + if ids[i] == id {
  54 + return i
  55 + }
  56 + }
  57 + return -1
  58 + }
  59 + for i := range users {
  60 + user := users[i]
  61 + var targetIndex = findIndex(user.Departments, req.Id)
  62 + if targetIndex != -1 { // 归属分组存在,则移除
  63 + user.Departments = append(user.Departments[:targetIndex], user.Departments[targetIndex+1:]...) // 移除分组ID
  64 + _, err = l.svcCtx.UserRepository.UpdateWithVersion(l.ctx, conn, user)
  65 + if err != nil {
  66 + return err
  67 + }
  68 + }
  69 + }
  70 + }
  71 + return nil
  72 + }, true)
  73 +
  74 + return
  75 +}
@@ -55,18 +55,18 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re @@ -55,18 +55,18 @@ func (l *SystemUpdateLogic) SystemUpdate(req *types.DepartmentUpdateRequest) (re
55 newIdMap[req.Ids[i]] = 0 55 newIdMap[req.Ids[i]] = 0
56 } 56 }
57 57
58 - // 更新  
59 - err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {  
60 - _, err = l.svcCtx.DepartmentRepository.UpdateWithVersion(l.ctx, conn, one)  
61 - if err != nil {  
62 - return err  
63 - }  
64 -  
65 // 获取公司下的所有用户 58 // 获取公司下的所有用户
66 _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions(). 59 _, users, err := l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().
67 WithFindOnly(). 60 WithFindOnly().
68 WithKV(" companyId", one.CompanyId)) 61 WithKV(" companyId", one.CompanyId))
69 if err != nil { 62 if err != nil {
  63 + return nil, err
  64 + }
  65 +
  66 + // 更新
  67 + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, conn transaction.Conn) error {
  68 + _, err = l.svcCtx.DepartmentRepository.UpdateWithVersion(l.ctx, conn, one)
  69 + if err != nil {
70 return err 70 return err
71 } 71 }
72 72
@@ -207,23 +207,23 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res @@ -207,23 +207,23 @@ func (l *MiniBusinessLogic) MiniBusiness(req *types.MessageBusinessRequest) (res
207 } 207 }
208 208
209 // CommentArticle 评论文章 209 // CommentArticle 评论文章
210 -func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, content string, at []int64) (err error) {  
211 - return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, 0, content, at) 210 +func (l *MiniBusinessLogic) CommentArticle(conn transaction.Conn, articleId int64, sectionId int64, content string, at []int64) (err error) {
  211 + return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeArticle, articleId, sectionId, 0, content, at)
212 } 212 }
213 213
214 // CommentReply 评论回复 214 // CommentReply 评论回复
215 -func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, commentId int64, content string, at []int64) (err error) {  
216 - return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, commentId, content, at) 215 +func (l *MiniBusinessLogic) CommentReply(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, content string, at []int64) (err error) {
  216 + return l.createMessage(conn, domain.MsgTypeReply, domain.OptTypeComment, articleId, sectionId, commentId, content, at)
217 } 217 }
218 218
219 // LikeArticle 点赞文章 219 // LikeArticle 点赞文章
220 func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) { 220 func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, at int64) (err error) {
221 - return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, "", []int64{at}) 221 + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeArticle, articleId, 0, 0, "", []int64{at})
222 } 222 }
223 223
224 // LikeComment 点赞评论 224 // LikeComment 点赞评论
225 -func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, commentId int64, at int64) (err error) {  
226 - return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, commentId, "", []int64{at}) 225 +func (l *MiniBusinessLogic) LikeComment(conn transaction.Conn, articleId int64, sectionId int64, commentId int64, at int64) (err error) {
  226 + return l.createMessage(conn, domain.MsgTypeLike, domain.OptTypeComment, articleId, sectionId, commentId, "", []int64{at})
227 } 227 }
228 228
229 func (l *MiniBusinessLogic) createMessage( 229 func (l *MiniBusinessLogic) createMessage(
@@ -231,6 +231,7 @@ func (l *MiniBusinessLogic) createMessage( @@ -231,6 +231,7 @@ func (l *MiniBusinessLogic) createMessage(
231 msgType domain.MsgBusinessType, 231 msgType domain.MsgBusinessType,
232 optType domain.MsgBusinessOpt, 232 optType domain.MsgBusinessOpt,
233 articleId int64, 233 articleId int64,
  234 + sectionId int64,
234 commentId int64, 235 commentId int64,
235 content string, 236 content string,
236 at []int64) (err error) { 237 at []int64) (err error) {
@@ -245,6 +246,7 @@ func (l *MiniBusinessLogic) createMessage( @@ -245,6 +246,7 @@ func (l *MiniBusinessLogic) createMessage(
245 UserId: userToken.UserId, 246 UserId: userToken.UserId,
246 RecipientId: at[i], 247 RecipientId: at[i],
247 ArticleId: articleId, 248 ArticleId: articleId,
  249 + SectionId: sectionId,
248 CommentId: commentId, 250 CommentId: commentId,
249 Content: content, 251 Content: content,
250 } 252 }
@@ -50,10 +50,12 @@ type MiniCreateArticleCommentResponse struct { @@ -50,10 +50,12 @@ type MiniCreateArticleCommentResponse struct {
50 } 50 }
51 51
52 type MiniListArticleCommentRequest struct { 52 type MiniListArticleCommentRequest struct {
53 - Page int64 `json:"page"`  
54 - Size int64 `json:"size"` 53 + Page int `json:"page"`
  54 + Size int `json:"size"`
55 CompanyId int64 `json:",optional"` 55 CompanyId int64 `json:",optional"`
56 - SectionId int64 `json:"sectionId"` 56 + UserId int64 `json:",optional"`
  57 + ArticleId int64 `json:"articleId"`
  58 + SectionId int64 `json:"sectionId,optional"`
57 } 59 }
58 60
59 type MiniListArticleCommentResponse struct { 61 type MiniListArticleCommentResponse struct {
@@ -106,6 +108,26 @@ type MiniDeleteArticleCommentResponse struct { @@ -106,6 +108,26 @@ type MiniDeleteArticleCommentResponse struct {
106 Id int64 `json:"id"` 108 Id int64 `json:"id"`
107 } 109 }
108 110
  111 +type MiniTop5ArticleCommentRequest struct {
  112 + CompanyId int64 `json:",optional"`
  113 + UserId int64 `json:",optional"`
  114 + ArticleId int64 `json:"articleId"`
  115 +}
  116 +
  117 +type MiniTop5ArticleCommentResponse struct {
  118 + List []ArticleCommentItem `json:"list"`
  119 +}
  120 +
  121 +type MiniArticleCommentAtWhoRequest struct {
  122 + CompanyId int64 `json:",optional"`
  123 + UserId int64 `json:",optional"`
  124 + ArticleId int64 `json:"articleId"`
  125 +}
  126 +
  127 +type MiniArticleCommentAtWhoResponse struct {
  128 + List []CommentAtWho `json:"list"`
  129 +}
  130 +
109 type MessageSystemRequest struct { 131 type MessageSystemRequest struct {
110 Page int `json:"page"` 132 Page int `json:"page"`
111 Size int `json:"size"` 133 Size int `json:"size"`
@@ -782,6 +804,35 @@ type MiniArticleMarkItem struct { @@ -782,6 +804,35 @@ type MiniArticleMarkItem struct {
782 UpdatedAt int64 `json:"updatedAt"` 804 UpdatedAt int64 `json:"updatedAt"`
783 } 805 }
784 806
  807 +type MiniArticleSetTagRequest struct {
  808 + CompanyId int64 `json:",optional"` // 公司id
  809 + UserId int64 `json:",optional"` // 公司id
  810 + ArticleId int64 `json:"articleId"` // 文章id
  811 + TagId int64 `json:"tagId"` // 标签id
  812 +}
  813 +
  814 +type MiniArticleSetTagResponse struct {
  815 + Id int64 `json:"id"`
  816 +}
  817 +
  818 +type MiniAllArticleTagRequest struct {
  819 + CompanyId int64 `json:",optional"` // 公司id
  820 + UserId int64 `json:",optional"` // 公司id
  821 + ArticleId int64 `json:"articleId"` // 文章id
  822 + TagId int64 `json:"tagId"` // 标签id
  823 +}
  824 +
  825 +type MiniAllArticleTagResponse struct {
  826 + TagGroup []string `json:"tagGroup"`
  827 + Tags []ArticleTagItem `json:"tags"`
  828 +}
  829 +
  830 +type ArticleTagItem struct {
  831 + Id int64 `json:"id"`
  832 + Group string `json:"group"`
  833 + Name string `json:"name"`
  834 +}
  835 +
785 type SystemArticleGetRequest struct { 836 type SystemArticleGetRequest struct {
786 Id int64 `path:"id"` //id 837 Id int64 `path:"id"` //id
787 CompanyId int64 `path:",optional"` 838 CompanyId int64 `path:",optional"`
  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  8 + "gorm.io/gorm"
  9 +)
  10 +
  11 +type ArticleAndTag struct {
  12 + Id int64 // 唯一标识
  13 + CompanyId int64 `json:"companyId"`
  14 + CreatedAt int64 `json:"createdAt,omitempty"`
  15 + UpdatedAt int64 `json:"updatedAt,omitempty"`
  16 + ArticleId int64 `json:"articleId"`
  17 + TagId int64 `json:"tagId"`
  18 +}
  19 +
  20 +func (m *ArticleAndTag) TableName() string {
  21 + return "article_and_tag"
  22 +}
  23 +
  24 +func (m *ArticleAndTag) BeforeCreate(tx *gorm.DB) (err error) {
  25 + m.CreatedAt = time.Now().Unix()
  26 + m.UpdatedAt = time.Now().Unix()
  27 + return
  28 +}
  29 +
  30 +func (m *ArticleAndTag) BeforeUpdate(tx *gorm.DB) (err error) {
  31 + // m.UpdatedAt = time.Now().Unix()
  32 + return
  33 +}
  34 +
  35 +func (m *ArticleAndTag) CacheKeyFunc() string {
  36 + if m.Id == 0 {
  37 + return ""
  38 + }
  39 + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
  40 +}
  41 +
  42 +func (m *ArticleAndTag) CacheKeyFuncByObject(obj interface{}) string {
  43 + if v, ok := obj.(*ArticleAndTag); ok {
  44 + return v.CacheKeyFunc()
  45 + }
  46 + return ""
  47 +}
  48 +
  49 +func (m *ArticleAndTag) CachePrimaryKeyFunc() string {
  50 + if len("") == 0 {
  51 + return ""
  52 + }
  53 + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
  54 +}
@@ -17,6 +17,7 @@ type MessageBusiness struct { @@ -17,6 +17,7 @@ type MessageBusiness struct {
17 UserId int64 `json:"userId"` // 操作人用户ID 17 UserId int64 `json:"userId"` // 操作人用户ID
18 RecipientId int64 `json:"recipientId"` // 接收人用户ID 18 RecipientId int64 `json:"recipientId"` // 接收人用户ID
19 ArticleId int64 `json:"articleId,omitempty"` // 文章ID 19 ArticleId int64 `json:"articleId,omitempty"` // 文章ID
  20 + SectionId int64 `json:"sectionId,omitempty"` // 段落ID
20 CommentId int64 `json:"commentId,omitempty"` // 评论ID 21 CommentId int64 `json:"commentId,omitempty"` // 评论ID
21 Content string `json:"content,omitempty"` // 消息内容 22 Content string `json:"content,omitempty"` // 消息内容
22 CreatedAt int64 `json:",omitempty"` 23 CreatedAt int64 `json:",omitempty"`
  1 +package repository
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "github.com/jinzhu/copier"
  7 + "github.com/pkg/errors"
  8 + "github.com/tiptok/gocomm/pkg/cache"
  9 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models"
  10 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  11 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  12 + "gorm.io/gorm"
  13 +)
  14 +
  15 +type ArticleAndTagRepository struct {
  16 + *cache.CachedRepository
  17 +}
  18 +
  19 +func (repository *ArticleAndTagRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.ArticleAndTag) (*domain.ArticleAndTag, error) {
  20 + var (
  21 + err error
  22 + m = &models.ArticleAndTag{}
  23 + tx = conn.DB()
  24 + )
  25 + if m, err = repository.DomainModelToModel(dm); err != nil {
  26 + return nil, err
  27 + }
  28 + if tx = tx.Model(m).Save(m); tx.Error != nil {
  29 + return nil, tx.Error
  30 + }
  31 + dm.Id = m.Id
  32 + return repository.ModelToDomainModel(m)
  33 +
  34 +}
  35 +
  36 +func (repository *ArticleAndTagRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.ArticleAndTag) (*domain.ArticleAndTag, error) {
  37 + var (
  38 + err error
  39 + m *models.ArticleAndTag
  40 + tx = conn.DB()
  41 + )
  42 + if m, err = repository.DomainModelToModel(dm); err != nil {
  43 + return nil, err
  44 + }
  45 + queryFunc := func() (interface{}, error) {
  46 + tx = tx.Model(m).Updates(m)
  47 + return nil, tx.Error
  48 + }
  49 + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  50 + return nil, err
  51 + }
  52 + return repository.ModelToDomainModel(m)
  53 +}
  54 +
  55 +func (repository *ArticleAndTagRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.ArticleAndTag) (*domain.ArticleAndTag, error) {
  56 + var (
  57 + tx = conn.DB()
  58 + m = &models.ArticleAndTag{Id: dm.Id}
  59 + )
  60 + queryFunc := func() (interface{}, error) {
  61 + tx = tx.Where("id = ?", m.Id).Delete(m)
  62 + return m, tx.Error
  63 + }
  64 + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  65 + return dm, err
  66 + }
  67 + return repository.ModelToDomainModel(m)
  68 +}
  69 +
  70 +func (repository *ArticleAndTagRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.ArticleAndTag, error) {
  71 + var (
  72 + err error
  73 + tx = conn.DB()
  74 + m = new(models.ArticleAndTag)
  75 + )
  76 + queryFunc := func() (interface{}, error) {
  77 + tx = tx.Model(m).Where("id = ?", id).First(m)
  78 + if errors.Is(tx.Error, gorm.ErrRecordNotFound) {
  79 + return nil, domain.ErrNotFound
  80 + }
  81 + return m, tx.Error
  82 + }
  83 + cacheModel := new(models.ArticleAndTag)
  84 + cacheModel.Id = id
  85 + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil {
  86 + return nil, err
  87 + }
  88 + return repository.ModelToDomainModel(m)
  89 +}
  90 +
  91 +func (repository *ArticleAndTagRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.ArticleAndTag, error) {
  92 + var (
  93 + tx = conn.DB()
  94 + ms []*models.ArticleAndTag
  95 + dms = make([]*domain.ArticleAndTag, 0)
  96 + total int64
  97 + )
  98 + queryFunc := func() (interface{}, error) {
  99 + tx = tx.Model(&ms).Order("id desc")
  100 + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
  101 + return dms, tx.Error
  102 + }
  103 + return dms, nil
  104 + }
  105 +
  106 + if _, err := repository.Query(queryFunc); err != nil {
  107 + return 0, nil, err
  108 + }
  109 +
  110 + for _, item := range ms {
  111 + if dm, err := repository.ModelToDomainModel(item); err != nil {
  112 + return 0, dms, err
  113 + } else {
  114 + dms = append(dms, dm)
  115 + }
  116 + }
  117 + return total, dms, nil
  118 +}
  119 +
  120 +func (repository *ArticleAndTagRepository) ModelToDomainModel(from *models.ArticleAndTag) (*domain.ArticleAndTag, error) {
  121 + to := &domain.ArticleAndTag{}
  122 + err := copier.Copy(to, from)
  123 + return to, err
  124 +}
  125 +
  126 +func (repository *ArticleAndTagRepository) DomainModelToModel(from *domain.ArticleAndTag) (*models.ArticleAndTag, error) {
  127 + to := &models.ArticleAndTag{}
  128 + err := copier.Copy(to, from)
  129 + return to, err
  130 +}
  131 +
  132 +func NewArticleAndTagRepository(cache *cache.CachedRepository) domain.ArticleAndTagRepository {
  133 + return &ArticleAndTagRepository{CachedRepository: cache}
  134 +}
@@ -125,11 +125,23 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans @@ -125,11 +125,23 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
125 queryFunc := func() (interface{}, error) { 125 queryFunc := func() (interface{}, error) {
126 tx = tx.Model(&ms).Order("id desc") 126 tx = tx.Model(&ms).Order("id desc")
127 if v, ok := queryOptions["topId"]; ok { 127 if v, ok := queryOptions["topId"]; ok {
128 - tx = tx.Where("top_id", v) 128 + tx = tx.Where("top_id=?", v)
129 } 129 }
130 if v, ok := queryOptions["show"]; ok { 130 if v, ok := queryOptions["show"]; ok {
131 - tx = tx.Where("show", v) 131 + tx = tx.Where("show=?", v)
132 } 132 }
  133 + if v, ok := queryOptions["articleId"]; ok {
  134 + tx = tx.Where("article_id=?", v)
  135 + }
  136 +
  137 + if v, ok := queryOptions["sectionId"]; ok {
  138 + tx = tx.Where("section_id=?", v)
  139 + }
  140 +
  141 + if v, ok := queryOptions["companyId"]; ok {
  142 + tx = tx.Where("company_id=?", v)
  143 + }
  144 +
133 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 145 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
134 return dms, tx.Error 146 return dms, tx.Error
135 } 147 }
@@ -216,7 +228,10 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co @@ -216,7 +228,10 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co
216 ) 228 )
217 m = &models.ArticleComment{Id: commnetId} 229 m = &models.ArticleComment{Id: commnetId}
218 queryFunc := func() (interface{}, error) { 230 queryFunc := func() (interface{}, error) {
219 - tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr)) 231 + tx = tx.Model(m).Updates(map[string]interface{}{
  232 + "count_user_love": gorm.Expr("count_user_love+?", incr),
  233 + "version": gorm.Expr("version+1"),
  234 + })
220 return nil, tx.Error 235 return nil, tx.Error
221 } 236 }
222 if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { 237 if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
@@ -235,7 +250,10 @@ func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Conte @@ -235,7 +250,10 @@ func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Conte
235 ) 250 )
236 m = &models.ArticleComment{Id: commnetId} 251 m = &models.ArticleComment{Id: commnetId}
237 queryFunc := func() (interface{}, error) { 252 queryFunc := func() (interface{}, error) {
238 - tx = tx.Model(m).Update("count_reply", gorm.Expr("count_reply+?", incr)) 253 + tx = tx.Model(m).Updates(map[string]interface{}{
  254 + "count_reply": gorm.Expr("count_reply+?", incr),
  255 + "version": gorm.Expr("version+1"),
  256 + })
239 return nil, tx.Error 257 return nil, tx.Error
240 } 258 }
241 if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { 259 if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
@@ -245,6 +263,60 @@ func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Conte @@ -245,6 +263,60 @@ func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Conte
245 263
246 } 264 }
247 265
  266 +// 获取热度前5的
  267 +// 规则 热门=(回复数+赞数量+运营点赞)Top5
  268 +func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*domain.ArticleComment, error) {
  269 +
  270 + sql1 := `select
  271 + article_comment.id ,
  272 + (article_comment.count_reply +article_comment.count_user_love +article_comment.count_admin_love ) cnt
  273 + from article_comment
  274 + where top_id =0 and article_id =? and deleted_at=0 and show=0 and company_id=?
  275 + order by cnt desc,article_comment.id desc
  276 + limit 5 `
  277 + db := conn.DB()
  278 + rows, err := db.Raw(sql1, articleId, companyId).Rows()
  279 + if err != nil {
  280 + return nil, err
  281 + }
  282 + defer rows.Close()
  283 + commentIds := []int64{}
  284 + var cid int64
  285 + var cnt int64
  286 + for rows.Next() {
  287 + err = rows.Scan(&cid, &cnt)
  288 + if err != nil {
  289 + return nil, err
  290 + }
  291 + commentIds = append(commentIds, cid)
  292 + }
  293 + if len(commentIds) == 0 {
  294 + return nil, nil
  295 + }
  296 + ms := make([]*models.ArticleComment, 0)
  297 + dms := make([]*domain.ArticleComment, 0)
  298 + queryFunc := func() (interface{}, error) {
  299 + tx := db.Model(&ms).Where("id in(?)", commentIds)
  300 + queryOptions := domain.NewQueryOptions().WithFindOnly()
  301 + if _, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
  302 + return dms, tx.Error
  303 + }
  304 + return dms, nil
  305 + }
  306 +
  307 + if _, err := repository.Query(queryFunc); err != nil {
  308 + return nil, err
  309 + }
  310 +
  311 + for _, item := range ms {
  312 + if dm, err := repository.ModelToDomainModel(item); err != nil {
  313 + return dms, err
  314 + } else {
  315 + dms = append(dms, dm)
  316 + }
  317 + }
  318 + return dms, nil
  319 +}
248 func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { 320 func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository {
249 return &ArticleCommentRepository{CachedRepository: cache} 321 return &ArticleCommentRepository{CachedRepository: cache}
250 } 322 }
@@ -178,6 +178,27 @@ func (repository *ArticleSectionRepository) DomainModelToModel(from *domain.Arti @@ -178,6 +178,27 @@ func (repository *ArticleSectionRepository) DomainModelToModel(from *domain.Arti
178 return to, nil 178 return to, nil
179 } 179 }
180 180
  181 +// 评论数量变动
  182 +func (repository *ArticleSectionRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, sectionId int64) error {
  183 + var (
  184 + err error
  185 + m *models.ArticleSection
  186 + tx = conn.DB()
  187 + )
  188 + m = &models.ArticleSection{Id: sectionId}
  189 + queryFunc := func() (interface{}, error) {
  190 + tx = tx.Model(m).Updates(map[string]interface{}{
  191 + "total_comment": gorm.Expr("total_comment+?", incr),
  192 + "version": gorm.Expr("version+1"),
  193 + })
  194 + return nil, tx.Error
  195 + }
  196 + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
  197 + return err
  198 + }
  199 + return nil
  200 +}
  201 +
181 func NewArticleSectionRepository(cache *cache.CachedRepository) domain.ArticleSectionRepository { 202 func NewArticleSectionRepository(cache *cache.CachedRepository) domain.ArticleSectionRepository {
182 return &ArticleSectionRepository{CachedRepository: cache} 203 return &ArticleSectionRepository{CachedRepository: cache}
183 } 204 }
  1 +package domain
  2 +
  3 +import (
  4 + "context"
  5 +
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
  7 +)
  8 +
  9 +// 保存文章和标签的关系,主要用于分组统计用
  10 +type ArticleAndTag struct {
  11 + Id int64 `json:"id"`
  12 + CompanyId int64 `json:"companyId"`
  13 + CreatedAt int64 `json:"createdAt"`
  14 + UpdatedAt int64 `json:"updatedAt"`
  15 + ArticleId int64 `json:"articleId"`
  16 + TagId int64 `json:"tagId"`
  17 +}
  18 +
  19 +type ArticleAndTagRepository interface {
  20 + Insert(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
  21 + Update(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
  22 + Delete(ctx context.Context, conn transaction.Conn, dm *ArticleAndTag) (*ArticleAndTag, error)
  23 + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleAndTag, error)
  24 + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleAndTag, error)
  25 +}
@@ -59,4 +59,5 @@ type ArticleCommentRepository interface { @@ -59,4 +59,5 @@ type ArticleCommentRepository interface {
59 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)
60 IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, commentId int64) 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 // 评论回复数量变动 61 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)
62 } 63 }
@@ -27,6 +27,7 @@ type ArticleSectionRepository interface { @@ -27,6 +27,7 @@ type ArticleSectionRepository interface {
27 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error) 27 Delete(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error)
28 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error) 28 FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error)
29 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error) 29 Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error)
  30 + IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, sectionId int64) error //评论数量变动
30 } 31 }
31 32
32 // 排序文章分段列表 33 // 排序文章分段列表
@@ -13,6 +13,7 @@ type MessageBusiness struct { @@ -13,6 +13,7 @@ type MessageBusiness struct {
13 UserId int64 `json:"userId"` // 操作人用户ID 13 UserId int64 `json:"userId"` // 操作人用户ID
14 RecipientId int64 `json:"recipientId"` // 接收人用户ID 14 RecipientId int64 `json:"recipientId"` // 接收人用户ID
15 ArticleId int64 `json:"articleId"` // 文章ID 15 ArticleId int64 `json:"articleId"` // 文章ID
  16 + SectionId int64 `json:"sectionId"` // 段落ID
16 CommentId int64 `json:"commentId"` // 评论ID 17 CommentId int64 `json:"commentId"` // 评论ID
17 Content string `json:"content"` // 消息内容 18 Content string `json:"content"` // 消息内容
18 CreatedAt int64 `json:",omitempty"` 19 CreatedAt int64 `json:",omitempty"`
@@ -35,7 +36,7 @@ const ( @@ -35,7 +36,7 @@ const (
35 36
36 const ( 37 const (
37 OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章 38 OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章
38 - OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论 39 + OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论()
39 OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论 40 OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论
40 ) 41 )
41 42