正在显示
6 个修改的文件
包含
74 行增加
和
15 行删除
@@ -2,6 +2,7 @@ package article | @@ -2,6 +2,7 @@ package article | ||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "context" | 4 | "context" |
5 | + | ||
5 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | 6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" |
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" |
7 | 8 | ||
@@ -25,6 +26,7 @@ func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext | @@ -25,6 +26,7 @@ func NewMiniArticleMarkListLogic(ctx context.Context, svcCtx *svc.ServiceContext | ||
25 | } | 26 | } |
26 | } | 27 | } |
27 | 28 | ||
29 | +// 获取我的文章浏览记录 | ||
28 | func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMarkListRequest) (resp *types.MiniArticleMarkListResponse, err error) { | 30 | func (l *MiniArticleMarkListLogic) MiniArticleMarkList(req *types.MiniArticleMarkListRequest) (resp *types.MiniArticleMarkListResponse, err error) { |
29 | var userToken = contextdata.GetUserTokenFromCtx(l.ctx) | 31 | var userToken = contextdata.GetUserTokenFromCtx(l.ctx) |
30 | 32 |
@@ -5,6 +5,9 @@ import ( | @@ -5,6 +5,9 @@ import ( | ||
5 | 5 | ||
6 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | 6 | "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" | 7 | "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" |
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
8 | 11 | ||
9 | "github.com/zeromicro/go-zero/core/logx" | 12 | "github.com/zeromicro/go-zero/core/logx" |
10 | ) | 13 | ) |
@@ -25,7 +28,57 @@ func NewMiniArticleSetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) | @@ -25,7 +28,57 @@ func NewMiniArticleSetTagLogic(ctx context.Context, svcCtx *svc.ServiceContext) | ||
25 | 28 | ||
26 | // 设置文章的定性标签 | 29 | // 设置文章的定性标签 |
27 | func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagRequest) (resp *types.MiniArticleSetTagResponse, err error) { | 30 | func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagRequest) (resp *types.MiniArticleSetTagResponse, err error) { |
28 | - | 31 | + var conn = l.svcCtx.DefaultDBConn() |
29 | // | 32 | // |
30 | - return | 33 | + articleInfo, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.ArticleId) |
34 | + if err != nil { | ||
35 | + return nil, xerr.NewErrMsgErr("获取文章信息失败", err) | ||
36 | + } | ||
37 | + | ||
38 | + tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId) | ||
39 | + if err != nil { | ||
40 | + return nil, xerr.NewErrMsgErr("获取标签信息失败", err) | ||
41 | + } | ||
42 | + | ||
43 | + // 查询可能存在的 ArticleAndTag | ||
44 | + queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id) | ||
45 | + _, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption) | ||
46 | + if err != nil { | ||
47 | + return nil, xerr.NewErrMsgErr("检查文章的标签失败", err) | ||
48 | + } | ||
49 | + | ||
50 | + articleInfo.Tags = []int64{tagInfo.Id} | ||
51 | + // 额外保存一份ArticleAndTag | ||
52 | + articleAndTag := domain.ArticleAndTag{ | ||
53 | + Id: 0, | ||
54 | + CompanyId: articleInfo.CompanyId, | ||
55 | + CreatedAt: 0, | ||
56 | + UpdatedAt: 0, | ||
57 | + ArticleId: articleInfo.Id, | ||
58 | + TagId: tagInfo.Id, | ||
59 | + } | ||
60 | + err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | ||
61 | + //清理可能存在的 ArticleAndTag | ||
62 | + for _, v := range oldTags { | ||
63 | + _, err = l.svcCtx.ArticleAndTagRepository.Delete(ctx, c, v) | ||
64 | + if err != nil { | ||
65 | + return err | ||
66 | + } | ||
67 | + } | ||
68 | + // 更新article | ||
69 | + _, err = l.svcCtx.ArticleRepository.UpdateWithVersion(ctx, c, articleInfo) | ||
70 | + if err != nil { | ||
71 | + return err | ||
72 | + } | ||
73 | + _, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTag) | ||
74 | + if err != nil { | ||
75 | + return err | ||
76 | + } | ||
77 | + return nil | ||
78 | + }, true) | ||
79 | + | ||
80 | + resp = &types.MiniArticleSetTagResponse{ | ||
81 | + Id: articleAndTag.Id, | ||
82 | + } | ||
83 | + return resp, nil | ||
31 | } | 84 | } |
@@ -26,6 +26,7 @@ type ServiceContext struct { | @@ -26,6 +26,7 @@ type ServiceContext struct { | ||
26 | ArticleRepository domain.ArticleRepository | 26 | ArticleRepository domain.ArticleRepository |
27 | ArticleSectionRepository domain.ArticleSectionRepository | 27 | ArticleSectionRepository domain.ArticleSectionRepository |
28 | ArticleTagRepository domain.ArticleTagRepository | 28 | ArticleTagRepository domain.ArticleTagRepository |
29 | + ArticleAndTagRepository domain.ArticleAndTagRepository | ||
29 | 30 | ||
30 | CompanyRepository domain.CompanyRepository | 31 | CompanyRepository domain.CompanyRepository |
31 | CommentRepository domain.CommentRepository // 待移除 | 32 | CommentRepository domain.CommentRepository // 待移除 |
@@ -59,12 +60,14 @@ func NewServiceContext(c config.Config) *ServiceContext { | @@ -59,12 +60,14 @@ func NewServiceContext(c config.Config) *ServiceContext { | ||
59 | ApiAuthService: apiAuth, | 60 | ApiAuthService: apiAuth, |
60 | LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, | 61 | LoginStatusCheck: middleware.NewLoginStatusCheckMiddleware(apiAuth).Handle, |
61 | 62 | ||
62 | - CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)), | ||
63 | - ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), | ||
64 | - ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), | ||
65 | - ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)), | ||
66 | - ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)), | ||
67 | - ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)), | 63 | + CommentRepository: repository.NewCommentRepository(cache.NewCachedRepository(mlCache)), |
64 | + ArticleBackupRepository: repository.NewArticleBackupRepository(cache.NewCachedRepository(mlCache)), | ||
65 | + ArticleCommentRepository: repository.NewArticleCommentRepository(cache.NewCachedRepository(mlCache)), | ||
66 | + ArticleDraftRepository: repository.NewArticleDraftRepository(cache.NewCachedRepository(mlCache)), | ||
67 | + ArticleRepository: repository.NewArticleRepository(cache.NewCachedRepository(mlCache)), | ||
68 | + ArticleSectionRepository: repository.NewArticleSectionRepository(cache.NewCachedRepository(mlCache)), | ||
69 | + ArticleAndTagRepository: repository.NewArticleAndTagRepository(cache.NewCachedRepository(mlCache)), | ||
70 | + | ||
68 | CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)), | 71 | CompanyRepository: repository.NewCompanyRepository(cache.NewCachedRepository(mlCache)), |
69 | DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)), | 72 | DepartmentRepository: repository.NewDepartmentRepository(cache.NewCachedRepository(mlCache)), |
70 | MessageBusinessRepository: repository.NewMessageBusinessRepository(cache.NewCachedRepository(mlCache)), | 73 | MessageBusinessRepository: repository.NewMessageBusinessRepository(cache.NewCachedRepository(mlCache)), |
@@ -97,6 +97,9 @@ func (repository *ArticleAndTagRepository) Find(ctx context.Context, conn transa | @@ -97,6 +97,9 @@ func (repository *ArticleAndTagRepository) Find(ctx context.Context, conn transa | ||
97 | ) | 97 | ) |
98 | queryFunc := func() (interface{}, error) { | 98 | queryFunc := func() (interface{}, error) { |
99 | tx = tx.Model(&ms).Order("id desc") | 99 | tx = tx.Model(&ms).Order("id desc") |
100 | + if v, ok := queryOptions["articleId"]; ok { | ||
101 | + tx = tx.Where("article_id=?", v) | ||
102 | + } | ||
100 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 103 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
101 | return dms, tx.Error | 104 | return dms, tx.Error |
102 | } | 105 | } |
@@ -14,8 +14,8 @@ type ArticleBackup struct { | @@ -14,8 +14,8 @@ type ArticleBackup struct { | ||
14 | UpdatedAt int64 `json:"updatedAt,omitempty"` | 14 | UpdatedAt int64 `json:"updatedAt,omitempty"` |
15 | DeletedAt int64 `json:"deletedAt,omitempty"` | 15 | DeletedAt int64 `json:"deletedAt,omitempty"` |
16 | Version int `json:"version,omitempty"` | 16 | Version int `json:"version,omitempty"` |
17 | - Operator UserSimple `json:"operator"` // 操作人 | ||
18 | - ArticleId int64 `json:"articleId"` | 17 | + Operator UserSimple `json:"operator"` // 操作人 |
18 | + ArticleId int64 `json:"articleId"` // | ||
19 | Title string `json:"title"` // 标题 | 19 | Title string `json:"title"` // 标题 |
20 | Section []ArticleSection `json:"section"` // 分段内容 | 20 | Section []ArticleSection `json:"section"` // 分段内容 |
21 | Images []Image `json:"images"` // 图片 | 21 | Images []Image `json:"images"` // 图片 |
@@ -29,11 +29,9 @@ type Opinion struct { | @@ -29,11 +29,9 @@ type Opinion struct { | ||
29 | } | 29 | } |
30 | 30 | ||
31 | type UserSimple struct { | 31 | type UserSimple struct { |
32 | - Id int64 `json:"id"` // 人员id | ||
33 | - Name string `json:"name"` // 人员的名字 | ||
34 | - Avatar string `json:"avatar,omitempty"` // 人员头像URL | ||
35 | - // GroupId int64 `json:"groupId"` //分组id | ||
36 | - //Group string `json:"group,omitempty"` // 人员的分组 | 32 | + Id int64 `json:"id"` // 人员id |
33 | + Name string `json:"name"` // 人员的名字 | ||
34 | + Avatar string `json:"avatar,omitempty"` // 人员头像URL | ||
37 | Position string `json:"position,omitempty"` // 职位 | 35 | Position string `json:"position,omitempty"` // 职位 |
38 | Company string `json:"company,omitempty"` // 公司 | 36 | Company string `json:"company,omitempty"` // 公司 |
39 | CompanyId int64 `json:"companyId"` | 37 | CompanyId int64 `json:"companyId"` |
-
请 注册 或 登录 后发表评论