正在显示
1 个修改的文件
包含
26 行增加
和
9 行删除
| @@ -30,10 +30,11 @@ func NewArticleCategoryUpdateLogic(ctx context.Context, svcCtx *svc.ServiceConte | @@ -30,10 +30,11 @@ func NewArticleCategoryUpdateLogic(ctx context.Context, svcCtx *svc.ServiceConte | ||
| 30 | 30 | ||
| 31 | func (l *ArticleCategoryUpdateLogic) ArticleCategoryUpdate(req *types.ArticleCategoryUpdateRequest) (resp *types.ArticleCategoryUpdateResponse, err error) { | 31 | func (l *ArticleCategoryUpdateLogic) ArticleCategoryUpdate(req *types.ArticleCategoryUpdateRequest) (resp *types.ArticleCategoryUpdateResponse, err error) { |
| 32 | var ( | 32 | var ( |
| 33 | - conn = l.svcCtx.DefaultDBConn() | ||
| 34 | - dm *domain.ArticleCategory | ||
| 35 | - dupDm *domain.ArticleCategory | ||
| 36 | - userToken = contextdata.GetUserTokenFromCtx(l.ctx) | 33 | + conn = l.svcCtx.DefaultDBConn() |
| 34 | + dm *domain.ArticleCategory | ||
| 35 | + dupDm *domain.ArticleCategory | ||
| 36 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
| 37 | + changeName = false | ||
| 37 | ) | 38 | ) |
| 38 | if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil { | 39 | if dm, err = l.svcCtx.ArticleCategoryRepository.FindOne(l.ctx, conn, req.Id); err != nil { |
| 39 | return nil, xerr.NewErrMsgErr("不存在", err) | 40 | return nil, xerr.NewErrMsgErr("不存在", err) |
| @@ -43,14 +44,30 @@ func (l *ArticleCategoryUpdateLogic) ArticleCategoryUpdate(req *types.ArticleCat | @@ -43,14 +44,30 @@ func (l *ArticleCategoryUpdateLogic) ArticleCategoryUpdate(req *types.ArticleCat | ||
| 43 | if dupDm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, userToken.CompanyId, req.ArticleCategory.Name); err == nil && dupDm != nil { | 44 | if dupDm, err = l.svcCtx.ArticleCategoryRepository.FindOneByName(l.ctx, conn, userToken.CompanyId, req.ArticleCategory.Name); err == nil && dupDm != nil { |
| 44 | return nil, xerr.NewErrMsg(fmt.Sprintf("已存在分类`%s`", dupDm.Name)) | 45 | return nil, xerr.NewErrMsg(fmt.Sprintf("已存在分类`%s`", dupDm.Name)) |
| 45 | } | 46 | } |
| 47 | + changeName = true | ||
| 46 | } | 48 | } |
| 47 | - // 赋值 | ||
| 48 | - dm.Name = req.ArticleCategory.Name | ||
| 49 | - dm.SortBy = req.ArticleCategory.SortBy | ||
| 50 | - dm.Enable = req.ArticleCategory.Enable | ||
| 51 | - dm.Other = req.ArticleCategory.Other | 49 | + |
| 52 | // 更新 | 50 | // 更新 |
| 53 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | 51 | if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { |
| 52 | + // 同步标签的分类名称 | ||
| 53 | + if changeName { | ||
| 54 | + _, articleTags, _ := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, userToken.CompanyId, domain.NewQueryOptions().MustWithKV("name", dm.Name)) | ||
| 55 | + for _, articleTag := range articleTags { | ||
| 56 | + if articleTag.Name != dm.Name || articleTag.CategoryId != dm.Id { | ||
| 57 | + continue | ||
| 58 | + } | ||
| 59 | + // 新的分类名称 | ||
| 60 | + articleTag.Category = req.ArticleCategory.Name | ||
| 61 | + if _, err = l.svcCtx.ArticleTagRepository.UpdateWithVersion(l.ctx, conn, articleTag); err != nil { | ||
| 62 | + return err | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + // 赋值 | ||
| 67 | + dm.Name = req.ArticleCategory.Name | ||
| 68 | + dm.SortBy = req.ArticleCategory.SortBy | ||
| 69 | + dm.Enable = req.ArticleCategory.Enable | ||
| 70 | + dm.Other = req.ArticleCategory.Other | ||
| 54 | dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm) | 71 | dm, err = l.svcCtx.ArticleCategoryRepository.UpdateWithVersion(l.ctx, conn, dm) |
| 55 | return err | 72 | return err |
| 56 | }, true); err != nil { | 73 | }, true); err != nil { |
-
请 注册 或 登录 后发表评论