kboss/b/news/news_article_add.dspy
2026-07-29 16:42:48 +08:00

62 lines
1.9 KiB
Plaintext

async def news_article_add(ns={}):
if not ns.get('url_link'):
return {
'status': False,
'msg': '请传递url_link'
}
if not ns.get('title_zh'):
return {
'status': False,
'msg': '请传递中文标题'
}
domain_name = ns.get('url_link').split("//")[1].split("/")[0]
if 'localhost' in domain_name:
domain_name = 'dev.opencomputing.cn'
status = ns.get('status', '0')
if status not in ['0', '1']:
status = '0'
ns_dic = {
'id': uuid(),
'domain_name': domain_name,
'title_zh': ns.get('title_zh'),
'title_en': ns.get('title_en'),
'article_type_zh': ns.get('article_type_zh'),
'article_type_en': ns.get('article_type_en'),
'summary_zh': ns.get('summary_zh'),
'summary_en': ns.get('summary_en'),
'cover_img': ns.get('cover_img'),
'content_zh': ns.get('content_zh'),
'content_en': ns.get('content_en'),
'status': status,
'publish_time': ns.get('publish_time'),
'read_count': 0,
'del_flg': '0'
}
db = DBPools()
async with db.sqlorContext('kboss') as sor:
try:
await sor.C('enterprise_news_article', ns_dic)
if status == '1' and not ns.get('publish_time'):
publish_sql = """update enterprise_news_article set publish_time = current_timestamp() where id = '%s';""" % ns_dic.get('id')
await sor.sqlExe(publish_sql, {})
return {
'status': True,
'msg': 'create news article success',
'data': {
'id': ns_dic.get('id')
}
}
except Exception as e:
await sor.rollback()
return {
'status': False,
'msg': 'create news article failed, %s' % str(e)
}
ret = await news_article_add(params_kw)
return ret