169 lines
6.0 KiB
Python
169 lines
6.0 KiB
Python
|
|
import json
|
|||
|
|
|
|||
|
|
# 读取大健康项目案例数据
|
|||
|
|
with open('网页未导入数据/大健康产业/大健康项目案例.json', 'r', encoding='utf-8') as f:
|
|||
|
|
health_data = json.load(f)
|
|||
|
|
|
|||
|
|
# 转换为projectLibraryMock.js格式
|
|||
|
|
projects_list = []
|
|||
|
|
projects_detail = []
|
|||
|
|
|
|||
|
|
for idx, item in enumerate(health_data):
|
|||
|
|
project_id = f"health_{idx + 1}"
|
|||
|
|
|
|||
|
|
# 处理适用岗位 - 只包含岗位名称
|
|||
|
|
applicable_positions = []
|
|||
|
|
if item.get("对应个人简历名称"):
|
|||
|
|
positions = item["对应个人简历名称"].split(",")
|
|||
|
|
for pos in positions:
|
|||
|
|
applicable_positions.append({
|
|||
|
|
"position": pos.strip(),
|
|||
|
|
"level": "普通岗" # 默认级别
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
# 创建列表项
|
|||
|
|
list_item = {
|
|||
|
|
"id": project_id,
|
|||
|
|
"title": item["案例名称"],
|
|||
|
|
"category": item.get("所属垂直方向", "健康管理"),
|
|||
|
|
"description": "", # 从项目内容中提取概述
|
|||
|
|
"applicablePositions": applicable_positions,
|
|||
|
|
"compoundUnits": item.get("对应单元名称(复合能力课)", "").split(",") if item.get("对应单元名称(复合能力课)") else [],
|
|||
|
|
"verticalUnits": item.get("对应单元名称(垂直能力课)", "").split(",") if item.get("对应单元名称(垂直能力课)") else []
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 从项目内容中提取概述
|
|||
|
|
content = item.get("项目案例内容", "")
|
|||
|
|
if "# 一、项目概述" in content:
|
|||
|
|
overview_start = content.index("# 一、项目概述") + len("# 一、项目概述")
|
|||
|
|
overview_end = content.find("# 二、", overview_start) if "# 二、" in content[overview_start:] else len(content)
|
|||
|
|
overview = content[overview_start:overview_end].strip()
|
|||
|
|
# 清理换行符并取前200字作为描述
|
|||
|
|
overview = overview.replace('\n\n', ' ').replace('\n', '')[:200] + '...'
|
|||
|
|
list_item["description"] = overview
|
|||
|
|
|
|||
|
|
projects_list.append(list_item)
|
|||
|
|
|
|||
|
|
# 创建详情项 - 使用新的数据结构
|
|||
|
|
sections = []
|
|||
|
|
|
|||
|
|
# 解析项目内容中的各个部分
|
|||
|
|
if "# 二、项目整体流程介绍" in content:
|
|||
|
|
process_start = content.index("# 二、项目整体流程介绍")
|
|||
|
|
process_end = content.find("# 三、", process_start) if "# 三、" in content[process_start:] else len(content)
|
|||
|
|
process_content = content[process_start:process_end].strip()
|
|||
|
|
|
|||
|
|
sections.append({
|
|||
|
|
"title": "项目整体流程介绍",
|
|||
|
|
"content": process_content.replace("# 二、项目整体流程介绍", "").strip()
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
if "# 三、项目" in content:
|
|||
|
|
tech_start = content.index("# 三、项目")
|
|||
|
|
tech_content = content[tech_start:].strip()
|
|||
|
|
|
|||
|
|
sections.append({
|
|||
|
|
"title": "项目关键技术点",
|
|||
|
|
"content": tech_content.replace("# 三、项目案例关键技术点", "").replace("# 三、项目关键技术与创新点", "").strip()
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
detail_item = {
|
|||
|
|
"id": project_id,
|
|||
|
|
"title": item["案例名称"],
|
|||
|
|
"category": item.get("所属垂直方向", "健康管理"),
|
|||
|
|
"overview": list_item["description"],
|
|||
|
|
"sections": sections,
|
|||
|
|
"images": [], # 暂无图片
|
|||
|
|
"applicablePositions": applicable_positions
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
projects_detail.append(detail_item)
|
|||
|
|
|
|||
|
|
# 创建projectUnitsMapping数据
|
|||
|
|
units_mapping = {}
|
|||
|
|
for item in health_data:
|
|||
|
|
project_name = item["案例名称"]
|
|||
|
|
compound_units = [u.strip() for u in item.get("对应单元名称(复合能力课)", "").split(",") if u.strip()]
|
|||
|
|
vertical_units = [u.strip() for u in item.get("对应单元名称(垂直能力课)", "").split(",") if u.strip()]
|
|||
|
|
|
|||
|
|
units_mapping[project_name] = {
|
|||
|
|
"compoundUnits": compound_units,
|
|||
|
|
"verticalUnits": vertical_units
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 生成projectLibraryMock.js内容
|
|||
|
|
mock_js_content = f"""// 项目库Mock数据 - 大健康产业
|
|||
|
|
export const projectsData = {json.dumps(projects_list, ensure_ascii=False, indent=2)};
|
|||
|
|
|
|||
|
|
// 项目详情数据
|
|||
|
|
export const projectsDetail = {json.dumps(projects_detail, ensure_ascii=False, indent=2)};
|
|||
|
|
|
|||
|
|
// 统一导出
|
|||
|
|
const projectLibraryMock = {{
|
|||
|
|
list: projectsData,
|
|||
|
|
detail: projectsDetail
|
|||
|
|
}};
|
|||
|
|
|
|||
|
|
export default projectLibraryMock;
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
# 生成projectUnitsMapping.js内容
|
|||
|
|
mapping_js_content = f"""// 项目案例对应单元映射数据 - 大健康产业
|
|||
|
|
|
|||
|
|
export const projectUnitsMapping = {json.dumps(units_mapping, ensure_ascii=False, indent=2)};
|
|||
|
|
|
|||
|
|
// 获取项目的复合能力课程
|
|||
|
|
export const getCompoundUnits = (projectTitle) => {{
|
|||
|
|
if (!projectTitle) return [];
|
|||
|
|
|
|||
|
|
// 直接匹配
|
|||
|
|
if (projectUnitsMapping[projectTitle]) {{
|
|||
|
|
return projectUnitsMapping[projectTitle].compoundUnits || [];
|
|||
|
|
}}
|
|||
|
|
|
|||
|
|
// 尝试去除后缀后匹配(如"详情")
|
|||
|
|
const cleanTitle = projectTitle.replace(/详情$/, '');
|
|||
|
|
if (projectUnitsMapping[cleanTitle]) {{
|
|||
|
|
return projectUnitsMapping[cleanTitle].compoundUnits || [];
|
|||
|
|
}}
|
|||
|
|
|
|||
|
|
return [];
|
|||
|
|
}};
|
|||
|
|
|
|||
|
|
// 获取项目的垂直能力课程
|
|||
|
|
export const getVerticalUnits = (projectTitle) => {{
|
|||
|
|
if (!projectTitle) return [];
|
|||
|
|
|
|||
|
|
// 直接匹配
|
|||
|
|
if (projectUnitsMapping[projectTitle]) {{
|
|||
|
|
return projectUnitsMapping[projectTitle].verticalUnits || [];
|
|||
|
|
}}
|
|||
|
|
|
|||
|
|
// 尝试去除后缀后匹配(如"详情")
|
|||
|
|
const cleanTitle = projectTitle.replace(/详情$/, '');
|
|||
|
|
if (projectUnitsMapping[cleanTitle]) {{
|
|||
|
|
return projectUnitsMapping[cleanTitle].verticalUnits || [];
|
|||
|
|
}}
|
|||
|
|
|
|||
|
|
return [];
|
|||
|
|
}};
|
|||
|
|
|
|||
|
|
// 获取项目的所有对应单元
|
|||
|
|
export const getProjectUnits = (projectTitle) => {{
|
|||
|
|
const mapping = projectUnitsMapping[projectTitle];
|
|||
|
|
if (!mapping) return [];
|
|||
|
|
|
|||
|
|
return [...mapping.compoundUnits, ...mapping.verticalUnits];
|
|||
|
|
}};
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
# 写入文件
|
|||
|
|
with open('src/mocks/projectLibraryMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(mock_js_content)
|
|||
|
|
|
|||
|
|
with open('src/data/projectUnitsMapping.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(mapping_js_content)
|
|||
|
|
|
|||
|
|
print(f"成功转换 {len(health_data)} 个大健康项目案例")
|
|||
|
|
print(f"已更新 src/mocks/projectLibraryMock.js")
|
|||
|
|
print(f"已更新 src/data/projectUnitsMapping.js")
|