...
|
...
|
@@ -57,25 +57,25 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU |
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取当前用户信息失败", err)
|
|
|
}
|
|
|
operator := domain.UserSimple{
|
|
|
Id: userToken.UserId,
|
|
|
Name: userMe.User.NickName,
|
|
|
Avatar: userMe.User.Avatar,
|
|
|
CompanyId: userToken.CompanyId,
|
|
|
Company: userMe.CurrentCompany.Name,
|
|
|
}
|
|
|
// 文章数据
|
|
|
article, err := l.svcCtx.ArticleRepository.FindOne(l.ctx, l.conn, req.Id)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("帖子不存在", err)
|
|
|
}
|
|
|
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, map[string]interface{}{"articleId": article.Id})
|
|
|
//
|
|
|
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", req.Id)
|
|
|
_, sectionList, err := l.svcCtx.ArticleSectionRepository.Find(l.ctx, l.conn, queryOption)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("获取文章段落内容失败", err)
|
|
|
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 = "编辑"
|
|
|
|
|
|
oldBackup := article.MakeBackup(operator, sectionList)
|
|
|
// 获取图片的尺寸大小
|
|
|
images, err := l.getImages(req)
|
|
|
if err != nil {
|
...
|
...
|
@@ -126,6 +126,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU |
|
|
}
|
|
|
//文章内容
|
|
|
updateSectionIds := []int64{}
|
|
|
updateSection := []*domain.ArticleSection{}
|
|
|
for _, item := range articleSections {
|
|
|
if item.Id > 0 {
|
|
|
section, err := l.svcCtx.ArticleSectionRepository.FindOne(ctx, c, item.Id)
|
...
|
...
|
@@ -142,23 +143,30 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU |
|
|
return xerr.NewErrMsgErr("保存文章段落内容失败", err)
|
|
|
}
|
|
|
} else {
|
|
|
_, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, c, &item)
|
|
|
_, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, c, item)
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsgErr("保存文章段落内容失败", err)
|
|
|
}
|
|
|
}
|
|
|
updateSectionIds = append(updateSectionIds, item.Id)
|
|
|
updateSection = append(updateSection, item)
|
|
|
}
|
|
|
if len(updateSectionIds) > 0 {
|
|
|
err = l.svcCtx.ArticleSectionRepository.DeleteBy(ctx, c, domain.NewQueryOptions().WithKV("articleId", article.Id).WithKV("notIds", updateSectionIds))
|
|
|
queryOption := domain.NewQueryOptions().WithKV("articleId", article.Id).WithKV("notIds", updateSectionIds)
|
|
|
err = l.svcCtx.ArticleSectionRepository.DeleteBy(ctx, c, queryOption)
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsgErr("保存文章内容失败", err)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
backup := article.MakeBackup(operator, updateSection)
|
|
|
backup.Action = "编辑"
|
|
|
if ok := backup.CheckChangeField(oldBackup); ok {
|
|
|
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsgErr("保存文章内容失败", err)
|
|
|
}
|
|
|
}
|
|
|
//文章定性
|
|
|
err = l.setTags(c, article)
|
|
|
if err != nil {
|
...
|
...
|
@@ -307,8 +315,8 @@ func (l *SystemUpdateArticleLogic) getVideos(req *types.SystemArticleUpdateReque |
|
|
return videos, nil
|
|
|
}
|
|
|
|
|
|
func (l *SystemUpdateArticleLogic) getSections(req *types.SystemArticleUpdateRequest, article *domain.Article) []domain.ArticleSection {
|
|
|
articleSections := make([]domain.ArticleSection, 0)
|
|
|
func (l *SystemUpdateArticleLogic) getSections(req *types.SystemArticleUpdateRequest, article *domain.Article) []*domain.ArticleSection {
|
|
|
articleSections := make([]*domain.ArticleSection, 0)
|
|
|
sortBy := 1
|
|
|
lo.ForEach(req.Section, func(item types.ArticleSection, index int) {
|
|
|
strList := strings.Split(item.Content, "\n")
|
...
|
...
|
@@ -326,7 +334,7 @@ func (l *SystemUpdateArticleLogic) getSections(req *types.SystemArticleUpdateReq |
|
|
if key == 0 {
|
|
|
section.Id = item.Id
|
|
|
}
|
|
|
articleSections = append(articleSections, section)
|
|
|
articleSections = append(articleSections, §ion)
|
|
|
sortBy++
|
|
|
}
|
|
|
})
|
...
|
...
|
|