...
|
...
|
@@ -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)
|
...
|
...
|
|