120 lines
4.6 KiB
Plaintext
120 lines
4.6 KiB
Plaintext
async def publish_product_to_excel(ns={}):
|
|
if not ns.get('ids') and (not ns.get('result')):
|
|
return {
|
|
'status': False,
|
|
'msg': '请传递产品ID'
|
|
}
|
|
result = []
|
|
if ns.get('ids'):
|
|
db = DBPools()
|
|
async with db.sqlorContext('kboss') as sor:
|
|
ids = json.loads(ns.get('ids')) if isinstance(ns.get('ids'), str) else ns.get('ids')
|
|
# 根据ids查询user_publish_product表
|
|
find_sql = """SELECT * FROM user_publish_product WHERE id IN (%s) AND del_flg = '0';""" % ','.join(["'%s'" % id for id in ids])
|
|
result = await sor.sqlExe(find_sql, {})
|
|
if not result:
|
|
return {
|
|
'status': False,
|
|
'msg': '没有找到匹配的产品'
|
|
}
|
|
if ns.get('result_from_search'):
|
|
result = ns.get('result_from_search')
|
|
|
|
# 结果转换成 中文名称:值 的字典列表
|
|
field_mapping = {
|
|
# 'id': 'id',
|
|
# 'publish_type': '类型',
|
|
'img': '图片链接',
|
|
# 'cart_flag': '是否支持显卡',
|
|
# 'domain_name': '所属域名',
|
|
# 'orgid': '所属机构',
|
|
'product_name': '商品名称',
|
|
# 'product_category': '所属类别',
|
|
'company_name': '企业名称',
|
|
# 'company_type': '公司类别',
|
|
'contact_person': '联系人',
|
|
'job_title': '职务',
|
|
'phone_number': '手机号码',
|
|
'email': '邮箱',
|
|
'cpu': 'cpu',
|
|
'memory': '内存',
|
|
'gpu': 'gpu',
|
|
'sys_disk': '系统盘',
|
|
'data_disk': '数据盘',
|
|
'net_card': '网卡',
|
|
'price': '价格',
|
|
'unit': '价格单位',
|
|
'discount': '价格折扣',
|
|
'discount_price': '折扣后价格',
|
|
'service_charge': '服务费',
|
|
'short_term': '是否短租',
|
|
# 'priority': '排序优先级',
|
|
'status': '上架状态',
|
|
# 'title': '主题',
|
|
# 'label': '标签',
|
|
# 'first_page': '是否推送到首页',
|
|
# 'admin_push': '是否是运营人员提交',
|
|
'requirement_summary': '需求概述',
|
|
'related_parameters': '相关参数',
|
|
'application_scenario': '应用场景',
|
|
'audit_status': '审核状态',
|
|
'listing_status': '上架状态',
|
|
'reject_reason': '驳回原因',
|
|
'update_time': '更新时间',
|
|
'create_at': '创建时间',
|
|
# 'publish_time': '发布日期',
|
|
# 'del_flg': '删除标志'
|
|
}
|
|
# 转换字典键为中文
|
|
for data_dic in result:
|
|
# 如果有图片路径 则转换为完整的图片链接
|
|
if data_dic.get('img') and data_dic['img'] != 'null':
|
|
data_dic['img'] = 'https://' + data_dic['domain_name'] + '/idfile?path=' + data_dic['img']
|
|
else:
|
|
data_dic['img'] = None
|
|
# 转换字典键为中文 对应的值要有映射
|
|
# 拆分后:显式循环结构(便于后续处理)
|
|
new_data_dic = {}
|
|
for key, value in data_dic.items():
|
|
if key == 'publish_type':
|
|
# 显示类型映射
|
|
if value == '1':
|
|
value = '产品'
|
|
elif value == '2':
|
|
value = '需求'
|
|
if key == 'audit_status':
|
|
# 显示审核状态映射
|
|
if value == 'pending':
|
|
value = '待审'
|
|
elif value == 'approved':
|
|
value = '通过'
|
|
elif value == 'rejected':
|
|
value = '拒绝'
|
|
if key == 'listing_status':
|
|
# 显示上架状态映射
|
|
if value == '1':
|
|
value = '上架'
|
|
elif value == '0':
|
|
value = '下架'
|
|
if key == 'short_term':
|
|
# 显示短租状态映射
|
|
if value == '1':
|
|
value = '是'
|
|
elif value == '0':
|
|
value = '否'
|
|
# 获取中文映射键
|
|
chinese_key = field_mapping.get(key)
|
|
# 仅保留有映射关系的字段
|
|
if chinese_key is not None:
|
|
new_data_dic[chinese_key] = value
|
|
data_dic.clear()
|
|
data_dic.update(new_data_dic)
|
|
|
|
return {
|
|
'status': True,
|
|
'msg': 'export to excel success',
|
|
'data': result
|
|
}
|
|
|
|
ret = await publish_product_to_excel(params_kw)
|
|
return ret |