正在显示
2 个修改的文件
包含
39 行增加
和
1 行删除
| @@ -34,19 +34,25 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR | @@ -34,19 +34,25 @@ func (l *MiniArticleSetTagLogic) MiniArticleSetTag(req *types.MiniArticleSetTagR | ||
| 34 | if err != nil { | 34 | if err != nil { |
| 35 | return nil, xerr.NewErrMsgErr("获取文章信息失败", err) | 35 | return nil, xerr.NewErrMsgErr("获取文章信息失败", err) |
| 36 | } | 36 | } |
| 37 | + if articleInfo.CompanyId != req.CompanyId { | ||
| 38 | + return nil, xerr.NewErrMsg("获取文章信息失败") | ||
| 39 | + } | ||
| 37 | 40 | ||
| 38 | tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId) | 41 | tagInfo, err := l.svcCtx.ArticleTagRepository.FindOne(l.ctx, conn, req.TagId) |
| 39 | if err != nil { | 42 | if err != nil { |
| 40 | return nil, xerr.NewErrMsgErr("获取标签信息失败", err) | 43 | return nil, xerr.NewErrMsgErr("获取标签信息失败", err) |
| 41 | } | 44 | } |
| 42 | 45 | ||
| 46 | + if tagInfo.CompanyId != req.CompanyId { | ||
| 47 | + return nil, xerr.NewErrMsg("获取标签信息失败") | ||
| 48 | + } | ||
| 43 | // 查询可能存在的 ArticleAndTag | 49 | // 查询可能存在的 ArticleAndTag |
| 44 | queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id) | 50 | queryOption := domain.NewQueryOptions().WithFindOnly().MustWithKV("articleId", articleInfo.Id) |
| 45 | _, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption) | 51 | _, oldTags, err := l.svcCtx.ArticleAndTagRepository.Find(l.ctx, conn, queryOption) |
| 46 | if err != nil { | 52 | if err != nil { |
| 47 | return nil, xerr.NewErrMsgErr("检查文章的标签失败", err) | 53 | return nil, xerr.NewErrMsgErr("检查文章的标签失败", err) |
| 48 | } | 54 | } |
| 49 | - | 55 | + // 更新article中的tags |
| 50 | articleInfo.Tags = []int64{tagInfo.Id} | 56 | articleInfo.Tags = []int64{tagInfo.Id} |
| 51 | // 额外保存一份ArticleAndTag | 57 | // 额外保存一份ArticleAndTag |
| 52 | articleAndTag := domain.ArticleAndTag{ | 58 | articleAndTag := domain.ArticleAndTag{ |
| @@ -277,3 +277,35 @@ func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, c | @@ -277,3 +277,35 @@ func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, c | ||
| 277 | func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository { | 277 | func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository { |
| 278 | return &ArticleRepository{CachedRepository: cache} | 278 | return &ArticleRepository{CachedRepository: cache} |
| 279 | } | 279 | } |
| 280 | + | ||
| 281 | +// with | ||
| 282 | +// -- 按查看权限查询文章 | ||
| 283 | +// t_article as( | ||
| 284 | +// select article.id | ||
| 285 | +// from article | ||
| 286 | +// where article.deleted_at=0 | ||
| 287 | +// and article.company_id =1598224576532189184 | ||
| 288 | +// and article."show" =0 | ||
| 289 | +// and (article.target_user =0 or article.who_read @>'[1]') | ||
| 290 | +// ), | ||
| 291 | +// -- 获取有标签的文章 | ||
| 292 | +// t_article_and_tag as ( | ||
| 293 | +// select article_and_tag.article_id ,article_and_tag.tag_id | ||
| 294 | +// from article_and_tag | ||
| 295 | +// where article_and_tag.company_id =1598224576532189184 | ||
| 296 | +// ), | ||
| 297 | +// -- 过滤出可展示的文章id | ||
| 298 | +// t_article_and_tag_2 as ( | ||
| 299 | +// select t_article_and_tag.article_id, t_article_and_tag.tag_id | ||
| 300 | +// from t_article_and_tag | ||
| 301 | +// join t_article on t_article_and_tag.article_id = t_article.id | ||
| 302 | +// ), | ||
| 303 | +// -- 查询人员已查看的文章 | ||
| 304 | +// t_user_read as( | ||
| 305 | +// select user_read_article.article_id from user_read_article where user_read_article.user_id =1 | ||
| 306 | +// ) | ||
| 307 | +// -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量 | ||
| 308 | +// select count(t_article_and_tag_2.article_id) as cnt_1 ,count(t_user_read.article_id) as cnt_2, t_article_and_tag_2.tag_id | ||
| 309 | +// from t_article_and_tag_2 | ||
| 310 | +// left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id | ||
| 311 | +// group by t_article_and_tag_2.tag_id |
-
请 注册 或 登录 后发表评论