作者 tangxvhui

Merge branch 'dev' into test

... ... @@ -175,19 +175,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
newArticle.MatchUrl[k] = v
}
//设置内容概要
if len(sectionList) > 0 {
// 截取内容 50个字
runeNumber := 0 //字数
stringIndex := 0 //字符串长度
for i := range sectionList[0].Content {
if runeNumber > 50 {
break
}
runeNumber += 1
stringIndex = i
}
newArticle.Summary = sectionList[0].Content[0:stringIndex]
}
newArticle.SetSummary(sectionList)
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
newArticle, err = l.svcCtx.ArticleRepository.Insert(ctx, c, newArticle)
... ...
... ... @@ -77,6 +77,8 @@ func (l *SystemArticleRestoreLogic) SystemArticleRestore(req *types.SystemArticl
})
})
article.SetSummary(articleSections)
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//保存文章
_, err = l.svcCtx.ArticleRepository.Update(ctx, c, article)
... ...
... ... @@ -117,19 +117,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
//文章内容
articleSections := l.getSections(req, article)
//设置内容概要
if len(req.Section) > 0 {
// 截取内容 50个字
runeNumber := 0 //字数
stringIndex := 0 //字符串长度
for i := range req.Section[0].Content {
if runeNumber > 50 {
break
}
runeNumber += 1
stringIndex = i
}
article.Summary = req.Section[0].Content[0:stringIndex]
}
article.SetSummary(articleSections)
err = transaction.UseTrans(l.ctx, l.conn.DB(), func(ctx context.Context, c transaction.Conn) error {
_, err = l.svcCtx.ArticleRepository.Update(l.ctx, c, article)
... ...
... ... @@ -2,6 +2,7 @@ package domain
import (
"context"
"strings"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
)
... ... @@ -128,3 +129,30 @@ func (m *Article) MakeBackup(operator UserSimple, section []*ArticleSection) *Ar
}
return &b
}
func (m *Article) SetSummary(sectionList []ArticleSection) {
if len(sectionList) == 0 {
return
}
//设置内容概要
// 截取内容 50个字
runeNumber := 0 //字数
stringIndex := 0 //字符串长度
content := ""
for i := range sectionList {
str := strings.TrimSpace(sectionList[i].Content)
if len(str) > 0 {
content = str
break
}
}
for i := range content {
if runeNumber > 50 {
break
}
runeNumber += 1
stringIndex = i
}
m.Summary = content[0:stringIndex]
}
... ...