Merge branch 'dev' of http://gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss into dev
正在显示
2 个修改的文件
包含
37 行增加
和
16 行删除
@@ -2,7 +2,6 @@ package article | @@ -2,7 +2,6 @@ package article | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | - | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" |
7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
8 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
@@ -26,14 +25,20 @@ func NewMiniAllArticleTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) | @@ -26,14 +25,20 @@ func NewMiniAllArticleTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) | ||
26 | } | 25 | } |
27 | 26 | ||
28 | func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagRequest) (resp *types.MiniAllArticleTagResponse, err error) { | 27 | func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagRequest) (resp *types.MiniAllArticleTagResponse, err error) { |
29 | - var conn = l.svcCtx.DefaultDBConn() | 28 | + var ( |
29 | + conn = l.svcCtx.DefaultDBConn() | ||
30 | + categoryList []*domain.ArticleCategory | ||
31 | + ) | ||
30 | queryOption := domain.NewQueryOptions().WithFindOnly() | 32 | queryOption := domain.NewQueryOptions().WithFindOnly() |
31 | _, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption) | 33 | _, tagList, err := l.svcCtx.ArticleTagRepository.Find(l.ctx, conn, req.CompanyId, queryOption) |
32 | if err != nil { | 34 | if err != nil { |
33 | return nil, xerr.NewErrMsgErr("获取标签列表失败", err) | 35 | return nil, xerr.NewErrMsgErr("获取标签列表失败", err) |
34 | } | 36 | } |
37 | + _, categoryList, err = l.svcCtx.ArticleCategoryRepository.Find(l.ctx, conn, req.CompanyId, domain.NewQueryOptions().MustWithKV("enable", 1)) | ||
38 | + if err != nil { | ||
39 | + return nil, xerr.NewErrMsgErr("获取标签分类列表失败", err) | ||
40 | + } | ||
35 | // 合并输出数据 | 41 | // 合并输出数据 |
36 | - var group []string | ||
37 | tagMap := map[string][]types.ArticleTagItem{} | 42 | tagMap := map[string][]types.ArticleTagItem{} |
38 | for _, val := range tagList { | 43 | for _, val := range tagList { |
39 | if m, ok := tagMap[val.Category]; ok { | 44 | if m, ok := tagMap[val.Category]; ok { |
@@ -46,7 +51,6 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR | @@ -46,7 +51,6 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR | ||
46 | }) | 51 | }) |
47 | tagMap[val.Category] = m | 52 | tagMap[val.Category] = m |
48 | } else { | 53 | } else { |
49 | - group = append(group, val.Category) | ||
50 | tagMap[val.Category] = []types.ArticleTagItem{ | 54 | tagMap[val.Category] = []types.ArticleTagItem{ |
51 | { | 55 | { |
52 | Id: val.Id, | 56 | Id: val.Id, |
@@ -61,10 +65,10 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR | @@ -61,10 +65,10 @@ func (l *MiniAllArticleTagLogic) MiniAllArticleTag(req *types.MiniAllArticleTagR | ||
61 | resp = &types.MiniAllArticleTagResponse{ | 65 | resp = &types.MiniAllArticleTagResponse{ |
62 | TagGroup: make([]types.ArticleTagGroup, 0), | 66 | TagGroup: make([]types.ArticleTagGroup, 0), |
63 | } | 67 | } |
64 | - for i := range group { | 68 | + for _, category := range categoryList { |
65 | resp.TagGroup = append(resp.TagGroup, types.ArticleTagGroup{ | 69 | resp.TagGroup = append(resp.TagGroup, types.ArticleTagGroup{ |
66 | - Category: group[i], | ||
67 | - Tags: tagMap[group[i]], | 70 | + Category: category.Name, |
71 | + Tags: tagMap[category.Name], | ||
68 | }) | 72 | }) |
69 | } | 73 | } |
70 | return resp, nil | 74 | return resp, nil |
@@ -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("categoryId", dm.Id)) | ||
55 | + for _, articleTag := range articleTags { | ||
56 | + if 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 { |
-
请 注册 或 登录 后发表评论