作者 tangxvhui

调整文章 添加 定性标签的逻辑

@@ -306,10 +306,10 @@ type ( @@ -306,10 +306,10 @@ type (
306 CompanyId int64 `json:",optional"` // 公司id 306 CompanyId int64 `json:",optional"` // 公司id
307 UserId int64 `json:",optional"` // 公司id 307 UserId int64 `json:",optional"` // 公司id
308 ArticleId int64 `json:"articleId"` // 文章id 308 ArticleId int64 `json:"articleId"` // 文章id
309 - TagId int64 `json:"tagId"` // 标签id 309 + TagId []int64 `json:"tagId"` // 标签id
310 } 310 }
311 MiniArticleSetTagResponse { 311 MiniArticleSetTagResponse {
312 - Id int64 `json:"id"` 312 + Id []int64 `json:"id"`
313 } 313 }
314 ) 314 )
315 315
@@ -2,6 +2,7 @@ package article @@ -2,6 +2,7 @@ package article
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"
@@ -38,32 +39,37 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR @@ -38,32 +39,37 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
38 if articleInfo.CompanyId != req.CompanyId { 39 if articleInfo.CompanyId != req.CompanyId {
39 return nil, xerr.NewErrMsg("获取文章信息失败") 40 return nil, xerr.NewErrMsg("获取文章信息失败")
40 } 41 }
41 -  
42 - tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId)  
43 - if err != nil {  
44 - return nil, xerr.NewErrMsgErr("获取标签信息失败", err)  
45 - }  
46 -  
47 - if tagInfo.CompanyId != req.CompanyId {  
48 - return nil, xerr.NewErrMsg("获取标签信息失败") 42 + tagIdList := []int64{}
  43 + // 额外保存一份ArticleAndTag
  44 + var articleAndTagList []domain.ArticleAndTag
  45 + for _, val := range req.TagId {
  46 + tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, val)
  47 + if err != nil {
  48 + return nil, xerr.NewErrMsgErr("获取标签信息失败", err)
  49 + }
  50 + if tagInfo.CompanyId != req.CompanyId {
  51 + return nil, xerr.NewErrMsg("获取标签信息失败")
  52 + }
  53 + tagIdList = append(tagIdList, tagInfo.Id)
  54 + articleAndTag := domain.ArticleAndTag{
  55 + Id: 0,
  56 + CompanyId: articleInfo.CompanyId,
  57 + CreatedAt: 0,
  58 + UpdatedAt: 0,
  59 + ArticleId: articleInfo.Id,
  60 + TagId: tagInfo.Id,
  61 + }
  62 + articleAndTagList = append(articleAndTagList, articleAndTag)
49 } 63 }
  64 + //更新article中的tags
  65 + articleInfo.Tags = tagIdList
50 // 查询可能存在的 ArticleAndTag 66 // 查询可能存在的 ArticleAndTag
51 queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id) 67 queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id)
52 _, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption) 68 _, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption)
53 if err != nil { 69 if err != nil {
54 return nil, xerr.NewErrMsgErr("检查文章的标签失败", err) 70 return nil, xerr.NewErrMsgErr("检查文章的标签失败", err)
55 } 71 }
56 - // 更新article中的tags  
57 - articleInfo.Tags = []int64{tagInfo.Id}  
58 - // 额外保存一份ArticleAndTag  
59 - articleAndTag := domain.ArticleAndTag{  
60 - Id: 0,  
61 - CompanyId: articleInfo.CompanyId,  
62 - CreatedAt: 0,  
63 - UpdatedAt: 0,  
64 - ArticleId: articleInfo.Id,  
65 - TagId: tagInfo.Id,  
66 - } 72 + //
67 err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { 73 err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
68 //清理可能存在的 ArticleAndTag 74 //清理可能存在的 ArticleAndTag
69 for _, v := range oldTags { 75 for _, v := range oldTags {
@@ -77,11 +83,12 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR @@ -77,11 +83,12 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
77 if err != nil { 83 if err != nil {
78 return err 84 return err
79 } 85 }
80 - _, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTag)  
81 - if err != nil {  
82 - return err 86 + for i := range articleAndTagList {
  87 + _, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTagList[i])
  88 + if err != nil {
  89 + return err
  90 + }
83 } 91 }
84 -  
85 // 定性消息通知 92 // 定性消息通知
86 messageLogic := message.NewMiniSystemLogic(ctx, l.svcCtx) 93 messageLogic := message.NewMiniSystemLogic(ctx, l.svcCtx)
87 err = messageLogic.ArticleDefined(c, articleInfo.CompanyId, articleInfo.AuthorId, articleInfo.Title) 94 err = messageLogic.ArticleDefined(c, articleInfo.CompanyId, articleInfo.AuthorId, articleInfo.Title)
@@ -93,7 +100,10 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR @@ -93,7 +100,10 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
93 }, true) 100 }, true)
94 101
95 resp = &types.MiniArticleSetTagResponse{ 102 resp = &types.MiniArticleSetTagResponse{
96 - Id: articleAndTag.Id, 103 + Id: []int64{},
  104 + }
  105 + for _, val := range articleAndTagList {
  106 + resp.Id = append(resp.Id, val.Id)
97 } 107 }
98 return resp, nil 108 return resp, nil
99 } 109 }
@@ -1062,14 +1062,14 @@ type MiniArticleMarkItem struct { @@ -1062,14 +1062,14 @@ type MiniArticleMarkItem struct {
1062 } 1062 }
1063 1063
1064 type MiniArticleSetTagRequest struct { 1064 type MiniArticleSetTagRequest struct {
1065 - CompanyId int64 `json:",optional"` // 公司id  
1066 - UserId int64 `json:",optional"` // 公司id  
1067 - ArticleId int64 `json:"articleId"` // 文章id  
1068 - TagId int64 `json:"tagId"` // 标签id 1065 + CompanyId int64 `json:",optional"` // 公司id
  1066 + UserId int64 `json:",optional"` // 公司id
  1067 + ArticleId int64 `json:"articleId"` // 文章id
  1068 + TagId []int64 `json:"tagId"` // 标签id
1069 } 1069 }
1070 1070
1071 type MiniArticleSetTagResponse struct { 1071 type MiniArticleSetTagResponse struct {
1072 - Id int64 `json:"id"` 1072 + Id []int64 `json:"id"`
1073 } 1073 }
1074 1074
1075 type MiniAllArticleTagRequest struct { 1075 type MiniAllArticleTagRequest struct {