Files
ALL-teach_sys/frontend_大健康/convert_health_qa_data.py
KQL cd2e307402 初始化12个产业教务系统项目
主要内容:
- 包含12个产业的完整教务系统前端代码
- 智能启动脚本 (start-industry.sh)
- 可视化产业导航页面 (index.html)
- 项目文档 (README.md)

优化内容:
- 删除所有node_modules和.yoyo文件夹,从7.5GB减少到2.7GB
- 添加.gitignore文件避免上传不必要的文件
- 自动依赖管理和智能启动系统

产业列表:
1. 文旅产业 (5150)
2. 智能制造 (5151)
3. 智能开发 (5152)
4. 财经商贸 (5153)
5. 视觉设计 (5154)
6. 交通物流 (5155)
7. 大健康 (5156)
8. 土木水利 (5157)
9. 食品产业 (5158)
10. 化工产业 (5159)
11. 能源产业 (5160)
12. 环保产业 (5161)

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 14:14:14 +08:00

171 lines
5.7 KiB
Python
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.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
from datetime import datetime
# 读取大健康问答内容数据
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/网页未导入数据/大健康产业/大健康问答内容.json', 'r', encoding='utf-8') as f:
health_qa_data = json.load(f)
# 导师头像映射
mentor_avatars = {
"李奇": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/teach_sys_teacher-avatar/recuW7dDIg60Tg.png",
"宋积极(配方师gigi)": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/teach_sys_teacher-avatar/recuW7dxJ5E4Al.png",
"吴兰": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/teach_sys_teacher-avatar/recuW7dxJ5t1Ii.png",
# 其他导师可以添加更多映射
}
# 默认机器人头像
robot_avatar = "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/img/teach_sys_icon/recuWmDuekBTlr.png"
# 转换为专家支持中心格式
conversations = []
for idx, item in enumerate(health_qa_data, 1):
messages = []
# 构建对话消息
# 流程1 - 用户问题
if item.get("问题_流程1"):
messages.append({
"type": "user",
"content": item["问题_流程1"],
"time": item["流程1_时间"]
})
# 流程2 - 助手回答
if item.get("回答_流程2"):
mentor_name = item.get("查询导师名称", "多多畅职机器人")
if item.get("问答类型") == "AI答疑":
mentor_name = "多多畅职机器人"
mentor_avatar = robot_avatar
else:
mentor_avatar = mentor_avatars.get(mentor_name, robot_avatar)
if mentor_name != "多多畅职机器人":
mentor_name += "老师"
messages.append({
"type": "assistant",
"content": item["回答_流程2"],
"mentor": mentor_name,
"time": item["流程2_时间"],
"mentorAvatar": mentor_avatar
})
# 流程3 - 用户问题
if item.get("问题_流程3"):
messages.append({
"type": "user",
"content": item["问题_流程3"],
"time": item["流程3_时间"]
})
# 流程4 - 助手回答
if item.get("回答_流程4"):
mentor_name = item.get("查询导师名称", "多多畅职机器人")
if item.get("问答类型") == "AI答疑":
mentor_name = "多多畅职机器人"
mentor_avatar = robot_avatar
else:
mentor_avatar = mentor_avatars.get(mentor_name, robot_avatar)
if mentor_name != "多多畅职机器人":
mentor_name += "老师"
messages.append({
"type": "assistant",
"content": item["回答_流程4"],
"mentor": mentor_name,
"time": item["流程4_时间"],
"mentorAvatar": mentor_avatar
})
# 流程5 - 用户问题
if item.get("问题_流程5"):
messages.append({
"type": "user",
"content": item["问题_流程5"],
"time": item["流程5_时间"]
})
# 流程6 - 助手回答
if item.get("回答_流程6"):
mentor_name = item.get("查询导师名称", "多多畅职机器人")
if item.get("问答类型") == "AI答疑":
mentor_name = "多多畅职机器人"
mentor_avatar = robot_avatar
else:
mentor_avatar = mentor_avatars.get(mentor_name, robot_avatar)
if mentor_name != "多多畅职机器人":
mentor_name += "老师"
messages.append({
"type": "assistant",
"content": item["回答_流程6"],
"mentor": mentor_name,
"time": item["流程6_时间"],
"mentorAvatar": mentor_avatar
})
# 获取对话日期(从第一条消息的时间提取年月)
if messages:
first_time = messages[0]["time"]
try:
# 解析时间格式 "2023/9/12 9:23"
date_obj = datetime.strptime(first_time, "%Y/%m/%d %H:%M")
conversation_date = f"{date_obj.year}{date_obj.month}"
except:
conversation_date = "2024年"
# 确定问答类型
qa_type = item.get("问答类型", "常规问题")
if qa_type == "导师问答":
qa_type = "专业知识"
elif qa_type == "AI答疑":
qa_type = "AI答疑"
else:
qa_type = "常规问题"
# 构建对话对象
if messages:
conversation = {
"id": idx,
"title": item.get("问题标题AI", f"问题{idx}"),
"status": "finish",
"date": conversation_date,
"type": qa_type,
"messages": messages
}
conversations.append(conversation)
# 按时间排序(从最早的第一条消息时间开始)
def get_first_message_time(conv):
if conv["messages"]:
time_str = conv["messages"][0]["time"]
try:
return datetime.strptime(time_str, "%Y/%m/%d %H:%M")
except:
return datetime.now()
return datetime.now()
# 按时间升序排序(早的在前)
conversations.sort(key=get_first_message_time)
# 构建最终的数据结构
expert_support_data = {
"conversations": conversations
}
# 生成JS文件内容
js_content = f"""// 从大健康问答内容.json转换的专家支持中心数据
const expertSupportData = {json.dumps(expert_support_data, ensure_ascii=False, indent=2)};
export default expertSupportData;"""
# 保存到文件
output_path = 'src/data/expertSupportData.js'
with open(output_path, 'w', encoding='utf-8') as f:
f.write(js_content)
print(f"✅ 成功转换 {len(conversations)} 条对话数据")
print(f"✅ 已保存到 {output_path}")