作者 yangfu
... ... @@ -306,10 +306,10 @@ type (
CompanyId int64 `json:",optional"` // 公司id
UserId int64 `json:",optional"` // 公司id
ArticleId int64 `json:"articleId"` // 文章id
TagId int64 `json:"tagId"` // 标签id
TagId []int64 `json:"tagId"` // 标签id
}
MiniArticleSetTagResponse {
Id int64 `json:"id"`
Id []int64 `json:"id"`
}
)
... ...
... ... @@ -31,8 +31,7 @@ func (l *MiniArticleBackupSearchLogic) MiniArticleBackupSearch(req *types.MiniAr
queryOption := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("article_id", req.ArticleId).
MustWithKV("company_id", req.CompanyId)
MustWithKV("articleId", req.ArticleId)
cnt, backupList, err := l.svcCtx.ArticleBackupRepository.Find(l.ctx, conn, queryOption)
if err != nil {
... ...
... ... @@ -2,6 +2,7 @@ package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/message"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
... ... @@ -38,24 +39,18 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取文章信息失败")
}
tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId)
tagIdList := []int64{}
// 额外保存一份ArticleAndTag
var articleAndTagList []domain.ArticleAndTag
for _, val := range req.TagId {
tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, val)
if err != nil {
return nil, xerr.NewErrMsgErr("获取标签信息失败", err)
}
if tagInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("获取标签信息失败")
}
// 查询可能存在的 ArticleAndTag
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id)
_, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("检查文章的标签失败", err)
}
// 更新article中的tags
articleInfo.Tags = []int64{tagInfo.Id}
// 额外保存一份ArticleAndTag
tagIdList = append(tagIdList, tagInfo.Id)
articleAndTag := domain.ArticleAndTag{
Id: 0,
CompanyId: articleInfo.CompanyId,
... ... @@ -64,6 +59,17 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
ArticleId: articleInfo.Id,
TagId: tagInfo.Id,
}
articleAndTagList = append(articleAndTagList, articleAndTag)
}
//更新article中的tags
articleInfo.Tags = tagIdList
// 查询可能存在的 ArticleAndTag
queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id)
_, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("检查文章的标签失败", err)
}
//
err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error {
//清理可能存在的 ArticleAndTag
for _, v := range oldTags {
... ... @@ -77,11 +83,12 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
if err != nil {
return err
}
_, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTag)
for i := range articleAndTagList {
_, err = l.svcCtx.ArticleAndTagRepository.Insert(ctx, c, &articleAndTagList[i])
if err != nil {
return err
}
}
// 定性消息通知
messageLogic := message.NewMiniSystemLogic(ctx, l.svcCtx)
err = messageLogic.ArticleDefined(c, articleInfo.CompanyId, articleInfo.AuthorId, articleInfo.Title)
... ... @@ -93,7 +100,10 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR
}, true)
resp = &types.MiniArticleSetTagResponse{
Id: articleAndTag.Id,
Id: []int64{},
}
for _, val := range articleAndTagList {
resp.Id = append(resp.Id, val.Id)
}
return resp, nil
}
... ...
... ... @@ -201,12 +201,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
}
}
// 设置保存备份
backup := newArticle.MakeBackup(newArticle.Author, sectionList)
backup.Action = "新增"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
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 {
... ...
... ... @@ -38,7 +38,25 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
if articleInfo.CompanyId != req.CompanyId {
return nil, xerr.NewErrMsg("没有查看权限")
}
//TODO 检查可查看人
if len(articleInfo.WhoRead) > 0 {
inWhoRead := false
for _, val := range articleInfo.WhoRead {
if req.UserId == int(val) {
inWhoRead = true
}
}
if !inWhoRead {
// 文章内容不显示
resp = &types.MiniArticleGetResponse{
Id: articleInfo.Id,
Title: articleInfo.Title,
Show: int(domain.ArticleShowDisable),
}
return resp, nil
}
}
if articleInfo.Show == domain.ArticleShowDisable {
// 文章内容不显示
resp = &types.MiniArticleGetResponse{
... ... @@ -81,6 +99,9 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
follow, _ := l.svcCtx.UserFollowRepository.FindOneUserFollowing(l.ctx, conn, int64(req.UserId), articleInfo.AuthorId)
queryOption = domain.NewQueryOptions().WithFindOnly().WithOffsetLimit(1, 1).WithKV("articleId", articleInfo.Id)
_, backupList, _ := l.svcCtx.ArticleBackupRepository.Find(l.ctx, conn, queryOption)
sortBy := domain.SortArticleSection(sectionList)
sort.Sort(sortBy)
articleSection := []types.ArticleSection{}
... ... @@ -124,7 +145,7 @@ func (l *MiniGetArticleLogic) MiniGetArticle(req *types.MiniArticleGetRequest) (
Tags: tags,
MatchUrl: map[string]string{},
}
if articleInfo.CreatedAt != articleInfo.UpdatedAt {
if len(backupList) > 0 {
resp.Edit = 1
}
... ...
... ... @@ -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)
... ...
... ... @@ -42,11 +42,30 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
//TargetUser 设定为分发给所有人,清空 WhoRead
req.WhoRead = make([]int64, 0)
}
// 获取当前用户信息
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, req.Id)
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)
}
//备份数据
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 = "编辑"
// 获取图片的尺寸大小
images := []domain.Image{}
for _, val := range req.Images {
... ... @@ -166,11 +185,7 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
}
article.Summary = req.Section[0].Content[0:stringIndex]
}
//获取当前用户信息
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(l.ctx, c, article)
if err != nil {
... ... @@ -207,15 +222,6 @@ func (l *SystemUpdateArticleLogic) SystemUpdateArticle(req *types.SystemArticleU
return 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,
}, articleSections)
backup.Action = "编辑"
_, err = l.svcCtx.ArticleBackupRepository.Insert(ctx, c, backup)
if err != nil {
return xerr.NewErrMsgErr("保存文章内容失败", err)
... ...
... ... @@ -1066,11 +1066,11 @@ type MiniArticleSetTagRequest struct {
CompanyId int64 `json:",optional"` // 公司id
UserId int64 `json:",optional"` // 公司id
ArticleId int64 `json:"articleId"` // 文章id
TagId int64 `json:"tagId"` // 标签id
TagId []int64 `json:"tagId"` // 标签id
}
type MiniArticleSetTagResponse struct {
Id int64 `json:"id"`
Id []int64 `json:"id"`
}
type MiniAllArticleTagRequest struct {
... ...
... ... @@ -21,6 +21,7 @@ type Article struct {
Author domain.UserSimple `gorm:"type:jsonb;serializer:json"` // 发布人
Title string // 文章标题
Images []domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
Videos []domain.Video `gorm:"type:jsonb;serializer:json"` // 视频
WhoRead []int64 `gorm:"type:jsonb;serializer:json"` // 谁可以看
WhoReview []int64 `gorm:"type:jsonb;serializer:json"` // 评论人
Location domain.Location `gorm:"type:jsonb;serializer:json"` // 坐标
... ...
... ... @@ -129,6 +129,9 @@ func (repository *ArticleBackupRepository) Find(ctx context.Context, conn transa
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id = ?", v)
}
if v, ok := queryOptions["companyId"]; ok {
tx = tx.Where("article_id = ?", v)
}
if v, ok := queryOptions["operator"]; ok && v.(string) != "" {
tx = tx.Where(`operator #>> '{"name"}' like ?`, "%"+v.(string)+"%")
}
... ...
... ... @@ -120,6 +120,10 @@ func (repository *ArticleDraftRepository) Find(ctx context.Context, conn transac
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["authorId"]; ok {
tx = tx.Where("author_id=?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -305,6 +305,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (*
Tags: from.Tags,
Summary: from.Summary,
MatchUrl: from.MatchUrl,
Videos: from.Videos,
}
return to, nil
}
... ... @@ -333,6 +334,7 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (*
Show: int(from.Show),
Summary: from.Summary,
MatchUrl: from.MatchUrl,
Videos: from.Videos,
}
// err := copier.Copy(to, from)
return to, nil
... ...
... ... @@ -122,6 +122,12 @@ func (repository *MessageSystemRepository) Find(ctx context.Context, conn transa
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
if v, ok := queryOptions["companyId"]; ok {
tx.Where("company_id = ?", v)
}
if v, ok := queryOptions["recipientId"]; ok {
tx.Where("recipient_id = ?", v)
}
return dms, tx.Error
}
return dms, nil
... ...
... ... @@ -18,6 +18,7 @@ type Article struct {
Author UserSimple `json:"author"` // 发布人
Title string `json:"title"` // 文章标题
Images []Image `json:"images"` // 图片
Videos []Video `json:"videos"` // 视频
WhoRead []int64 `json:"whoRead"` // 谁可以看
WhoReview []int64 `json:"whoReview"` // 评论人
Location Location `json:"location"` // 坐标
... ... @@ -93,7 +94,11 @@ func (a ArticleShow) Named() string {
}
// 设置文章的备份数据
func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *ArticleBackup {
func (m *Article) MakeBackup(operator UserSimple, section []*ArticleSection) *ArticleBackup {
sectionBackup := make([]ArticleSection, len(section))
for i := range section {
sectionBackup[i] = *section[i]
}
b := ArticleBackup{
Id: 0,
CompanyId: m.CompanyId,
... ... @@ -104,7 +109,7 @@ func (m *Article) MakeBackup(operator UserSimple, section []ArticleSection) *Art
Operator: operator,
ArticleId: m.Id,
Title: m.Title,
Section: section,
Section: sectionBackup,
Images: m.Images,
Action: "",
TargetUser: m.TargetUser,
... ...
... ... @@ -7,6 +7,14 @@ type Image struct {
Height int `json:"height"` // 图片高度
}
// 视频信息
type Video struct {
Url string `json:"url"` //视频文件的地址
Cover string `json:"cover"` //封面
Width int `json:"width"` //封面图片宽
Height int `json:"height"` //封面图片长
}
// 坐标位置
type Location struct {
Longitude float64 `json:"longitude"` //经度
... ...