|
@@ -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,24 +39,18 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR |
|
@@ -38,24 +39,18 @@ 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)
|
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)
|
43
|
if err != nil {
|
47
|
if err != nil {
|
44
|
return nil, xerr.NewErrMsgErr("获取标签信息失败", err)
|
48
|
return nil, xerr.NewErrMsgErr("获取标签信息失败", err)
|
45
|
}
|
49
|
}
|
46
|
-
|
|
|
47
|
if tagInfo.CompanyId != req.CompanyId {
|
50
|
if tagInfo.CompanyId != req.CompanyId {
|
48
|
return nil, xerr.NewErrMsg("获取标签信息失败")
|
51
|
return nil, xerr.NewErrMsg("获取标签信息失败")
|
49
|
}
|
52
|
}
|
50
|
- // 查询可能存在的 ArticleAndTag
|
|
|
51
|
- queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id)
|
|
|
52
|
- _, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption)
|
|
|
53
|
- if err != nil {
|
|
|
54
|
- return nil, xerr.NewErrMsgErr("检查文章的标签失败", err)
|
|
|
55
|
- }
|
|
|
56
|
- // 更新article中的tags
|
|
|
57
|
- articleInfo.Tags = []int64{tagInfo.Id}
|
|
|
58
|
- // 额外保存一份ArticleAndTag
|
53
|
+ tagIdList = append(tagIdList, tagInfo.Id)
|
59
|
articleAndTag := domain.ArticleAndTag{
|
54
|
articleAndTag := domain.ArticleAndTag{
|
60
|
Id: 0,
|
55
|
Id: 0,
|
61
|
CompanyId: articleInfo.CompanyId,
|
56
|
CompanyId: articleInfo.CompanyId,
|
|
@@ -64,6 +59,17 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR |
|
@@ -64,6 +59,17 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR |
64
|
ArticleId: articleInfo.Id,
|
59
|
ArticleId: articleInfo.Id,
|
65
|
TagId: tagInfo.Id,
|
60
|
TagId: tagInfo.Id,
|
66
|
}
|
61
|
}
|
|
|
62
|
+ articleAndTagList = append(articleAndTagList, articleAndTag)
|
|
|
63
|
+ }
|
|
|
64
|
+ //更新article中的tags
|
|
|
65
|
+ articleInfo.Tags = tagIdList
|
|
|
66
|
+ // 查询可能存在的 ArticleAndTag
|
|
|
67
|
+ queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id)
|
|
|
68
|
+ _, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption)
|
|
|
69
|
+ if err != nil {
|
|
|
70
|
+ return nil, xerr.NewErrMsgErr("检查文章的标签失败", err)
|
|
|
71
|
+ }
|
|
|
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)
|
86
|
+ for i := range articleAndTagList {
|
|
|
87
|
+ _, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTagList[i])
|
81
|
if err != nil {
|
88
|
if err != nil {
|
82
|
return err
|
89
|
return err
|
83
|
}
|
90
|
}
|
84
|
-
|
91
|
+ }
|
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
|
} |