192 lines
6.8 KiB
Python
192 lines
6.8 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def clean_markdown_content(content):
|
|||
|
|
"""清理Markdown内容,确保格式正确"""
|
|||
|
|
if not content:
|
|||
|
|
return ""
|
|||
|
|
# 保持Markdown格式,但清理多余空白
|
|||
|
|
content = content.strip()
|
|||
|
|
# 确保标题格式正确
|
|||
|
|
content = re.sub(r'\n{3,}', '\n\n', content)
|
|||
|
|
return content
|
|||
|
|
|
|||
|
|
def convert_civil_projects():
|
|||
|
|
# 读取土木水利项目案例数据
|
|||
|
|
with open('网页未导入数据/土木水利产业/土木水利项目案例.json', 'r', encoding='utf-8') as f:
|
|||
|
|
civil_data = json.load(f)
|
|||
|
|
|
|||
|
|
print(f"土木水利项目总数: {len(civil_data)}")
|
|||
|
|
|
|||
|
|
# 获取所有垂直方向(用于分类)
|
|||
|
|
directions = list(set([item['所属垂直方向'] for item in civil_data if '所属垂直方向' in item]))
|
|||
|
|
print(f"项目方向分类: {directions}")
|
|||
|
|
|
|||
|
|
# 转换为班级项目库格式
|
|||
|
|
projects_list = []
|
|||
|
|
projects_detail = []
|
|||
|
|
|
|||
|
|
for idx, item in enumerate(civil_data, 1):
|
|||
|
|
# 提取字段
|
|||
|
|
project_name = item.get('案例名称', '')
|
|||
|
|
direction = item.get('所属垂直方向', '综合项目')
|
|||
|
|
content = item.get('项目案例内容', '')
|
|||
|
|
units = item.get('对应单元名称(垂直能力课)', '')
|
|||
|
|
positions = item.get('对应个人简历名称', '')
|
|||
|
|
|
|||
|
|
# 处理岗位列表
|
|||
|
|
position_list = []
|
|||
|
|
position_detail_list = []
|
|||
|
|
if positions:
|
|||
|
|
pos_names = [p.strip() for p in positions.split(',')]
|
|||
|
|
position_list = pos_names
|
|||
|
|
# 为详情创建带等级的岗位列表
|
|||
|
|
for pos in pos_names:
|
|||
|
|
# 根据岗位名称判断等级
|
|||
|
|
if '助理' in pos or '实习' in pos:
|
|||
|
|
level = "实习生岗"
|
|||
|
|
elif '经理' in pos or '主管' in pos:
|
|||
|
|
level = "储备干部岗"
|
|||
|
|
else:
|
|||
|
|
level = "技术骨干岗"
|
|||
|
|
position_detail_list.append({
|
|||
|
|
"level": level,
|
|||
|
|
"position": pos
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
# 处理单元名称(可能有多个)
|
|||
|
|
unit_name = units.split(',')[0] if units else direction
|
|||
|
|
|
|||
|
|
# 创建列表数据
|
|||
|
|
list_item = {
|
|||
|
|
"id": idx,
|
|||
|
|
"name": project_name,
|
|||
|
|
"description": direction, # 项目方向作为描述
|
|||
|
|
"positions": position_list,
|
|||
|
|
"unit": unit_name,
|
|||
|
|
"direction": direction, # 用于分类筛选
|
|||
|
|
"category": direction.split('与')[0] if '与' in direction else direction
|
|||
|
|
}
|
|||
|
|
projects_list.append(list_item)
|
|||
|
|
|
|||
|
|
# 处理项目内容,分解为概述、流程和关键点
|
|||
|
|
overview = ""
|
|||
|
|
process = ""
|
|||
|
|
keyPoints = ""
|
|||
|
|
|
|||
|
|
if content:
|
|||
|
|
# 尝试从内容中提取各部分
|
|||
|
|
sections = re.split(r'#+\s*', content)
|
|||
|
|
|
|||
|
|
# 查找概述部分
|
|||
|
|
for section in sections:
|
|||
|
|
if '项目概述' in section or '项目背景' in section or '概述' in section:
|
|||
|
|
overview = section.split('\n', 1)[1] if '\n' in section else section
|
|||
|
|
overview = clean_markdown_content(overview)
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 如果没有找到概述,使用前200字作为概述
|
|||
|
|
if not overview and content:
|
|||
|
|
overview = content[:500] + "..."
|
|||
|
|
|
|||
|
|
# 查找流程部分
|
|||
|
|
for section in sections:
|
|||
|
|
if '流程' in section or '任务' in section or '实施' in section or '步骤' in section:
|
|||
|
|
process = "### " + section
|
|||
|
|
process = clean_markdown_content(process)
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 查找关键点
|
|||
|
|
for section in sections:
|
|||
|
|
if '关键' in section or '要点' in section or '成果' in section or '总结' in section:
|
|||
|
|
keyPoints = "### " + section
|
|||
|
|
keyPoints = clean_markdown_content(keyPoints)
|
|||
|
|
break
|
|||
|
|
|
|||
|
|
# 如果没有分离出流程和关键点,将整个内容作为流程
|
|||
|
|
if not process and not keyPoints:
|
|||
|
|
process = clean_markdown_content(content)
|
|||
|
|
|
|||
|
|
# 创建详情数据
|
|||
|
|
detail_item = {
|
|||
|
|
"id": idx,
|
|||
|
|
"name": project_name,
|
|||
|
|
"positions": position_detail_list,
|
|||
|
|
"unit": unit_name,
|
|||
|
|
"overview": overview or f"{project_name}是{direction}领域的重要实践项目,通过本项目的实施,学生能够掌握相关的专业技能和实践经验。",
|
|||
|
|
"process": process or f"### 项目实施流程\n\n本项目按照标准的{direction}流程进行实施,包括需求分析、方案设计、实施执行、测试验收等关键环节。",
|
|||
|
|
"keyPoints": keyPoints or f"### 项目关键要点\n\n1. 掌握{direction}的核心技术\n2. 熟悉项目实施的完整流程\n3. 培养解决实际问题的能力\n4. 提升团队协作和沟通能力"
|
|||
|
|
}
|
|||
|
|
projects_detail.append(detail_item)
|
|||
|
|
|
|||
|
|
# 生成JavaScript代码
|
|||
|
|
output = """// 项目库Mock数据
|
|||
|
|
export const getMockProjectsList = (params = {}) => {
|
|||
|
|
const { search = "", page = 1, pageSize = 10 } = params;
|
|||
|
|
|
|||
|
|
// 完整项目列表数据
|
|||
|
|
const projects = """
|
|||
|
|
|
|||
|
|
output += json.dumps(projects_list, ensure_ascii=False, indent=2)
|
|||
|
|
output += ";\n\n"
|
|||
|
|
|
|||
|
|
output += """ // 根据搜索条件过滤
|
|||
|
|
let filteredProjects = projects;
|
|||
|
|
if (search) {
|
|||
|
|
filteredProjects = projects.filter(project =>
|
|||
|
|
project.name.toLowerCase().includes(search.toLowerCase()) ||
|
|||
|
|
project.description.toLowerCase().includes(search.toLowerCase())
|
|||
|
|
);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 分页处理
|
|||
|
|
const startIndex = (page - 1) * pageSize;
|
|||
|
|
const endIndex = startIndex + pageSize;
|
|||
|
|
const paginatedProjects = filteredProjects.slice(startIndex, endIndex);
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
success: true,
|
|||
|
|
data: paginatedProjects,
|
|||
|
|
total: filteredProjects.length,
|
|||
|
|
page: page,
|
|||
|
|
pageSize: pageSize
|
|||
|
|
};
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 获取项目详情
|
|||
|
|
export const getMockProjectDetail = (id) => {
|
|||
|
|
// 直接根据ID返回对应项目的详情
|
|||
|
|
const projects = """
|
|||
|
|
|
|||
|
|
output += json.dumps(projects_detail, ensure_ascii=False, indent=2)
|
|||
|
|
output += """;\n
|
|||
|
|
const project = projects.find(p => p.id === parseInt(id));
|
|||
|
|
|
|||
|
|
if (project) {
|
|||
|
|
return {
|
|||
|
|
success: true,
|
|||
|
|
data: project
|
|||
|
|
};
|
|||
|
|
} else {
|
|||
|
|
return {
|
|||
|
|
success: false,
|
|||
|
|
message: "项目不存在"
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
# 保存到文件
|
|||
|
|
with open('src/mocks/projectLibraryMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(output)
|
|||
|
|
|
|||
|
|
print(f"\n✅ 班级项目库数据已替换完成")
|
|||
|
|
print(f" - 项目列表: {len(projects_list)}个项目")
|
|||
|
|
print(f" - 项目详情: {len(projects_detail)}个项目")
|
|||
|
|
print(f" - 项目分类: {', '.join(directions)}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
convert_civil_projects()
|