Files
ALL-teach_sys/frontend_能源/fix_project_details_final.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

132 lines
5.5 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
import re
def create_js_template_string(text):
"""
创建JavaScript模板字符串格式用反引号包围以支持多行
"""
if not text:
return '``'
# 转义反引号和反斜杠
text = text.replace('\\', '\\\\')
text = text.replace('`', '\\`')
text = text.replace('${', '\\${') # 转义模板字符串插值
return f'`{text}`'
def extract_sections_from_content(content):
"""
从项目案例内容中提取overview、process、keyPoints等部分
"""
# 提取一、项目概述部分
overview_match = re.search(r'# 一、项目概述\n\n(.*?)(?=\n# 二、)', content, re.DOTALL)
overview = overview_match.group(1).strip() if overview_match else ""
# 提取二、项目整体流程介绍部分
process_match = re.search(r'# 二、项目整体流程介绍\n\n(.*?)(?=\n# 三、)', content, re.DOTALL)
process = process_match.group(1).strip() if process_match else ""
# 提取三、项目案例关键技术点部分
keypoints_match = re.search(r'# 三、项目案例关键技术点\n\n(.*)', content, re.DOTALL)
keypoints = keypoints_match.group(1).strip() if keypoints_match else ""
return overview, process, keypoints
def fix_project_details_final():
"""
最终修复projectLibraryMock.js文件中的项目详情数据
"""
# 读取能源项目案例数据
with open("网页未导入数据/能源产业/能源项目案例.json", 'r', encoding='utf-8') as f:
energy_projects = json.load(f)
# 转换项目详情数据
converted_details = []
for idx, project in enumerate(energy_projects, 1):
# 提取项目案例内容的各个部分
content = project.get("项目案例内容", "")
overview, process, keypoints = extract_sections_from_content(content)
# 处理岗位信息
resume_names = project.get("对应个人简历名称", "").split(",")
positions = []
for name in resume_names:
name = name.strip()
if name:
positions.append({
"level": "技术骨干岗",
"position": name
})
if not positions:
positions = [{"level": "技术骨干岗", "position": "能源工程师"}]
# 提取对应单元名称
vertical_units = project.get("对应单元名称(垂直能力课)", "").split(",")
unit = vertical_units[0].strip() if vertical_units else "能源技术基础"
# 使用模板字符串处理文本内容
safe_overview = create_js_template_string(overview) if overview else '`本项目聚焦能源产业核心技术领域,通过系统化的技术实施和管理优化,实现高效、安全、可持续的能源系统运营。`'
safe_process = create_js_template_string(process) if process else '`### 流程一:前期准备与需求分析\n\n1. 进行全面的技术需求调研和可行性分析\n2. 制定详细的项目实施方案和时间计划\n\n### 流程二:系统设计与优化\n\n1. 完成核心技术方案设计\n2. 进行系统集成和性能优化\n\n### 流程三:实施与验收\n\n1. 按计划实施项目各项内容\n2. 完成系统测试和项目验收`'
safe_keypoints = create_js_template_string(keypoints) if keypoints else '`### (一)核心技术应用\n\n1. 应用先进的能源技术和管理方法\n2. 实现系统的高效稳定运行\n\n### (二)安全管理体系\n\n1. 建立完善的安全管理制度\n2. 确保项目实施过程的安全可控\n\n### (三)持续优化改进\n\n1. 建立持续改进机制\n2. 不断提升系统性能和效益`'
converted_detail = {
"id": idx,
"name": project["案例名称"],
"positions": positions,
"unit": unit,
"overview": safe_overview,
"process": safe_process,
"keyPoints": safe_keypoints
}
converted_details.append(converted_detail)
# 读取现有Mock文件
with open("src/mocks/projectLibraryMock.js", 'r', encoding='utf-8') as f:
content = f.read()
# 生成新的项目详情数据JavaScript格式
details_js = "[\n"
for detail in converted_details:
# 处理positions数组
positions_str = ""
for pos in detail['positions']:
positions_str += f' {{\n "level": "{pos["level"]}",\n "position": "{pos["position"]}"\n }},\n'
positions_str = positions_str.rstrip(',\n')
details_js += f''' {{
"id": {detail['id']},
"name": "{detail['name']}",
"positions": [
{positions_str}
],
"unit": "{detail['unit']}",
"overview": {detail['overview']},
"process": {detail['process']},
"keyPoints": {detail['keyPoints']}
}},
'''
details_js = details_js.rstrip(',\n') + "\n ]"
# 替换项目详情数组查找getMockProjectDetail函数中的projects数组
pattern = r'(export const getMockProjectDetail = \(id\) => \{\s*// 直接根据ID返回对应项目的详情\s*const projects = )\[[\s\S]*?\];'
replacement = f'\\g<1>{details_js};'
updated_content = re.sub(pattern, replacement, content)
# 写入更新后的内容
with open("src/mocks/projectLibraryMock.js", 'w', encoding='utf-8') as f:
f.write(updated_content)
print(f"✅ 最终修复完成,已使用模板字符串处理 {len(converted_details)} 个能源项目详情")
if __name__ == "__main__":
fix_project_details_final()