63 lines
1.9 KiB
Plaintext
63 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'):
|
|
return {
|
|
'status': False,
|
|
'msg': '请传递标题'
|
|
}
|
|
# if ns.get('article_type') not in ['企业动态', '产品动态', '行业洞察', '活动资讯']:
|
|
# 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': ns.get('title'),
|
|
'article_type': ns.get('article_type'),
|
|
'summary': ns.get('summary'),
|
|
'cover_img': ns.get('cover_img'),
|
|
'content': ns.get('content'),
|
|
'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
|