main #138
@ -16,7 +16,7 @@ async def front_news_search(ns={}):
|
||||
if ns.get('article_type'):
|
||||
conditions.append("article_type = '%s'" % ns.get('article_type'))
|
||||
if ns.get('title'):
|
||||
conditions.append("title like '%%%s%%'" % ns.get('title'))
|
||||
conditions.append("title like '%%%%%s%%%%'" % ns.get('title'))
|
||||
where_clause = " and ".join(conditions)
|
||||
|
||||
db = DBPools()
|
||||
|
||||
@ -13,6 +13,7 @@ async def news_article_search(ns={}):
|
||||
offset = (current_page - 1) * page_size
|
||||
|
||||
conditions = ["domain_name = '%s'" % domain_name, "del_flg = '0'"]
|
||||
summary_conditions = ["domain_name = '%s'" % domain_name, "del_flg = '0'"]
|
||||
if ns.get('title'):
|
||||
conditions.append("title like '%%%%%s%%%%'" % ns.get('title'))
|
||||
if ns.get('article_type'):
|
||||
@ -26,6 +27,24 @@ async def news_article_search(ns={}):
|
||||
try:
|
||||
count_sql = """select count(*) as total_count from enterprise_news_article where %s;""" % where_clause
|
||||
total_count = (await sor.sqlExe(count_sql, {}))[0]['total_count']
|
||||
summary_sql = """
|
||||
select article_type, count(*) as article_count, ifnull(sum(read_count), 0) as read_count
|
||||
from enterprise_news_article
|
||||
where %s
|
||||
group by article_type;
|
||||
""" % " and ".join(summary_conditions)
|
||||
summary_result = await sor.sqlExe(summary_sql, {})
|
||||
summary_mapping = {}
|
||||
for summary_dic in summary_result:
|
||||
summary_mapping[summary_dic.get('article_type')] = summary_dic
|
||||
article_type_summary = []
|
||||
for article_type in ['企业动态', '产品动态', '行业洞察', '活动资讯']:
|
||||
summary_dic = summary_mapping.get(article_type, {})
|
||||
article_type_summary.append({
|
||||
'article_type': article_type,
|
||||
'article_count': summary_dic.get('article_count', 0),
|
||||
'read_count': summary_dic.get('read_count', 0)
|
||||
})
|
||||
search_sql = """
|
||||
select id, domain_name, title, article_type, summary, cover_img, status,
|
||||
publish_time, read_count, update_time, create_at
|
||||
@ -42,6 +61,7 @@ async def news_article_search(ns={}):
|
||||
'status': True,
|
||||
'msg': 'search news article success',
|
||||
'data': result,
|
||||
'article_type_summary': article_type_summary,
|
||||
'pagination': {
|
||||
'total': total_count,
|
||||
'page_size': page_size,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user