kboss/b/news/front_news_search.dspy
2026-08-06 11:13:43 +08:00

59 lines
2.3 KiB
Plaintext

async def front_news_search(ns={}):
if not ns.get('url_link'):
return {
'status': False,
'msg': '请传递url_link'
}
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
if 'localhost' in domain_name:
domain_name = 'dev.opencomputing.cn'
current_page = int(ns.get('current_page', 1))
page_size = int(ns.get('page_size', 10))
offset = (current_page - 1) * page_size
conditions = ["domain_name = '%s'" % domain_name, "status = '1'", "del_flg = '0'"]
if ns.get('article_type_zh'):
conditions.append("article_type_zh = '%s'" % ns.get('article_type_zh'))
if ns.get('article_type_en'):
conditions.append("article_type_en = '%s'" % ns.get('article_type_en'))
if ns.get('title_zh'):
conditions.append("title_zh like '%%%%%s%%%%'" % ns.get('title_zh'))
if ns.get('title_en'):
conditions.append("title_en like '%%%%%s%%%%'" % ns.get('title_en'))
where_clause = " and ".join(conditions)
db = DBPools()
async with db.sqlorContext('kboss') as sor:
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']
search_sql = """
select id, title_zh, title_en, article_type_zh, article_type_en,
summary_zh, summary_en, cover_img_zh, cover_img_en,
publish_time_zh, publish_time_en, read_count
from enterprise_news_article
where %s
order by publish_time_zh desc, update_time desc
limit %s offset %s;
""" % (where_clause, page_size, offset)
result = await sor.sqlExe(search_sql, {})
return {
'status': True,
'msg': 'search front news success',
'data': result,
'pagination': {
'total': total_count,
'page_size': page_size,
'current_page': current_page
}
}
except Exception as e:
return {
'status': False,
'msg': 'search front news failed, %s' % str(e)
}
ret = await front_news_search(params_kw)
return ret