...
|
...
|
@@ -30,10 +30,11 @@ func NewArticleCategoryUpdateLogic(ctx context.Context, svcCtx *svc.ServiceConte |
|
|
|
|
|
func (l *ArticleCategoryUpdateLogic) ArticleCategoryUpdate(req *types.ArticleCategoryUpdateRequest) (resp *types.ArticleCategoryUpdateResponse, err error) {
|
|
|
var (
|
|
|
conn = l.svcCtx.DefaultDBConn()
|
|
|
dm *domain.ArticleCategory
|
|
|
dupDm *domain.ArticleCategory
|
|
|
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
|
|
|
conn = l.svcCtx.DefaultDBConn()
|
|
|
dm *domain.ArticleCategory
|
|
|
dupDm *domain.ArticleCategory
|
|
|
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
|
|
|
changeName = false
|
|
|
)
|
|
|
if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("不存在", err)
|
...
|
...
|
@@ -43,14 +44,30 @@ func (l *ArticleCategoryUpdateLogic) ArticleCategoryUpdate(req *types.ArticleCat |
|
|
if dupDm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, userToken.CompanyId, req.ArticleCategory.Name); err == nil && dupDm != nil {
|
|
|
return nil, xerr.NewErrMsg(fmt.Sprintf("已存在分类`%s`", dupDm.Name))
|
|
|
}
|
|
|
changeName = true
|
|
|
}
|
|
|
// 赋值
|
|
|
dm.Name = req.ArticleCategory.Name
|
|
|
dm.SortBy = req.ArticleCategory.SortBy
|
|
|
dm.Enable = req.ArticleCategory.Enable
|
|
|
dm.Other = req.ArticleCategory.Other
|
|
|
|
|
|
// 更新
|
|
|
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
|
|
|
// 同步标签的分类名称
|
|
|
if changeName {
|
|
|
_, articleTags, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().MustWithKV("categoryId", dm.Id))
|
|
|
for _, articleTag := range articleTags {
|
|
|
if articleTag.CategoryId != dm.Id {
|
|
|
continue
|
|
|
}
|
|
|
// 新的分类名称
|
|
|
articleTag.Category = req.ArticleCategory.Name
|
|
|
if _, err = l.svcCtx.ArticleTagRepository.UpdateWithVersion(l.ctx, conn, articleTag); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 赋值
|
|
|
dm.Name = req.ArticleCategory.Name
|
|
|
dm.SortBy = req.ArticleCategory.SortBy
|
|
|
dm.Enable = req.ArticleCategory.Enable
|
|
|
dm.Other = req.ArticleCategory.Other
|
|
|
dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm)
|
|
|
return err
|
|
|
}, true); err != nil {
|
...
|
...
|
|