main #138
16
b/news/enterprise_news_article.sql
Normal file
16
b/news/enterprise_news_article.sql
Normal file
@ -0,0 +1,16 @@
|
||||
CREATE TABLE `enterprise_news_article` (
|
||||
`id` varchar(32) NOT NULL COMMENT '唯一标识符',
|
||||
`domain_name` varchar(64) NOT NULL COMMENT '所属域名',
|
||||
`title` varchar(100) NOT NULL COMMENT '文章标题',
|
||||
`article_type` varchar(20) NOT NULL COMMENT '文章类型(企业动态/产品动态/行业洞察/活动资讯)',
|
||||
`summary` varchar(255) DEFAULT NULL COMMENT '文章摘要',
|
||||
`cover_img` varchar(255) DEFAULT NULL COMMENT '封面图片',
|
||||
`content` text COMMENT '文章正文',
|
||||
`status` varchar(1) DEFAULT '0' COMMENT '状态(0-草稿/1-已发布)',
|
||||
`publish_time` date DEFAULT NULL COMMENT '发布时间',
|
||||
`read_count` int(11) DEFAULT 0 COMMENT '阅读数据',
|
||||
`del_flg` varchar(1) DEFAULT '0' COMMENT '删除标志(0-正常/1-已删除)',
|
||||
`update_time` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '更新时间',
|
||||
`create_at` timestamp NULL DEFAULT current_timestamp() COMMENT '创建时间',
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='企业文章表';
|
||||
37
b/news/front_news_detail.dspy
Normal file
37
b/news/front_news_detail.dspy
Normal file
@ -0,0 +1,37 @@
|
||||
async def front_news_detail(ns={}):
|
||||
if not ns.get('id'):
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '请传递id'
|
||||
}
|
||||
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
try:
|
||||
update_sql = """update enterprise_news_article set read_count = ifnull(read_count, 0) + 1 where id = '%s' and status = '1' and del_flg = '0';""" % ns.get('id')
|
||||
await sor.sqlExe(update_sql, {})
|
||||
search_sql = """
|
||||
select id, title, article_type, summary, cover_img, content, publish_time, read_count
|
||||
from enterprise_news_article
|
||||
where id = '%s' and status = '1' and del_flg = '0';
|
||||
""" % ns.get('id')
|
||||
result = await sor.sqlExe(search_sql, {})
|
||||
if not result:
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '文章不存在或未发布'
|
||||
}
|
||||
return {
|
||||
'status': True,
|
||||
'msg': 'search front news detail success',
|
||||
'data': result[0]
|
||||
}
|
||||
except Exception as e:
|
||||
await sor.rollback()
|
||||
return {
|
||||
'status': False,
|
||||
'msg': 'search front news detail failed, %s' % str(e)
|
||||
}
|
||||
|
||||
ret = await front_news_detail(params_kw)
|
||||
return ret
|
||||
52
b/news/front_news_search.dspy
Normal file
52
b/news/front_news_search.dspy
Normal file
@ -0,0 +1,52 @@
|
||||
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'):
|
||||
conditions.append("article_type = '%s'" % ns.get('article_type'))
|
||||
if ns.get('title'):
|
||||
conditions.append("title like '%%%%%s%%%%'" % ns.get('title'))
|
||||
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, article_type, summary, cover_img, publish_time, read_count
|
||||
from enterprise_news_article
|
||||
where %s
|
||||
order by publish_time 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
|
||||
62
b/news/news_article_add.dspy
Normal file
62
b/news/news_article_add.dspy
Normal file
@ -0,0 +1,62 @@
|
||||
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
|
||||
28
b/news/news_article_delete.dspy
Normal file
28
b/news/news_article_delete.dspy
Normal file
@ -0,0 +1,28 @@
|
||||
async def news_article_delete(ns={}):
|
||||
if not ns.get('id'):
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '请传递id'
|
||||
}
|
||||
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
try:
|
||||
ns_dic = {
|
||||
'id': ns.get('id'),
|
||||
'del_flg': '1'
|
||||
}
|
||||
await sor.U('enterprise_news_article', ns_dic)
|
||||
return {
|
||||
'status': True,
|
||||
'msg': 'delete news article success'
|
||||
}
|
||||
except Exception as e:
|
||||
await sor.rollback()
|
||||
return {
|
||||
'status': False,
|
||||
'msg': 'delete news article failed, %s' % str(e)
|
||||
}
|
||||
|
||||
ret = await news_article_delete(params_kw)
|
||||
return ret
|
||||
31
b/news/news_article_detail.dspy
Normal file
31
b/news/news_article_detail.dspy
Normal file
@ -0,0 +1,31 @@
|
||||
async def news_article_detail(ns={}):
|
||||
if not ns.get('id'):
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '请传递id'
|
||||
}
|
||||
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
try:
|
||||
search_sql = """select * from enterprise_news_article where id = '%s' and del_flg = '0';""" % ns.get('id')
|
||||
result = await sor.sqlExe(search_sql, {})
|
||||
if not result:
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '文章不存在'
|
||||
}
|
||||
result[0]['status_name'] = {'0': '草稿', '1': '已发布'}.get(str(result[0].get('status')), result[0].get('status'))
|
||||
return {
|
||||
'status': True,
|
||||
'msg': 'search news article detail success',
|
||||
'data': result[0]
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
'status': False,
|
||||
'msg': 'search news article detail failed, %s' % str(e)
|
||||
}
|
||||
|
||||
ret = await news_article_detail(params_kw)
|
||||
return ret
|
||||
28
b/news/news_article_offline.dspy
Normal file
28
b/news/news_article_offline.dspy
Normal file
@ -0,0 +1,28 @@
|
||||
async def news_article_offline(ns={}):
|
||||
if not ns.get('id'):
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '请传递id'
|
||||
}
|
||||
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
try:
|
||||
ns_dic = {
|
||||
'id': ns.get('id'),
|
||||
'status': '0'
|
||||
}
|
||||
await sor.U('enterprise_news_article', ns_dic)
|
||||
return {
|
||||
'status': True,
|
||||
'msg': 'offline news article success'
|
||||
}
|
||||
except Exception as e:
|
||||
await sor.rollback()
|
||||
return {
|
||||
'status': False,
|
||||
'msg': 'offline news article failed, %s' % str(e)
|
||||
}
|
||||
|
||||
ret = await news_article_offline(params_kw)
|
||||
return ret
|
||||
29
b/news/news_article_publish.dspy
Normal file
29
b/news/news_article_publish.dspy
Normal file
@ -0,0 +1,29 @@
|
||||
async def news_article_publish(ns={}):
|
||||
if not ns.get('id'):
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '请传递id'
|
||||
}
|
||||
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
try:
|
||||
publish_time = ns.get('publish_time')
|
||||
if publish_time:
|
||||
publish_sql = """update enterprise_news_article set status = '1', publish_time = '%s' where id = '%s' and del_flg = '0';""" % (publish_time, ns.get('id'))
|
||||
else:
|
||||
publish_sql = """update enterprise_news_article set status = '1' where id = '%s' and del_flg = '0';""" % ns.get('id')
|
||||
await sor.sqlExe(publish_sql, {})
|
||||
return {
|
||||
'status': True,
|
||||
'msg': 'publish news article success'
|
||||
}
|
||||
except Exception as e:
|
||||
await sor.rollback()
|
||||
return {
|
||||
'status': False,
|
||||
'msg': 'publish news article failed, %s' % str(e)
|
||||
}
|
||||
|
||||
ret = await news_article_publish(params_kw)
|
||||
return ret
|
||||
78
b/news/news_article_search.dspy
Normal file
78
b/news/news_article_search.dspy
Normal file
@ -0,0 +1,78 @@
|
||||
async def news_article_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, "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'):
|
||||
conditions.append("article_type = '%s'" % ns.get('article_type'))
|
||||
if ns.get('status'):
|
||||
conditions.append("status = '%s'" % ns.get('status'))
|
||||
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']
|
||||
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, content,
|
||||
publish_time, read_count, update_time, create_at
|
||||
from enterprise_news_article
|
||||
where %s
|
||||
order by publish_time desc, update_time desc
|
||||
limit %s offset %s;
|
||||
""" % (where_clause, page_size, offset)
|
||||
result = await sor.sqlExe(search_sql, {})
|
||||
for data_dic in result:
|
||||
data_dic['status_name'] = {'0': '草稿', '1': '已发布'}.get(str(data_dic.get('status')), data_dic.get('status'))
|
||||
data_dic['operation_list'] = ['发布', '删除'] if str(data_dic.get('status')) == '0' else ['下架', '删除']
|
||||
return {
|
||||
'status': True,
|
||||
'msg': 'search news article success',
|
||||
'data': result,
|
||||
'article_type_summary': article_type_summary,
|
||||
'pagination': {
|
||||
'total': total_count,
|
||||
'page_size': page_size,
|
||||
'current_page': current_page
|
||||
}
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
'status': False,
|
||||
'msg': 'search news article failed, %s' % str(e)
|
||||
}
|
||||
|
||||
ret = await news_article_search(params_kw)
|
||||
return ret
|
||||
55
b/news/news_article_update.dspy
Normal file
55
b/news/news_article_update.dspy
Normal file
@ -0,0 +1,55 @@
|
||||
async def news_article_update(ns={}):
|
||||
if not ns.get('id'):
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '请传递id'
|
||||
}
|
||||
|
||||
ns_dic = {
|
||||
'id': ns.get('id')
|
||||
}
|
||||
if 'title' in ns:
|
||||
ns_dic['title'] = ns.get('title')
|
||||
if 'article_type' in ns:
|
||||
# if ns.get('article_type') not in ['企业动态', '产品动态', '行业洞察', '活动资讯']:
|
||||
# return {
|
||||
# 'status': False,
|
||||
# 'msg': '文章类型错误'
|
||||
# }
|
||||
ns_dic['article_type'] = ns.get('article_type')
|
||||
if 'summary' in ns:
|
||||
ns_dic['summary'] = ns.get('summary')
|
||||
if 'cover_img' in ns:
|
||||
ns_dic['cover_img'] = ns.get('cover_img')
|
||||
if 'content' in ns:
|
||||
ns_dic['content'] = ns.get('content')
|
||||
if 'status' in ns:
|
||||
if ns.get('status') not in ['0', '1']:
|
||||
return {
|
||||
'status': False,
|
||||
'msg': '状态错误'
|
||||
}
|
||||
ns_dic['status'] = ns.get('status')
|
||||
if 'publish_time' in ns:
|
||||
ns_dic['publish_time'] = ns.get('publish_time')
|
||||
|
||||
db = DBPools()
|
||||
async with db.sqlorContext('kboss') as sor:
|
||||
try:
|
||||
await sor.U('enterprise_news_article', ns_dic)
|
||||
if ns.get('status') == '1' and not ns.get('publish_time'):
|
||||
publish_sql = """update enterprise_news_article set publish_time = ifnull(publish_time, current_timestamp()) where id = '%s';""" % ns.get('id')
|
||||
await sor.sqlExe(publish_sql, {})
|
||||
return {
|
||||
'status': True,
|
||||
'msg': 'update news article success'
|
||||
}
|
||||
except Exception as e:
|
||||
await sor.rollback()
|
||||
return {
|
||||
'status': False,
|
||||
'msg': 'update news article failed, %s' % str(e)
|
||||
}
|
||||
|
||||
ret = await news_article_update(params_kw)
|
||||
return ret
|
||||
Loading…
x
Reference in New Issue
Block a user