作者 tangxvhui

Merge branch 'dev' into test

... ... @@ -201,12 +201,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
}
}
// 设置保存备份
backup := newArticle.MakeBackup(newArticle.Author, sectionList)
backup.Action = "新增"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
if err != nil {
return xerr.NewErrMsgErr("创建文章内容失败", err)
}
// backup := newArticle.MakeBackup(newArticle.Author, sectionList)
// backup.Action = "新增"
// _, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
// if err != nil {
// return xerr.NewErrMsgErr("创建文章内容失败", err)
// }
return nil
}, true)
if err != nil {
... ...
... ... @@ -38,8 +38,18 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
//TODO 检查可查看人
if articleInfo.Show == domain.ArticleShowDisable {
inWhoRead := false
if len(articleInfo.WhoRead) > 0 {
for _, val := range articleInfo.WhoRead {
if req.UserId == int(val) {
inWhoRead = true
}
}
}
if articleInfo.Show == domain.ArticleShowDisable || !inWhoRead {
// 文章内容不显示
resp = &types.MiniArticleGetResponse{
Id: articleInfo.Id,
... ... @@ -81,6 +91,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
follow, _ := l.svcCtx.UserFollowRepository.FindOneUserFollowing(l.ctx, conn, int64(req.UserId), articleInfo.AuthorId)
queryOption = domain.NewQueryOptions().WithFindOnly().WithOffsetLimit(1, 1).WithKV("articleId", articleInfo.Id)
_, backupList, _ := l.svcCtx.ArticleBackupRepository.Find(l.ctx, conn, queryOption)
sortBy := domain.SortArticleSection(sectionList)
sort.Sort(sortBy)
articleSection := []types.ArticleSection{}
... ... @@ -124,7 +137,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
Tags: tags,
MatchUrl: map[string]string{},
}
if articleInfo.CreatedAt != articleInfo.UpdatedAt {
if len(backupList) > 0 {
resp.Edit = 1
}
... ...
... ... @@ -36,10 +36,30 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl
if err != nil {
return nil, xerr.NewErrMsgErr("获取编辑历史记录失败", err)
}
//获取当前用户信息
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, backup.ArticleId)
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章失败", err)
}
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, conn, map[string]interface{}{"articleId": article.Id})
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章段落内容失败", err)
}
// 备份数据
newBackUp := article.MakeBackup(domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}, sectionList)
newBackUp.Action = "恢复"
article.Version = article.Version + 1
article.Images = backup.Images
article.Title = backup.Title
... ... @@ -55,12 +75,7 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl
SortBy: item.SortBy,
})
})
//获取当前用户信息
userToken := contextdata.GetUserTokenFromCtx(l.ctx)
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//保存文章
_, err = l.svcCtx.ArticleRepository.Update(ctx, c, article)
... ... @@ -93,15 +108,7 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl
return xerr.NewErrMsgErr("保存文章内容失败", err)
}
}
//备份数据
newBackUp := article.MakeBackup(domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}, articleSections)
newBackUp.Action = "恢复"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, newBackUp)
if err != nil {
return xerr.NewErrMsgErr("恢复文章版本失败", err)
... ...
... ... @@ -42,11 +42,30 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
//TargetUser 设定为分发给所有人,清空 WhoRead
req.WhoRead = make([]int64, 0)
}
// 获取当前用户信息
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
// 文章数据
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, conn, req.Id)
if err != nil {
return nil, xerr.NewErrMsgErr("帖子不存在", err)
}
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, conn, map[string]interface{}{"articleId": article.Id})
if err != nil {
return nil, xerr.NewErrMsgErr("获取文章段落内容失败", err)
}
//备份数据
backup := article.MakeBackup(domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}, sectionList)
backup.Action = "编辑"
// 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
... ... @@ -166,11 +185,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
}
article.Summary = req.Section[0].Content[0:stringIndex]
}
//获取当前用户信息
userMe, err := l.svcCtx.ApiAuthService.MeInfo(l.ctx, authlib.RequestUserMeQuery{Token: req.AccessToken})
if err != nil {
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
}
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, c, article)
if err != nil {
... ... @@ -207,15 +222,6 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
return xerr.NewErrMsgErr("保存文章内容失败", err)
}
}
//备份数据
backup := article.MakeBackup(domain.UserSimple{
Id: userToken.UserId,
Name: userMe.User.NickName,
Avatar: userMe.User.Avatar,
CompanyId: userToken.CompanyId,
Company: userMe.CurrentCompany.Name,
}, articleSections)
backup.Action = "编辑"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
if err != nil {
return xerr.NewErrMsgErr("保存文章内容失败", err)
... ...
... ... @@ -94,7 +94,11 @@ func (a ArticleShow) Named() string {
}
// 设置文章的备份数据
func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup {
func (m *Article) MakeBackup(operator UserSimple, section []*ArticleSection) *ArticleBackup {
sectionBackup := make([]ArticleSection, len(section))
for i := range section {
sectionBackup[i] = *section[i]
}
b := ArticleBackup{
Id: 0,
CompanyId: m.CompanyId,
... ... @@ -105,7 +109,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *Art
Operator: operator,
ArticleId: m.Id,
Title: m.Title,
Section: section,
Section: sectionBackup,
Images: m.Images,
Action: "",
TargetUser: m.TargetUser,
... ...