作者 yangfu
@@ -313,14 +313,16 @@ type ( @@ -313,14 +313,16 @@ type (
313 TagId int64 `json:"tagId"` // 标签id 313 TagId int64 `json:"tagId"` // 标签id
314 } 314 }
315 MiniAllArticleTagResponse{ 315 MiniAllArticleTagResponse{
316 - TagGroup []string `json:"tagGroup"`  
317 - Tags []ArticleTagItem `json:"tags"` 316 + TagGroup []ArticleTagGroup `json:"tagGroup"`
318 } 317 }
319 - 318 + ArticleTagGroup {
  319 + Group string `json:"group"`
  320 + Tags []ArticleTagItem `json:"tags"`
  321 + }
320 ArticleTagItem { 322 ArticleTagItem {
321 Id int64 `json:"id"` 323 Id int64 `json:"id"`
322 Group string `json:"group"` 324 Group string `json:"group"`
323 - Name string `json:"name"` 325 + Name string `json:"name"`
324 } 326 }
325 ) 327 )
326 328
@@ -7,6 +7,8 @@ import ( @@ -7,6 +7,8 @@ import (
7 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" 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" 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" 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"
10 ) 12 )
11 13
12 func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { 14 func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -18,11 +20,10 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -18,11 +20,10 @@ func MiniArticleCommentAtWhoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
18 } 20 }
19 21
20 l := comment.NewMiniArticleCommentAtWhoLogic(r.Context(), svcCtx) 22 l := comment.NewMiniArticleCommentAtWhoLogic(r.Context(), svcCtx)
  23 + token := contextdata.GetUserTokenFromCtx(r.Context())
  24 + req.CompanyId = token.CompanyId
  25 + req.UserId = token.UserId
21 resp, err := l.MiniArticleCommentAtWho(&req) 26 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 + result.HttpResult(r, w, resp, err)
27 } 28 }
28 } 29 }
@@ -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 {
@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ 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/pkg/xerr"
8 9
9 "github.com/zeromicro/go-zero/core/logx" 10 "github.com/zeromicro/go-zero/core/logx"
10 ) 11 )
@@ -24,7 +25,21 @@ func NewMiniArticleCommentAtWhoLogic(ctx context.Context, svcCtx *svc.ServiceCon @@ -24,7 +25,21 @@ func NewMiniArticleCommentAtWhoLogic(ctx context.Context, svcCtx *svc.ServiceCon
24 } 25 }
25 26
26 func (l *MiniArticleCommentAtWhoLogic) MiniArticleCommentAtWho(req *types.MiniArticleCommentAtWhoRequest) (resp *types.MiniArticleCommentAtWhoResponse, err error) { 27 func (l *MiniArticleCommentAtWhoLogic) MiniArticleCommentAtWho(req *types.MiniArticleCommentAtWhoRequest) (resp *types.MiniArticleCommentAtWhoResponse, err error) {
27 - // todo: add your logic here and delete this line 28 + var conn = l.svcCtx.DefaultDBConn()
  29 + articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
  30 + if err != nil {
  31 + return nil, xerr.NewErrMsgErr("获取评论人信息失败", err)
  32 + }
  33 + if articleInfo.CompanyId != req.CompanyId {
  34 + resp = &types.MiniArticleCommentAtWhoResponse{}
  35 + return resp, nil
  36 + }
  37 +
  38 + // userList := []*domain.User{}
  39 + // if len(articleInfo.WhoRead) == 0 {
  40 +
  41 + // return
  42 + // }
28 43
29 return 44 return
30 } 45 }
@@ -2,6 +2,7 @@ package comment @@ -2,6 +2,7 @@ package comment
2 2
3 import ( 3 import (
4 "context" 4 "context"
  5 +
5 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message" 6 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
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"
@@ -12,6 +13,7 @@ import ( @@ -12,6 +13,7 @@ import (
12 13
13 "text/template" 14 "text/template"
14 15
  16 + "github.com/samber/lo"
15 "github.com/zeromicro/go-zero/core/logx" 17 "github.com/zeromicro/go-zero/core/logx"
16 ) 18 )
17 19
@@ -88,11 +90,15 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -88,11 +90,15 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
88 for _, val := range req.AtWho { 90 for _, val := range req.AtWho {
89 atWhoIds = append(atWhoIds, val.Id) 91 atWhoIds = append(atWhoIds, val.Id)
90 } 92 }
  93 + atWhoIds = lo.Uniq(atWhoIds)
91 queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", atWhoIds) 94 queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", atWhoIds)
92 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption) 95 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
93 if err != nil { 96 if err != nil {
94 return nil, xerr.NewErrMsgErr("检查@的人员失败", err) 97 return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
95 } 98 }
  99 + if len(atWhoIds) != len(atWhoList) {
  100 + return nil, xerr.NewErrMsg("检查@的人员失败")
  101 + }
96 } 102 }
97 // 处理文本内容 103 // 处理文本内容
98 content := template.HTMLEscapeString(req.Content) 104 content := template.HTMLEscapeString(req.Content)
@@ -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 +}
@@ -852,8 +852,12 @@ type MiniAllArticleTagRequest struct { @@ -852,8 +852,12 @@ type MiniAllArticleTagRequest struct {
852 } 852 }
853 853
854 type MiniAllArticleTagResponse struct { 854 type MiniAllArticleTagResponse struct {
855 - TagGroup []string `json:"tagGroup"`  
856 - Tags []ArticleTagItem `json:"tags"` 855 + TagGroup []ArticleTagGroup `json:"tagGroup"`
  856 +}
  857 +
  858 +type ArticleTagGroup struct {
  859 + Group string `json:"group"`
  860 + Tags []ArticleTagItem `json:"tags"`
857 } 861 }
858 862
859 type ArticleTagItem struct { 863 type ArticleTagItem struct {
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 "gorm.io/gorm" 8 "gorm.io/gorm"
9 ) 9 )
10 10
  11 +// 保存文章和标签的关系,主要用于分组统计用
11 type ArticleAndTag struct { 12 type ArticleAndTag struct {
12 Id int64 // 唯一标识 13 Id int64 // 唯一标识
13 CompanyId int64 `json:"companyId"` 14 CompanyId int64 `json:"companyId"`
@@ -28,7 +29,7 @@ func (m *ArticleAndTag) BeforeCreate(tx *gorm.DB) (err error) { @@ -28,7 +29,7 @@ func (m *ArticleAndTag) BeforeCreate(tx *gorm.DB) (err error) {
28 } 29 }
29 30
30 func (m *ArticleAndTag) BeforeUpdate(tx *gorm.DB) (err error) { 31 func (m *ArticleAndTag) BeforeUpdate(tx *gorm.DB) (err error) {
31 - // m.UpdatedAt = time.Now().Unix() 32 + m.UpdatedAt = time.Now().Unix()
32 return 33 return
33 } 34 }
34 35
@@ -22,6 +22,7 @@ type ArticleTag struct { @@ -22,6 +22,7 @@ type ArticleTag struct {
22 Name string // 标签名称 22 Name string // 标签名称
23 Group string // 标签分类 23 Group string // 标签分类
24 Remark string // 备注 24 Remark string // 备注
  25 + SortBy int64 // 顺序
25 } 26 }
26 27
27 func (m *ArticleTag) TableName() string { 28 func (m *ArticleTag) TableName() string {
@@ -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 }
@@ -19,6 +19,7 @@ type ArticleTag struct { @@ -19,6 +19,7 @@ type ArticleTag struct {
19 Name string `json:"name"` // 标签名称 19 Name string `json:"name"` // 标签名称
20 Group string `json:"group"` // 标签分类 20 Group string `json:"group"` // 标签分类
21 Remark string `json:"remark"` // 备注 21 Remark string `json:"remark"` // 备注
  22 + SortBy int64 `json:"sortBy"` // 顺序
22 } 23 }
23 type ArticleTagRepository interface { 24 type ArticleTagRepository interface {
24 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) 25 Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error)
@@ -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