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_zh': ns.get('cover_img_zh'), 'cover_img_en': ns.get('cover_img_en'), 'content_zh': ns.get('content_zh'), 'content_en': ns.get('content_en'), 'status': status, 'publish_time_zh': ns.get('publish_time_zh') or None, 'publish_time_en': ns.get('publish_time_en') or None, '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': publish_sql = """ update enterprise_news_article set publish_time_zh = ifnull(publish_time_zh, current_date()), publish_time_en = ifnull(publish_time_en, current_date()) 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