...
|
...
|
@@ -5,6 +5,9 @@ import ( |
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
)
|
...
|
...
|
@@ -25,7 +28,63 @@ func NewMiniArticleSetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) |
|
|
|
|
|
// 设置文章的定性标签
|
|
|
func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagRequest) (resp *types.MiniArticleSetTagResponse, err error) {
|
|
|
|
|
|
var conn = l.svcCtx.DefaultDBConn()
|
|
|
//
|
|
|
return
|
|
|
articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取文章信息失败", err)
|
|
|
}
|
|
|
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("获取标签信息失败")
|
|
|
}
|
|
|
// 查询可能存在的 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 {
|
|
|
_, err = l.svcCtx.ArticleAndTagRepository.Delete(ctx, c, v)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
// 更新article
|
|
|
_, err = l.svcCtx.ArticleRepository.UpdateWithVersion(ctx, c, articleInfo)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
_, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTag)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}, true)
|
|
|
|
|
|
resp = &types.MiniArticleSetTagResponse{
|
|
|
Id: articleAndTag.Id,
|
|
|
}
|
|
|
return resp, nil
|
|
|
} |
...
|
...
|
|