kboss/b/product/search_user_inquiry.dspy
2025-08-19 15:27:26 +08:00

58 lines
2.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

async def search_user_inquiry(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'
db = DBPools()
async with db.sqlorContext('kboss') as sor:
search_sql = """select * from product_inquiry where domain_name = '%s' and del_flg = '0' order by update_time desc;""" % domain_name
result = await sor.sqlExe(search_sql, {})
if ns.get('to_excel') == '1':
# 创建映射字段 导出execl
# 结果转换成 中文名称:值 的字典列表
field_mapping = {
'name': '联系人姓名',
'custom_type': '客户类型',
'phone': '联系人电话',
'email': '邮箱',
'company': '公司名称',
'content': '咨询内容',
'feedback': '反馈状态',
}
# 新增值映射字典,集中管理各字段的数值转换规则
value_mapping = {
'custom_type': {'0': '个人', '1': '企业'},
'feedback': {'0': '未反馈', '1': '已反馈'} # 根据表结构补充反馈状态映射
}
# 转换字典键为中文
for data_dic in result:
# 拆分后:显式循环结构(便于后续处理)
new_data_dic = {}
# 按field_mapping定义的顺序处理字段确保输出顺序一致
for key in field_mapping.keys():
# 跳过数据中不存在的字段
if key not in data_dic:
continue
value = data_dic[key]
chinese_key = field_mapping[key]
if key in value_mapping:
mapped_value = value_mapping[key].get(str(value), value) # 若未找到对应映射,保留原始值
new_data_dic[chinese_key] = mapped_value
else:
new_data_dic[chinese_key] = value
data_dic.clear()
data_dic.update(new_data_dic)
return {
'status': True,
'msg': 'search success',
'data': result
}
ret = await search_user_inquiry(params_kw)
return ret