作者 tangxvhui
@@ -78,7 +78,7 @@ service Core { @@ -78,7 +78,7 @@ service Core {
78 @server( 78 @server(
79 prefix: v1/system 79 prefix: v1/system
80 group: article 80 group: article
81 - jwt: MiniAuth 81 + jwt: SystemAuth
82 ) 82 )
83 service Core { 83 service Core {
84 @doc "管理后台获取文章内容详情" 84 @doc "管理后台获取文章内容详情"
@@ -88,4 +88,8 @@ service Core { @@ -88,4 +88,8 @@ service Core {
88 @doc "管理后台获取文章列表" 88 @doc "管理后台获取文章列表"
89 @handler SystemSearchArticle 89 @handler SystemSearchArticle
90 post /article/search (SystemArticleSearchRequest) returns (SystemArticleSearchResponse) 90 post /article/search (SystemArticleSearchRequest) returns (SystemArticleSearchResponse)
  91 +
  92 + @doc "管理后台获取我发布的文章"
  93 + @handler SystemArticleSearchMe
  94 + post /article/search/me (SystemArticleSearchMeRequest) returns (SystemArticleSearchMeResponse)
91 } 95 }
@@ -88,6 +88,18 @@ type ( @@ -88,6 +88,18 @@ type (
88 CountComment int `json:"CountComment"` //评论数量 88 CountComment int `json:"CountComment"` //评论数量
89 Show int `json:"show"` //是否隐藏 [0显示、1不显示] 89 Show int `json:"show"` //是否隐藏 [0显示、1不显示]
90 } 90 }
  91 +
  92 + SystemArticleSearchMeRequest {
  93 + Page int `json:"page"`
  94 + Size int `json:"size"`
  95 + AuthorId int64 `json:"authorId"` // 用户
  96 + BeginTime int64 `json:"beginTime,optional"` // 开始时间
  97 + EndTime int64 `json:"endTime,optional"` // 结束时间
  98 + }
  99 + SystemArticleSearchMeResponse {
  100 + Total int `json:"total"`
  101 + List []ArticleSearchMe `json:"list"`
  102 + }
91 ) 103 )
92 104
93 //小程序端获取文章有哪些人进行了点赞 105 //小程序端获取文章有哪些人进行了点赞
@@ -45,6 +45,19 @@ service Core { @@ -45,6 +45,19 @@ service Core {
45 post /article_comment/at_who/list (MiniArticleCommentAtWhoRequest) returns (MiniArticleCommentAtWhoResponse) 45 post /article_comment/at_who/list (MiniArticleCommentAtWhoRequest) returns (MiniArticleCommentAtWhoResponse)
46 } 46 }
47 47
  48 +// 后台接口
  49 +@server(
  50 + prefix: v1/system
  51 + group: comment
  52 + middleware: LoginStatusCheck
  53 + jwt: SystemAuth
  54 +)
  55 +service Core {
  56 + @doc "小程序获取回复@人可选列表"
  57 + @handler SystemArticleCommentSearchMe
  58 + post /article_comment/search/me (SystemArticleCommentSearchMeRequest) returns (SystemArticleCommentSearchMeResponse)
  59 +}
  60 +
48 // 61 //
49 // 小程序获取回复@人可选列表 62 // 小程序获取回复@人可选列表
50 type ( 63 type (
@@ -139,6 +152,7 @@ type ( @@ -139,6 +152,7 @@ type (
139 AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 152 AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
140 CreatedAt int64 `json:"createdAt"` // 153 CreatedAt int64 `json:"createdAt"` //
141 MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) 154 MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
  155 + Content string `json:"content"` // 评论的内容
142 } 156 }
143 ) 157 )
144 158
@@ -190,4 +204,18 @@ type ( @@ -190,4 +204,18 @@ type (
190 MiniArticleCommentAtWhoResponse { 204 MiniArticleCommentAtWhoResponse {
191 List []CommentAtWho `json:"list"` 205 List []CommentAtWho `json:"list"`
192 } 206 }
  207 +)
  208 +
  209 +type(
  210 + SystemArticleCommentSearchMeRequest{
  211 + Page int `json:"page"`
  212 + Size int `json:"size"`
  213 + AuthorId int64 `json:"authorId"` // 用户
  214 + BeginTime int64 `json:"beginTime,optional"` // 开始时间
  215 + EndTime int64 `json:"endTime,optional"` // 结束时间
  216 + }
  217 + SystemArticleCommentSearchMeResponse{
  218 + List []ArticleCommentItem `json:"list"`
  219 + Total int64 `json:"total"`
  220 + }
193 ) 221 )
@@ -261,11 +261,13 @@ type( @@ -261,11 +261,13 @@ type(
261 Code string `json:"code"` 261 Code string `json:"code"`
262 } 262 }
263 UserStatisticsRequest{ 263 UserStatisticsRequest{
264 - UserId int64 `json:"userId"`  
265 - ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳 264 + UserId int64 `json:"userId,optional"`
  265 + ItemFlag int `json:"itemFlag"` //0:默认查询所有 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
266 } 266 }
267 UserStatisticsResponse{ 267 UserStatisticsResponse{
268 - List []StatisticsItem `json:"list"` 268 + TotalArticle int `json:"totalArticle"`
  269 + TotalComment int `json:"totalComment"`
  270 + TotalLoved int `json:"totalLoved"`
269 } 271 }
270 StatisticsItem{ 272 StatisticsItem{
271 ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳 273 ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
  1 +package article
  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/article"
  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 SystemArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.SystemArticleSearchMeRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := article.NewSystemArticleSearchMeLogic(r.Context(), svcCtx)
  22 + resp, err := l.SystemArticleSearchMe(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
  1 +package comment
  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/comment"
  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 SystemArticleCommentSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
  14 + return func(w http.ResponseWriter, r *http.Request) {
  15 + var req types.SystemArticleCommentSearchMeRequest
  16 + if err := httpx.Parse(r, &req); err != nil {
  17 + httpx.ErrorCtx(r.Context(), w, err)
  18 + return
  19 + }
  20 +
  21 + l := comment.NewSystemArticleCommentSearchMeLogic(r.Context(), svcCtx)
  22 + resp, err := l.SystemArticleCommentSearchMe(&req)
  23 + result.HttpResult(r, w, resp, err)
  24 + }
  25 +}
@@ -61,6 +61,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -61,6 +61,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
61 ) 61 )
62 62
63 server.AddRoutes( 63 server.AddRoutes(
  64 + rest.WithMiddlewares(
  65 + []rest.Middleware{serverCtx.LoginStatusCheck},
  66 + []rest.Route{
  67 + {
  68 + Method: http.MethodPost,
  69 + Path: "/article_comment/search/me",
  70 + Handler: comment.SystemArticleCommentSearchMeHandler(serverCtx),
  71 + },
  72 + }...,
  73 + ),
  74 + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
  75 + rest.WithPrefix("/v1/system"),
  76 + )
  77 +
  78 + server.AddRoutes(
64 []rest.Route{ 79 []rest.Route{
65 { 80 {
66 Method: http.MethodPost, 81 Method: http.MethodPost,
@@ -371,8 +386,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { @@ -371,8 +386,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
371 Path: "/article/search", 386 Path: "/article/search",
372 Handler: article.SystemSearchArticleHandler(serverCtx), 387 Handler: article.SystemSearchArticleHandler(serverCtx),
373 }, 388 },
  389 + {
  390 + Method: http.MethodPost,
  391 + Path: "/article/search/me",
  392 + Handler: article.SystemArticleSearchMeHandler(serverCtx),
  393 + },
374 }, 394 },
375 - rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), 395 + rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
376 rest.WithPrefix("/v1/system"), 396 rest.WithPrefix("/v1/system"),
377 ) 397 )
378 398
@@ -42,19 +42,24 @@ func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSea @@ -42,19 +42,24 @@ func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSea
42 List: make([]types.ArticleSearchMe, len(articleList)), 42 List: make([]types.ArticleSearchMe, len(articleList)),
43 } 43 }
44 for i := range articleList { 44 for i := range articleList {
45 - images := []string{}  
46 - for _, val2 := range articleList[i].Images {  
47 - images = append(images, val2.Url)  
48 - }  
49 - resp.List[i] = types.ArticleSearchMe{  
50 - Id: articleList[i].Id,  
51 - Title: articleList[i].Title,  
52 - Images: images,  
53 - CreatedAt: articleList[i].CreatedAt,  
54 - CountLove: articleList[i].CountLove,  
55 - CountComment: articleList[i].CountComment,  
56 - Show: int(articleList[i].Show),  
57 - } 45 + resp.List[i] = NewArticle(articleList[i])
58 } 46 }
59 return 47 return
60 } 48 }
  49 +
  50 +func NewArticle(article *domain.Article) types.ArticleSearchMe {
  51 + images := []string{}
  52 + for _, val2 := range article.Images {
  53 + images = append(images, val2.Url)
  54 + }
  55 + articleSearchMe := types.ArticleSearchMe{
  56 + Id: article.Id,
  57 + Title: article.Title,
  58 + Images: images,
  59 + CreatedAt: article.CreatedAt,
  60 + CountLove: article.CountLove,
  61 + CountComment: article.CountComment,
  62 + Show: int(article.Show),
  63 + }
  64 + return articleSearchMe
  65 +}
@@ -2,6 +2,7 @@ package article @@ -2,6 +2,7 @@ package article
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"
@@ -97,6 +98,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi @@ -97,6 +98,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeArticle(req *types.MiniSetUserLi
97 if err != nil { 98 if err != nil {
98 return err 99 return err
99 } 100 }
  101 +
  102 + // 删除点赞文章消息
  103 + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
  104 + err = messageLogic.UnLikeArticle(c, articleInfo.Id)
  105 + if err != nil {
  106 + return err
  107 + }
  108 +
100 return nil 109 return nil
101 }, true) 110 }, true)
102 if err != nil { 111 if err != nil {
@@ -170,6 +179,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi @@ -170,6 +179,14 @@ func (l *MiniSetUserLikeLogic) cancelSetUserLikeComment(req *types.MiniSetUserLi
170 if err != nil { 179 if err != nil {
171 return err 180 return err
172 } 181 }
  182 +
  183 + // 删除点赞评论消息
  184 + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
  185 + err = messageLogic.UnLikeComment(c, commentInfo.ArticleId, commentInfo.Id)
  186 + if err != nil {
  187 + return err
  188 + }
  189 +
173 return nil 190 return nil
174 }, true) 191 }, true)
175 if err != nil { 192 if err != nil {
@@ -243,6 +260,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ @@ -243,6 +260,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeArticle(req *types.MiniSetUserLikeRequ
243 if err != nil { 260 if err != nil {
244 return err 261 return err
245 } 262 }
  263 +
  264 + // 创建点赞消息
  265 + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
  266 + err = messageLogic.LikeArticle(c, articleInfo.Id, articleInfo.AuthorId)
  267 + if err != nil {
  268 + return err
  269 + }
  270 +
246 return nil 271 return nil
247 }, true) 272 }, true)
248 if err != nil { 273 if err != nil {
@@ -324,6 +349,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ @@ -324,6 +349,14 @@ func (l *MiniSetUserLikeLogic) setUserLikeComment(req *types.MiniSetUserLikeRequ
324 if err != nil { 349 if err != nil {
325 return err 350 return err
326 } 351 }
  352 +
  353 + // 创建点赞消息
  354 + var messageLogic = message.NewMiniBusinessLogic(l.ctx, l.svcCtx)
  355 + err = messageLogic.LikeComment(c, commentInfo.ArticleId, commentInfo.Id, commentInfo.FromUserId)
  356 + if err != nil {
  357 + return err
  358 + }
  359 +
327 return nil 360 return nil
328 }, true) 361 }, true)
329 if err != nil { 362 if err != nil {
  1 +package article
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  8 +
  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 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type SystemArticleSearchMeLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewSystemArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemArticleSearchMeLogic {
  22 + return &SystemArticleSearchMeLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *SystemArticleSearchMeLogic) SystemArticleSearchMe(req *types.SystemArticleSearchMeRequest) (resp *types.SystemArticleSearchMeResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  33 + )
  34 + queryOptions := domain.NewQueryOptions().
  35 + WithOffsetLimit(req.Page, req.Size).
  36 + MustWithKV("authorId", req.AuthorId).
  37 + WithKV("beginCreatedAt", req.BeginTime).
  38 + WithKV("endCreatedAt", req.EndTime)
  39 +
  40 + cnt, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, userToken.CompanyId, queryOptions)
  41 + if err != nil {
  42 + return &types.SystemArticleSearchMeResponse{}, xerr.NewErrMsgErr("获取文章列表失败", err)
  43 + }
  44 +
  45 + resp = &types.SystemArticleSearchMeResponse{
  46 + Total: int(cnt),
  47 + List: make([]types.ArticleSearchMe, len(articleList)),
  48 + }
  49 + for i := range articleList {
  50 + resp.List[i] = NewArticle(articleList[i])
  51 + }
  52 + return
  53 +}
@@ -51,36 +51,7 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5 @@ -51,36 +51,7 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5
51 List: make([]types.ArticleCommentItem, len(commentList)), 51 List: make([]types.ArticleCommentItem, len(commentList)),
52 } 52 }
53 for i, val := range commentList { 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 - } 54 + item := NewArticleCommentItem(val)
84 55
85 if _, ok := flagMap[val.Id]; ok { 56 if _, ok := flagMap[val.Id]; ok {
86 item.MeLoveFlag = 1 57 item.MeLoveFlag = 1
@@ -95,3 +66,38 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5 @@ -95,3 +66,38 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5
95 } 66 }
96 return 67 return
97 } 68 }
  69 +
  70 +func NewArticleCommentItem(val *domain.ArticleComment) types.ArticleCommentItem {
  71 + item := types.ArticleCommentItem{
  72 + Id: val.Id,
  73 + Pid: val.Pid,
  74 + TopId: val.TopId,
  75 + ArtitcleId: val.ArticleId,
  76 + SectionId: val.SectionId,
  77 + FromUserId: val.FromUserId,
  78 + FromUser: types.CommentAuthor{
  79 + Id: val.FromUser.Id,
  80 + Name: val.FromUser.Name,
  81 + Avatar: val.FromUser.Avatar,
  82 + Position: val.FromUser.Position,
  83 + Company: val.FromUser.Company,
  84 + },
  85 + ToUserId: val.ToUserId,
  86 + ToUser: types.CommentAuthor{
  87 + Id: val.ToUser.Id,
  88 + Name: val.ToUser.Name,
  89 + Avatar: val.ToUser.Avatar,
  90 + Position: val.ToUser.Position,
  91 + Company: val.ToUser.Company,
  92 + },
  93 + SectionContent: val.SectionContent,
  94 + CountReply: val.CountReply,
  95 + CountUserLove: val.CountUserLove,
  96 + CountAdminLove: val.CountAdminLove,
  97 + AtWho: []types.CommentAtWho{},
  98 + CreatedAt: val.CreatedAt,
  99 + MeLoveFlag: 0,
  100 + Content: val.Content,
  101 + }
  102 + return item
  103 +}
  1 +package comment
  2 +
  3 +import (
  4 + "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
  8 +
  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 + "github.com/zeromicro/go-zero/core/logx"
  13 +)
  14 +
  15 +type SystemArticleCommentSearchMeLogic struct {
  16 + logx.Logger
  17 + ctx context.Context
  18 + svcCtx *svc.ServiceContext
  19 +}
  20 +
  21 +func NewSystemArticleCommentSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemArticleCommentSearchMeLogic {
  22 + return &SystemArticleCommentSearchMeLogic{
  23 + Logger: logx.WithContext(ctx),
  24 + ctx: ctx,
  25 + svcCtx: svcCtx,
  26 + }
  27 +}
  28 +
  29 +func (l *SystemArticleCommentSearchMeLogic) SystemArticleCommentSearchMe(req *types.SystemArticleCommentSearchMeRequest) (resp *types.SystemArticleCommentSearchMeResponse, err error) {
  30 + var (
  31 + conn = l.svcCtx.DefaultDBConn()
  32 + userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  33 + )
  34 + queryOptions := domain.IndexCompanyId(userToken.CompanyId)().
  35 + WithOffsetLimit(req.Page, req.Size).
  36 + MustWithKV("fromUserId", req.AuthorId).
  37 + WithKV("beginCreatedAt", req.BeginTime).
  38 + WithKV("endCreatedAt", req.EndTime)
  39 +
  40 + cnt, articleList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions)
  41 + if err != nil {
  42 + return &types.SystemArticleCommentSearchMeResponse{}, xerr.NewErrMsgErr("获取评论回复列表失败", err)
  43 + }
  44 +
  45 + resp = &types.SystemArticleCommentSearchMeResponse{
  46 + Total: cnt,
  47 + List: make([]types.ArticleCommentItem, len(articleList)),
  48 + }
  49 + for i := range articleList {
  50 + resp.List[i] = NewArticleCommentItem(articleList[i])
  51 + }
  52 + return
  53 +}
@@ -222,8 +222,18 @@ func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64, @@ -222,8 +222,18 @@ func (l *MiniBusinessLogic) LikeArticle(conn transaction.Conn, articleId int64,
222 } 222 }
223 223
224 // LikeComment 点赞评论 224 // LikeComment 点赞评论
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}) 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, 0, commentId, "", []int64{at})
  227 +}
  228 +
  229 +// UnLikeArticle 取消点赞文章
  230 +func (l *MiniBusinessLogic) UnLikeArticle(conn transaction.Conn, articleId int64) (err error) {
  231 + return l.deleteMessage(conn, domain.OptTypeArticle, articleId, 0)
  232 +}
  233 +
  234 +// UnLikeComment 取消点赞评论
  235 +func (l *MiniBusinessLogic) UnLikeComment(conn transaction.Conn, articleId int64, commentId int64) (err error) {
  236 + return l.deleteMessage(conn, domain.OptTypeComment, articleId, commentId)
227 } 237 }
228 238
229 func (l *MiniBusinessLogic) createMessage( 239 func (l *MiniBusinessLogic) createMessage(
@@ -257,3 +267,27 @@ func (l *MiniBusinessLogic) createMessage( @@ -257,3 +267,27 @@ func (l *MiniBusinessLogic) createMessage(
257 } 267 }
258 return nil 268 return nil
259 } 269 }
  270 +
  271 +func (l *MiniBusinessLogic) deleteMessage(conn transaction.Conn, optType domain.MsgBusinessOpt, articleId int64, commentId int64) (err error) {
  272 + var userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  273 +
  274 + queryOption := domain.NewQueryOptions().WithFindOnly().WithOffsetLimit(1, 1).
  275 + MustWithKV("type", domain.MsgTypeLike).
  276 + MustWithKV("optType", optType).
  277 + MustWithKV("companyId", userToken.CompanyId).
  278 + MustWithKV("recipientId", userToken.UserId).
  279 + MustWithKV("articleId", articleId).
  280 + MustWithKV("commentId", commentId)
  281 +
  282 + _, list, err := l.svcCtx.MessageBusinessRepository.Find(l.ctx, conn, queryOption)
  283 + if err != nil {
  284 + return err
  285 + }
  286 + for i := range list {
  287 + _, err = l.svcCtx.MessageBusinessRepository.Delete(l.ctx, conn, list[i])
  288 + if err != nil {
  289 + return err
  290 + }
  291 + }
  292 + return nil
  293 +}
@@ -2,6 +2,8 @@ package user @@ -2,6 +2,8 @@ package user
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
5 7
6 "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"
7 "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"
@@ -24,7 +26,58 @@ func NewSystemUserStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContex @@ -24,7 +26,58 @@ func NewSystemUserStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContex
24 } 26 }
25 27
26 func (l *SystemUserStatisticsLogic) SystemUserStatistics(req *types.UserStatisticsRequest) (resp *types.UserStatisticsResponse, err error) { 28 func (l *SystemUserStatisticsLogic) SystemUserStatistics(req *types.UserStatisticsRequest) (resp *types.UserStatisticsResponse, err error) {
27 - // todo: add your logic here and delete this line 29 + var (
  30 + userId = req.UserId
  31 + userToken = contextdata.GetUserTokenFromCtx(l.ctx)
  32 + )
  33 + s := StatisticsItems(l.ctx, l.svcCtx, userToken.CompanyId, userId, req.ItemFlag)
  34 + resp = &types.UserStatisticsResponse{
  35 + TotalArticle: s.TotalArticle,
  36 + TotalComment: s.TotalComment,
  37 + TotalLoved: s.TotalLoved,
  38 + }
  39 + return
  40 +}
28 41
  42 +func StatisticsItems(ctx context.Context, svcCtx *svc.ServiceContext, companyId, userId int64, itemFlag int) (s Statistics) {
  43 + var conn = svcCtx.DefaultDBConn()
  44 + s = Statistics{}
  45 + if itemFlag == 0 {
  46 + itemFlag = -1
  47 + }
  48 + if (itemFlag & TotalArticle) > 0 {
  49 + var total int64
  50 + total, _, _ = svcCtx.ArticleRepository.Find(ctx, conn, companyId, domain.NewQueryOptions().WithCountOnly().MustWithKV("authorId", userId))
  51 + s.TotalArticle = int(total)
  52 + }
  53 + if (itemFlag & TotalComment) > 0 {
  54 + var total int64
  55 + total, _, _ = svcCtx.ArticleCommentRepository.Find(ctx, conn, domain.IndexCompanyId(companyId)().WithCountOnly().MustWithKV("fromUserId", userId))
  56 + s.TotalComment = int(total)
  57 + }
  58 + if (itemFlag & TotalLoved) > 0 {
  59 + var total int64
  60 + total, _, _ = svcCtx.UserLoveFlagRepository.Find(ctx, conn, domain.IndexCompanyId(companyId)().WithCountOnly().MustWithKV("userId", userId))
  61 + s.TotalComment = int(total)
  62 + }
29 return 63 return
30 } 64 }
  65 +
  66 +type Statistics struct {
  67 + TotalArticle int `json:"totalArticle"`
  68 + TotalComment int `json:"totalComment"`
  69 + TotalLoved int `json:"totalLoved"`
  70 +}
  71 +
  72 +const (
  73 + TotalArticle = 1
  74 + TotalComment = 2
  75 + TotalLoved = 4
  76 +)
  77 +
  78 +func NewStatisticsItem(itemFlag int, value float64) types.StatisticsItem {
  79 + return types.StatisticsItem{
  80 + ItemFlag: itemFlag,
  81 + Value: value,
  82 + }
  83 +}
@@ -87,6 +87,7 @@ type ArticleCommentItem struct { @@ -87,6 +87,7 @@ type ArticleCommentItem struct {
87 AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 87 AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
88 CreatedAt int64 `json:"createdAt"` // 88 CreatedAt int64 `json:"createdAt"` //
89 MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) 89 MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
  90 + Content string `json:"content"` // 评论的内容
90 } 91 }
91 92
92 type MiniGetArticleCommentRequest struct { 93 type MiniGetArticleCommentRequest struct {
@@ -129,6 +130,19 @@ type MiniArticleCommentAtWhoResponse struct { @@ -129,6 +130,19 @@ type MiniArticleCommentAtWhoResponse struct {
129 List []CommentAtWho `json:"list"` 130 List []CommentAtWho `json:"list"`
130 } 131 }
131 132
  133 +type SystemArticleCommentSearchMeRequest struct {
  134 + Page int `json:"page"`
  135 + Size int `json:"size"`
  136 + AuthorId int64 `json:"authorId"` // 用户
  137 + BeginTime int64 `json:"beginTime,optional"` // 开始时间
  138 + EndTime int64 `json:"endTime,optional"` // 结束时间
  139 +}
  140 +
  141 +type SystemArticleCommentSearchMeResponse struct {
  142 + List []ArticleCommentItem `json:"list"`
  143 + Total int64 `json:"total"`
  144 +}
  145 +
132 type MessageSystemRequest struct { 146 type MessageSystemRequest struct {
133 Page int `json:"page"` 147 Page int `json:"page"`
134 Size int `json:"size"` 148 Size int `json:"size"`
@@ -428,12 +442,14 @@ type SystemUserInfoResponse struct { @@ -428,12 +442,14 @@ type SystemUserInfoResponse struct {
428 } 442 }
429 443
430 type UserStatisticsRequest struct { 444 type UserStatisticsRequest struct {
431 - UserId int64 `json:"userId"`  
432 - ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳 445 + UserId int64 `json:"userId,optional"`
  446 + ItemFlag int `json:"itemFlag"` //0:默认查询所有 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
433 } 447 }
434 448
435 type UserStatisticsResponse struct { 449 type UserStatisticsResponse struct {
436 - List []StatisticsItem `json:"list"` 450 + TotalArticle int `json:"totalArticle"`
  451 + TotalComment int `json:"totalComment"`
  452 + TotalLoved int `json:"totalLoved"`
437 } 453 }
438 454
439 type StatisticsItem struct { 455 type StatisticsItem struct {
@@ -640,6 +656,19 @@ type ArticleSearchMe struct { @@ -640,6 +656,19 @@ type ArticleSearchMe struct {
640 Show int `json:"show"` //是否隐藏 [0显示、1不显示] 656 Show int `json:"show"` //是否隐藏 [0显示、1不显示]
641 } 657 }
642 658
  659 +type SystemArticleSearchMeRequest struct {
  660 + Page int `json:"page"`
  661 + Size int `json:"size"`
  662 + AuthorId int64 `json:"authorId"` // 用户
  663 + BeginTime int64 `json:"beginTime,optional"` // 开始时间
  664 + EndTime int64 `json:"endTime,optional"` // 结束时间
  665 +}
  666 +
  667 +type SystemArticleSearchMeResponse struct {
  668 + Total int `json:"total"`
  669 + List []ArticleSearchMe `json:"list"`
  670 +}
  671 +
643 type MiniUserLikeArticleRequest struct { 672 type MiniUserLikeArticleRequest struct {
644 ArticleId int64 `json:"articleId"` // 文章id 673 ArticleId int64 `json:"articleId"` // 文章id
645 CompanyId int64 `json:",optional"` //公司id 674 CompanyId int64 `json:",optional"` //公司id
@@ -137,10 +137,18 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans @@ -137,10 +137,18 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
137 if v, ok := queryOptions["sectionId"]; ok { 137 if v, ok := queryOptions["sectionId"]; ok {
138 tx = tx.Where("section_id=?", v) 138 tx = tx.Where("section_id=?", v)
139 } 139 }
140 -  
141 if v, ok := queryOptions["companyId"]; ok { 140 if v, ok := queryOptions["companyId"]; ok {
142 tx = tx.Where("company_id=?", v) 141 tx = tx.Where("company_id=?", v)
143 } 142 }
  143 + if v, ok := queryOptions["fromUserId"]; ok {
  144 + tx = tx.Where("from_user_id=?", v)
  145 + }
  146 + if v, ok := queryOptions["beginCreatedAt"]; ok {
  147 + tx = tx.Where("created_at >= ?", v)
  148 + }
  149 + if v, ok := queryOptions["endCreatedAt"]; ok {
  150 + tx = tx.Where("created_at < ?", v)
  151 + }
144 152
145 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 153 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
146 return dms, tx.Error 154 return dms, tx.Error
@@ -127,6 +127,12 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction. @@ -127,6 +127,12 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
127 if v, ok := queryOptions["authorId"]; ok { 127 if v, ok := queryOptions["authorId"]; ok {
128 tx = tx.Where("author_id = ?", v) 128 tx = tx.Where("author_id = ?", v)
129 } 129 }
  130 + if v, ok := queryOptions["beginCreatedAt"]; ok {
  131 + tx = tx.Where("created_at >= ?", v)
  132 + }
  133 + if v, ok := queryOptions["endCreatedAt"]; ok {
  134 + tx = tx.Where("created_at < ?", v)
  135 + }
130 136
131 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 137 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
132 return dms, tx.Error 138 return dms, tx.Error
@@ -121,9 +121,24 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran @@ -121,9 +121,24 @@ func (repository *MessageBusinessRepository) Find(ctx context.Context, conn tran
121 ) 121 )
122 queryFunc := func() (interface{}, error) { 122 queryFunc := func() (interface{}, error) {
123 tx = tx.Model(&ms).Order("id desc") 123 tx = tx.Model(&ms).Order("id desc")
  124 + if v, ok := queryOptions["type"]; ok {
  125 + tx.Where("type = ?", v)
  126 + }
  127 + if v, ok := queryOptions["optType"]; ok {
  128 + tx.Where("opt_type = ?", v)
  129 + }
124 if v, ok := queryOptions["companyId"]; ok { 130 if v, ok := queryOptions["companyId"]; ok {
125 tx.Where("company_id = ?", v) 131 tx.Where("company_id = ?", v)
126 } 132 }
  133 + if v, ok := queryOptions["recipientId"]; ok {
  134 + tx.Where("recipient_id = ?", v)
  135 + }
  136 + if v, ok := queryOptions["articleId"]; ok {
  137 + tx.Where("article_id = ?", v)
  138 + }
  139 + if v, ok := queryOptions["commentId"]; ok {
  140 + tx.Where("comment_id = ?", v)
  141 + }
127 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { 142 if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
128 return dms, tx.Error 143 return dms, tx.Error
129 } 144 }
@@ -126,6 +126,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac @@ -126,6 +126,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac
126 if v, ok := queryOptions["commentId"]; ok { 126 if v, ok := queryOptions["commentId"]; ok {
127 tx = tx.Where("comment_id=?", v) 127 tx = tx.Where("comment_id=?", v)
128 } 128 }
  129 + if v, ok := queryOptions["companyId"]; ok {
  130 + tx = tx.Where("company_id=?", v)
  131 + }
129 if v, ok := queryOptions["userId"]; ok { 132 if v, ok := queryOptions["userId"]; ok {
130 tx = tx.Where("user_id=?", v) 133 tx = tx.Where("user_id=?", v)
131 } 134 }
@@ -36,7 +36,7 @@ const ( @@ -36,7 +36,7 @@ const (
36 36
37 const ( 37 const (
38 OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章 38 OptTypeArticle MsgBusinessOpt = 1 // 操作分类-针对文章
39 - OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论() 39 + OptTypeComment MsgBusinessOpt = 2 // 操作分类-针对评论
40 OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论 40 OptTypeDiscussion MsgBusinessOpt = 3 // 操作分类-针对讨论
41 ) 41 )
42 42