...
|
...
|
@@ -2,9 +2,11 @@ package article |
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
"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"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
|
|
|
|
...
|
...
|
@@ -33,6 +35,18 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR |
|
|
if err != nil {
|
|
|
return nil, xerr.NewErrMsgErr("创建文章内容失败", err)
|
|
|
}
|
|
|
//TODO 获取人员信息
|
|
|
articleAuthor := domain.UserSimple{
|
|
|
Id: author.Id,
|
|
|
Name: author.Name,
|
|
|
Avatar: author.Avatar,
|
|
|
GroupId: 0,
|
|
|
Group: "",
|
|
|
Position: author.Position,
|
|
|
Company: "",
|
|
|
CompanyId: author.CompanyId,
|
|
|
}
|
|
|
|
|
|
//TODO 获取图片的尺寸大小
|
|
|
images := []domain.Image{}
|
|
|
for _, val := range req.Images {
|
...
|
...
|
@@ -59,24 +73,110 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR |
|
|
}
|
|
|
//检查文章可被哪些人评论
|
|
|
whoReview := []int64{}
|
|
|
if len(req.WhoReview) > 0 && len(whoRead) > 0 {
|
|
|
whoReview = lo.Uniq(req.WhoReview)
|
|
|
// 检查 whoRead 是否 完全包含 whoReview
|
|
|
ok := lo.Every(whoRead, whoReview)
|
|
|
if !ok {
|
|
|
//有指定可查看人的情况
|
|
|
if len(whoRead) > 0 {
|
|
|
if len(whoReview) > 0 {
|
|
|
whoReview = lo.Uniq(req.WhoReview)
|
|
|
// 检查 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 && 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 != author.CompanyId {
|
|
|
return nil, xerr.NewErrMsg("文章可评论人设置错误")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// if len(whoReview) == 0 {
|
|
|
// 未指定可查看人(全员可看),未指定可评论人 ,忽略判断
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
//切分文章分段
|
|
|
sectionList := []domain.ArticleSection{}
|
|
|
for i := range req.Section {
|
|
|
strList := strings.Split(req.Section[i], "\n")
|
|
|
for i2 := range strList {
|
|
|
newStr := strings.TrimSpace(strList[i2])
|
|
|
if len(newStr) == 0 {
|
|
|
continue
|
|
|
}
|
|
|
newSection := domain.ArticleSection{
|
|
|
Id: 0,
|
|
|
CompanyId: author.CompanyId,
|
|
|
ArticleId: 0,
|
|
|
Content: newStr,
|
|
|
SortBy: len(sectionList),
|
|
|
TotalComment: 0,
|
|
|
}
|
|
|
sectionList = append(sectionList, newSection)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
newArticle := &domain.Article{
|
|
|
Id: 0,
|
|
|
CompanyId: author.CompanyId,
|
|
|
AuthorId: author.Id,
|
|
|
Author: articleAuthor,
|
|
|
Title: req.Title,
|
|
|
Images: images,
|
|
|
WhoRead: whoRead,
|
|
|
WhoReview: whoReview,
|
|
|
Location: domain.Location{
|
|
|
Longitude: req.Location.Latitude,
|
|
|
Latitude: req.Location.Latitude,
|
|
|
Descript: req.Location.Descript,
|
|
|
},
|
|
|
TargetUser: domain.ArticleTargetAll,
|
|
|
}
|
|
|
if len(whoRead) > 0 {
|
|
|
newArticle.TargetUser = domain.ArticleTargetLimit
|
|
|
}
|
|
|
|
|
|
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
|
|
|
newArticle, err = l.svcCtx.ArticleRepository.Insert(ctx, c, newArticle)
|
|
|
if err != nil {
|
|
|
return xerr.NewErrMsgErr("创建文章失败", err)
|
|
|
}
|
|
|
|
|
|
for i := range sectionList {
|
|
|
sectionList[i].ArticleId = newArticle.Id
|
|
|
_, err = l.svcCtx.ArticleSectionRepository.Insert(ctx, c, §ionList[i])
|
|
|
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 {
|
|
|
return nil, xerr.NewErrMsgErr("创建文章失败", err)
|
|
|
}
|
|
|
// if len(whoRead) == 0 && len(whoReview) > 0 {
|
|
|
// 未指定可查看人(全员可看),有指定可评论人 ,忽略判断
|
|
|
// }
|
|
|
// if len(whoRead) == 0 && len(whoReview) == 0 {
|
|
|
// 未指定可查看人(全员可看),未指定可评论人 ,忽略判断
|
|
|
// }
|
|
|
|
|
|
resp = &types.MiniArticleCreateResponse{
|
|
|
Id: newArticle.Id,
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|