作者 tangxvhui

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

... ... @@ -306,10 +306,10 @@ type (
CompanyId int64 `json:",optional"` // 公司id
UserId int64 `json:",optional"` // 公司id
ArticleId int64 `json:"articleId"` // 文章id
TagId int64 `json:"tagId"` // 标签id
TagId []int64 `json:"tagId"` // 标签id
}
MiniArticleSetTagResponse {
Id int64 `json:"id"`
Id []int64 `json:"id"`
}
)
... ...
... ... @@ -2,6 +2,7 @@ package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -38,32 +39,37 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取文章信息失败")
}
tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取标签信息失败", err)
}
if tagInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取标签信息失败")
tagIdList := []int64{}
// 额外保存一份ArticleAndTag
var articleAndTagList []domain.ArticleAndTag
for _, val := range req.TagId {
tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, val)
if err != nil {
return nil, xerr.NewErrMsgErr("获取标签信息失败", err)
}
if tagInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取标签信息失败")
}
tagIdList = append(tagIdList, tagInfo.Id)
articleAndTag := domain.ArticleAndTag{
Id: 0,
CompanyId: articleInfo.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
ArticleId: articleInfo.Id,
TagId: tagInfo.Id,
}
articleAndTagList = append(articleAndTagList, articleAndTag)
}
//更新article中的tags
articleInfo.Tags = tagIdList
// 查询可能存在的 ArticleAndTag
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id)
_, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("检查文章的标签失败", err)
}
// 更新article中的tags
articleInfo.Tags = []int64{tagInfo.Id}
// 额外保存一份ArticleAndTag
articleAndTag := domain.ArticleAndTag{
Id: 0,
CompanyId: articleInfo.CompanyId,
CreatedAt: 0,
UpdatedAt: 0,
ArticleId: articleInfo.Id,
TagId: tagInfo.Id,
}
//
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//清理可能存在的 ArticleAndTag
for _, v := range oldTags {
... ... @@ -77,11 +83,12 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
if err != nil {
return err
}
_, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTag)
if err != nil {
return err
for i := range articleAndTagList {
_, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTagList[i])
if err != nil {
return err
}
}
// 定性消息通知
messageLogic := message.NewMiniSystemLogic(ctx, l.svcCtx)
err = messageLogic.ArticleDefined(c, articleInfo.CompanyId, articleInfo.AuthorId, articleInfo.Title)
... ... @@ -93,7 +100,10 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
}, true)
resp = &types.MiniArticleSetTagResponse{
Id: articleAndTag.Id,
Id: []int64{},
}
for _, val := range articleAndTagList {
resp.Id = append(resp.Id, val.Id)
}
return resp, nil
}
... ...
... ... @@ -1062,14 +1062,14 @@ type MiniArticleMarkItem struct {
}
type MiniArticleSetTagRequest struct {
CompanyId int64 `json:",optional"` // 公司id
UserId int64 `json:",optional"` // 公司id
ArticleId int64 `json:"articleId"` // 文章id
TagId int64 `json:"tagId"` // 标签id
CompanyId int64 `json:",optional"` // 公司id
UserId int64 `json:",optional"` // 公司id
ArticleId int64 `json:"articleId"` // 文章id
TagId []int64 `json:"tagId"` // 标签id
}
type MiniArticleSetTagResponse struct {
Id int64 `json:"id"`
Id []int64 `json:"id"`
}
type MiniAllArticleTagRequest struct {
... ...