...
|
...
|
@@ -277,3 +277,35 @@ func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, c |
|
|
func NewArticleRepository(cache *cache.CachedRepository) domain.ArticleRepository {
|
|
|
return &ArticleRepository{CachedRepository: cache}
|
|
|
}
|
|
|
|
|
|
// with
|
|
|
// -- 按查看权限查询文章
|
|
|
// t_article as(
|
|
|
// select article.id
|
|
|
// from article
|
|
|
// where article.deleted_at=0
|
|
|
// and article.company_id =1598224576532189184
|
|
|
// and article."show" =0
|
|
|
// and (article.target_user =0 or article.who_read @>'[1]')
|
|
|
// ),
|
|
|
// -- 获取有标签的文章
|
|
|
// t_article_and_tag as (
|
|
|
// select article_and_tag.article_id ,article_and_tag.tag_id
|
|
|
// from article_and_tag
|
|
|
// where article_and_tag.company_id =1598224576532189184
|
|
|
// ),
|
|
|
// -- 过滤出可展示的文章id
|
|
|
// t_article_and_tag_2 as (
|
|
|
// select t_article_and_tag.article_id, t_article_and_tag.tag_id
|
|
|
// from t_article_and_tag
|
|
|
// join t_article on t_article_and_tag.article_id = t_article.id
|
|
|
// ),
|
|
|
// -- 查询人员已查看的文章
|
|
|
// t_user_read as(
|
|
|
// select user_read_article.article_id from user_read_article where user_read_article.user_id =1
|
|
|
// )
|
|
|
// -- 汇总统计 cnt_1符合条件的文章总数,cnt_2 已浏览的数量
|
|
|
// 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
|
|
|
// from t_article_and_tag_2
|
|
|
// left join t_user_read on t_article_and_tag_2.article_id=t_user_read.article_id
|
|
|
// group by t_article_and_tag_2.tag_id |
...
|
...
|
|