...
|
...
|
@@ -11,6 +11,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/tool/oss"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
"strings"
|
|
|
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
|
...
|
...
|
@@ -51,29 +52,98 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU |
|
|
Height: h,
|
|
|
})
|
|
|
}
|
|
|
//检查文章可被哪些人查看
|
|
|
whoRead := []int64{}
|
|
|
if len(req.WhoRead) > 0 {
|
|
|
whoRead = lo.Uniq(req.WhoRead)
|
|
|
var u *domain.User
|
|
|
for _, val := range whoRead {
|
|
|
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, val)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("文章可查看人设置错误", err)
|
|
|
}
|
|
|
if u.CompanyId != article.CompanyId {
|
|
|
return nil, xerr.NewErrMsg("文章可查看人设置错误")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//检查文章可被哪些人评论
|
|
|
whoReview := []int64{}
|
|
|
if len(req.WhoReview) > 0 {
|
|
|
whoReview = lo.Uniq(req.WhoReview)
|
|
|
}
|
|
|
//有指定可查看人的情况
|
|
|
if len(whoRead) > 0 {
|
|
|
if len(whoReview) > 0 {
|
|
|
// 检查 whoRead 是否 完全包含 whoReview
|
|
|
ok := lo.Every(whoRead, whoReview)
|
|
|
if !ok {
|
|
|
return nil, xerr.NewErrMsg("文章可评论人设置错误")
|
|
|
}
|
|
|
}
|
|
|
if len(whoReview) == 0 {
|
|
|
//有指定可查看人 ,但未指定可评论人
|
|
|
return nil, xerr.NewErrMsg("文章可评论人设置错误")
|
|
|
}
|
|
|
}
|
|
|
//没有指定可查看人的情况
|
|
|
if len(whoRead) == 0 {
|
|
|
if len(whoReview) > 0 {
|
|
|
// 未指定可查看人(全员可看),有指定可评论人,
|
|
|
var u *domain.User
|
|
|
for _, val := range whoReview {
|
|
|
u, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, val)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("文章可评论人设置错误", err)
|
|
|
}
|
|
|
if u.CompanyId != article.CompanyId {
|
|
|
return nil, xerr.NewErrMsg("文章可评论人设置错误")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//验证tag
|
|
|
if len(req.Tags) > 0 {
|
|
|
req.Tags = lo.Uniq(req.Tags)
|
|
|
for _, value := range req.Tags {
|
|
|
t, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, value)
|
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("文章标签设置错误", err)
|
|
|
}
|
|
|
if t.CompanyId != article.CompanyId {
|
|
|
return nil, xerr.NewErrMsgErr("文章标签设置错误", err)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
article.Title = req.Title
|
|
|
article.Version = article.Version + 1
|
|
|
article.Images = images
|
|
|
article.WhoRead = req.WhoRead
|
|
|
article.WhoReview = req.WhoReview
|
|
|
article.WhoRead = whoRead
|
|
|
article.WhoReview = whoReview
|
|
|
article.TargetUser = domain.ArticleTarget(req.TargetUser)
|
|
|
article.Location = domain.Location{
|
|
|
Longitude: req.Location.Longitude,
|
|
|
Latitude: req.Location.Latitude,
|
|
|
Descript: req.Location.Descript,
|
|
|
}
|
|
|
article.Tags = req.Tags
|
|
|
//文章内容
|
|
|
articleSections := []domain.ArticleSection{}
|
|
|
sortBy := 1
|
|
|
lo.ForEach(req.Section, func(item types.ArticleSection, index int) {
|
|
|
articleSections = append(articleSections, domain.ArticleSection{
|
|
|
Id: item.Id,
|
|
|
CompanyId: article.CompanyId,
|
|
|
Version: article.Version,
|
|
|
ArticleId: article.Id,
|
|
|
Content: item.Content,
|
|
|
SortBy: index + 1,
|
|
|
})
|
|
|
strList := strings.Split(item.Content, "\n")
|
|
|
for key, value := range strList {
|
|
|
if value == "" {
|
|
|
continue
|
|
|
}
|
|
|
section := domain.ArticleSection{
|
|
|
CompanyId: article.CompanyId,
|
|
|
Version: article.Version,
|
|
|
ArticleId: article.Id,
|
|
|
Content: value,
|
|
|
SortBy: sortBy,
|
|
|
}
|
|
|
if key == 0 {
|
|
|
section.Id = item.Id
|
|
|
}
|
|
|
articleSections = append(articleSections, section)
|
|
|
sortBy++
|
|
|
}
|
|
|
})
|
|
|
//设置内容概要
|
|
|
if len(req.Section) > 0 {
|
...
|
...
|
|