正在显示
5 个修改的文件
包含
71 行增加
和
41 行删除
@@ -201,12 +201,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | @@ -201,12 +201,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | ||
201 | } | 201 | } |
202 | } | 202 | } |
203 | // 设置保存备份 | 203 | // 设置保存备份 |
204 | - backup := newArticle.MakeBackup(newArticle.Author, sectionList) | ||
205 | - backup.Action = "新增" | ||
206 | - _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup) | ||
207 | - if err != nil { | ||
208 | - return xerr.NewErrMsgErr("创建文章内容失败", err) | ||
209 | - } | 204 | + // backup := newArticle.MakeBackup(newArticle.Author, sectionList) |
205 | + // backup.Action = "新增" | ||
206 | + // _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup) | ||
207 | + // if err != nil { | ||
208 | + // return xerr.NewErrMsgErr("创建文章内容失败", err) | ||
209 | + // } | ||
210 | return nil | 210 | return nil |
211 | }, true) | 211 | }, true) |
212 | if err != nil { | 212 | if err != nil { |
@@ -38,8 +38,18 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -38,8 +38,18 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
38 | if articleInfo.CompanyId != req.CompanyId { | 38 | if articleInfo.CompanyId != req.CompanyId { |
39 | return nil, xerr.NewErrMsg("没有查看权限") | 39 | return nil, xerr.NewErrMsg("没有查看权限") |
40 | } | 40 | } |
41 | - //TODO 检查可查看人 | ||
42 | - if articleInfo.Show == domain.ArticleShowDisable { | 41 | + |
42 | + inWhoRead := false | ||
43 | + | ||
44 | + if len(articleInfo.WhoRead) > 0 { | ||
45 | + for _, val := range articleInfo.WhoRead { | ||
46 | + if req.UserId == int(val) { | ||
47 | + inWhoRead = true | ||
48 | + } | ||
49 | + } | ||
50 | + } | ||
51 | + | ||
52 | + if articleInfo.Show == domain.ArticleShowDisable || !inWhoRead { | ||
43 | // 文章内容不显示 | 53 | // 文章内容不显示 |
44 | resp = &types.MiniArticleGetResponse{ | 54 | resp = &types.MiniArticleGetResponse{ |
45 | Id: articleInfo.Id, | 55 | Id: articleInfo.Id, |
@@ -81,6 +91,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -81,6 +91,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
81 | 91 | ||
82 | follow, _ := l.svcCtx.UserFollowRepository.FindOneUserFollowing(l.ctx, conn, int64(req.UserId), articleInfo.AuthorId) | 92 | follow, _ := l.svcCtx.UserFollowRepository.FindOneUserFollowing(l.ctx, conn, int64(req.UserId), articleInfo.AuthorId) |
83 | 93 | ||
94 | + queryOption = domain.NewQueryOptions().WithFindOnly().WithOffsetLimit(1, 1).WithKV("articleId", articleInfo.Id) | ||
95 | + _, backupList, _ := l.svcCtx.ArticleBackupRepository.Find(l.ctx, conn, queryOption) | ||
96 | + | ||
84 | sortBy := domain.SortArticleSection(sectionList) | 97 | sortBy := domain.SortArticleSection(sectionList) |
85 | sort.Sort(sortBy) | 98 | sort.Sort(sortBy) |
86 | articleSection := []types.ArticleSection{} | 99 | articleSection := []types.ArticleSection{} |
@@ -124,7 +137,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | @@ -124,7 +137,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) ( | ||
124 | Tags: tags, | 137 | Tags: tags, |
125 | MatchUrl: map[string]string{}, | 138 | MatchUrl: map[string]string{}, |
126 | } | 139 | } |
127 | - if articleInfo.CreatedAt != articleInfo.UpdatedAt { | 140 | + if len(backupList) > 0 { |
128 | resp.Edit = 1 | 141 | resp.Edit = 1 |
129 | } | 142 | } |
130 | 143 |
@@ -36,10 +36,30 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl | @@ -36,10 +36,30 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl | ||
36 | if err != nil { | 36 | if err != nil { |
37 | return nil, xerr.NewErrMsgErr("获取编辑历史记录失败", err) | 37 | return nil, xerr.NewErrMsgErr("获取编辑历史记录失败", err) |
38 | } | 38 | } |
39 | + //获取当前用户信息 | ||
40 | + userToken := contextdata.GetUserTokenFromCtx(l.ctx) | ||
41 | + userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken}) | ||
42 | + if err != nil { | ||
43 | + return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err) | ||
44 | + } | ||
39 | article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, backup.ArticleId) | 45 | article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, backup.ArticleId) |
40 | if err != nil { | 46 | if err != nil { |
41 | return nil, xerr.NewErrMsgErr("获取文章失败", err) | 47 | return nil, xerr.NewErrMsgErr("获取文章失败", err) |
42 | } | 48 | } |
49 | + _, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, conn, map[string]interface{}{"articleId": article.Id}) | ||
50 | + if err != nil { | ||
51 | + return nil, xerr.NewErrMsgErr("获取文章段落内容失败", err) | ||
52 | + } | ||
53 | + // 备份数据 | ||
54 | + newBackUp := article.MakeBackup(domain.UserSimple{ | ||
55 | + Id: userToken.UserId, | ||
56 | + Name: userMe.User.NickName, | ||
57 | + Avatar: userMe.User.Avatar, | ||
58 | + CompanyId: userToken.CompanyId, | ||
59 | + Company: userMe.CurrentCompany.Name, | ||
60 | + }, sectionList) | ||
61 | + newBackUp.Action = "恢复" | ||
62 | + | ||
43 | article.Version = article.Version + 1 | 63 | article.Version = article.Version + 1 |
44 | article.Images = backup.Images | 64 | article.Images = backup.Images |
45 | article.Title = backup.Title | 65 | article.Title = backup.Title |
@@ -55,12 +75,7 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl | @@ -55,12 +75,7 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl | ||
55 | SortBy: item.SortBy, | 75 | SortBy: item.SortBy, |
56 | }) | 76 | }) |
57 | }) | 77 | }) |
58 | - //获取当前用户信息 | ||
59 | - userToken := contextdata.GetUserTokenFromCtx(l.ctx) | ||
60 | - userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken}) | ||
61 | - if err != nil { | ||
62 | - return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err) | ||
63 | - } | 78 | + |
64 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 79 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
65 | //保存文章 | 80 | //保存文章 |
66 | _, err = l.svcCtx.ArticleRepository.Update(ctx, c, article) | 81 | _, err = l.svcCtx.ArticleRepository.Update(ctx, c, article) |
@@ -93,15 +108,7 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl | @@ -93,15 +108,7 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl | ||
93 | return xerr.NewErrMsgErr("保存文章内容失败", err) | 108 | return xerr.NewErrMsgErr("保存文章内容失败", err) |
94 | } | 109 | } |
95 | } | 110 | } |
96 | - //备份数据 | ||
97 | - newBackUp := article.MakeBackup(domain.UserSimple{ | ||
98 | - Id: userToken.UserId, | ||
99 | - Name: userMe.User.NickName, | ||
100 | - Avatar: userMe.User.Avatar, | ||
101 | - CompanyId: userToken.CompanyId, | ||
102 | - Company: userMe.CurrentCompany.Name, | ||
103 | - }, articleSections) | ||
104 | - newBackUp.Action = "恢复" | 111 | + |
105 | _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, newBackUp) | 112 | _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, newBackUp) |
106 | if err != nil { | 113 | if err != nil { |
107 | return xerr.NewErrMsgErr("恢复文章版本失败", err) | 114 | return xerr.NewErrMsgErr("恢复文章版本失败", err) |
@@ -42,11 +42,30 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | @@ -42,11 +42,30 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | ||
42 | //TargetUser 设定为分发给所有人,清空 WhoRead | 42 | //TargetUser 设定为分发给所有人,清空 WhoRead |
43 | req.WhoRead = make([]int64, 0) | 43 | req.WhoRead = make([]int64, 0) |
44 | } | 44 | } |
45 | - | 45 | + // 获取当前用户信息 |
46 | + userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken}) | ||
47 | + if err != nil { | ||
48 | + return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err) | ||
49 | + } | ||
50 | + // 文章数据 | ||
46 | article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id) | 51 | article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id) |
47 | if err != nil { | 52 | if err != nil { |
48 | return nil, xerr.NewErrMsgErr("帖子不存在", err) | 53 | return nil, xerr.NewErrMsgErr("帖子不存在", err) |
49 | } | 54 | } |
55 | + _, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, conn, map[string]interface{}{"articleId": article.Id}) | ||
56 | + if err != nil { | ||
57 | + return nil, xerr.NewErrMsgErr("获取文章段落内容失败", err) | ||
58 | + } | ||
59 | + //备份数据 | ||
60 | + backup := article.MakeBackup(domain.UserSimple{ | ||
61 | + Id: userToken.UserId, | ||
62 | + Name: userMe.User.NickName, | ||
63 | + Avatar: userMe.User.Avatar, | ||
64 | + CompanyId: userToken.CompanyId, | ||
65 | + Company: userMe.CurrentCompany.Name, | ||
66 | + }, sectionList) | ||
67 | + backup.Action = "编辑" | ||
68 | + | ||
50 | // 获取图片的尺寸大小 | 69 | // 获取图片的尺寸大小 |
51 | images := []domain.Image{} | 70 | images := []domain.Image{} |
52 | for _, val := range req.Images { | 71 | for _, val := range req.Images { |
@@ -166,11 +185,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | @@ -166,11 +185,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | ||
166 | } | 185 | } |
167 | article.Summary = req.Section[0].Content[0:stringIndex] | 186 | article.Summary = req.Section[0].Content[0:stringIndex] |
168 | } | 187 | } |
169 | - //获取当前用户信息 | ||
170 | - userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken}) | ||
171 | - if err != nil { | ||
172 | - return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err) | ||
173 | - } | 188 | + |
174 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 189 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
175 | _, err = l.svcCtx.ArticleRepository.Update(l.ctx, c, article) | 190 | _, err = l.svcCtx.ArticleRepository.Update(l.ctx, c, article) |
176 | if err != nil { | 191 | if err != nil { |
@@ -207,15 +222,6 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | @@ -207,15 +222,6 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU | ||
207 | return xerr.NewErrMsgErr("保存文章内容失败", err) | 222 | return xerr.NewErrMsgErr("保存文章内容失败", err) |
208 | } | 223 | } |
209 | } | 224 | } |
210 | - //备份数据 | ||
211 | - backup := article.MakeBackup(domain.UserSimple{ | ||
212 | - Id: userToken.UserId, | ||
213 | - Name: userMe.User.NickName, | ||
214 | - Avatar: userMe.User.Avatar, | ||
215 | - CompanyId: userToken.CompanyId, | ||
216 | - Company: userMe.CurrentCompany.Name, | ||
217 | - }, articleSections) | ||
218 | - backup.Action = "编辑" | ||
219 | _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup) | 225 | _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup) |
220 | if err != nil { | 226 | if err != nil { |
221 | return xerr.NewErrMsgErr("保存文章内容失败", err) | 227 | return xerr.NewErrMsgErr("保存文章内容失败", err) |
@@ -94,7 +94,11 @@ func (a ArticleShow) Named() string { | @@ -94,7 +94,11 @@ func (a ArticleShow) Named() string { | ||
94 | } | 94 | } |
95 | 95 | ||
96 | // 设置文章的备份数据 | 96 | // 设置文章的备份数据 |
97 | -func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup { | 97 | +func (m *Article) MakeBackup(operator UserSimple, section []*ArticleSection) *ArticleBackup { |
98 | + sectionBackup := make([]ArticleSection, len(section)) | ||
99 | + for i := range section { | ||
100 | + sectionBackup[i] = *section[i] | ||
101 | + } | ||
98 | b := ArticleBackup{ | 102 | b := ArticleBackup{ |
99 | Id: 0, | 103 | Id: 0, |
100 | CompanyId: m.CompanyId, | 104 | CompanyId: m.CompanyId, |
@@ -105,7 +109,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *Art | @@ -105,7 +109,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *Art | ||
105 | Operator: operator, | 109 | Operator: operator, |
106 | ArticleId: m.Id, | 110 | ArticleId: m.Id, |
107 | Title: m.Title, | 111 | Title: m.Title, |
108 | - Section: section, | 112 | + Section: sectionBackup, |
109 | Images: m.Images, | 113 | Images: m.Images, |
110 | Action: "", | 114 | Action: "", |
111 | TargetUser: m.TargetUser, | 115 | TargetUser: m.TargetUser, |
-
请 注册 或 登录 后发表评论