214 lines
7.0 KiB
Python
214 lines
7.0 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
import json
|
||
|
|
import re
|
||
|
|
|
||
|
|
def get_position_level_mapping():
|
||
|
|
"""从土木水利岗位简历中获取岗位等级映射"""
|
||
|
|
with open('网页未导入数据/土木水利产业/土木水利岗位简历.json', 'r', encoding='utf-8') as f:
|
||
|
|
resumes = json.load(f)
|
||
|
|
|
||
|
|
position_levels = {}
|
||
|
|
for resume in resumes:
|
||
|
|
position = resume.get('岗位名称', '')
|
||
|
|
level = resume.get('岗位等级标签', '')
|
||
|
|
if position and level:
|
||
|
|
position_levels[position] = level
|
||
|
|
|
||
|
|
return position_levels
|
||
|
|
|
||
|
|
def extract_sections(content):
|
||
|
|
"""从内容中提取概述、流程和关键点三个部分"""
|
||
|
|
overview = ""
|
||
|
|
process = ""
|
||
|
|
keyPoints = ""
|
||
|
|
|
||
|
|
if not content:
|
||
|
|
return overview, process, keyPoints
|
||
|
|
|
||
|
|
# 提取项目概述
|
||
|
|
overview_match = re.search(r'#\s*一、\s*项目概述(.*?)(?=#\s*二、|$)', content, re.DOTALL)
|
||
|
|
if overview_match:
|
||
|
|
overview = overview_match.group(1).strip()
|
||
|
|
|
||
|
|
# 提取项目流程
|
||
|
|
process_match = re.search(r'#\s*二、\s*项目整体流程介绍(.*?)(?=#\s*三、|$)', content, re.DOTALL)
|
||
|
|
if process_match:
|
||
|
|
process = process_match.group(1).strip()
|
||
|
|
|
||
|
|
# 提取关键技术点
|
||
|
|
keypoints_match = re.search(r'#\s*三、\s*项目案例关键技术点(.*?)$', content, re.DOTALL)
|
||
|
|
if keypoints_match:
|
||
|
|
keyPoints = keypoints_match.group(1).strip()
|
||
|
|
|
||
|
|
# 如果没有找到标准格式,使用默认处理
|
||
|
|
if not overview:
|
||
|
|
overview = content[:500].strip()
|
||
|
|
if len(content) > 500:
|
||
|
|
overview += "..."
|
||
|
|
|
||
|
|
if not process and not keyPoints:
|
||
|
|
remaining = content[len(overview):].strip() if overview in content else content
|
||
|
|
if remaining:
|
||
|
|
process = remaining
|
||
|
|
|
||
|
|
return overview, process, keyPoints
|
||
|
|
|
||
|
|
def update_project_positions_with_levels():
|
||
|
|
# 获取岗位等级映射
|
||
|
|
position_levels = get_position_level_mapping()
|
||
|
|
print(f"获取到{len(position_levels)}个岗位的等级映射")
|
||
|
|
|
||
|
|
# 显示部分映射
|
||
|
|
print("\n岗位等级映射示例:")
|
||
|
|
for pos, level in list(position_levels.items())[:5]:
|
||
|
|
print(f" {pos}: {level}")
|
||
|
|
|
||
|
|
# 读取土木水利项目案例数据
|
||
|
|
with open('网页未导入数据/土木水利产业/土木水利项目案例.json', 'r', encoding='utf-8') as f:
|
||
|
|
civil_data = json.load(f)
|
||
|
|
|
||
|
|
print(f"\n开始更新项目详情数据,共{len(civil_data)}个项目")
|
||
|
|
|
||
|
|
# 转换为班级项目库格式
|
||
|
|
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:
|
||
|
|
# 从映射中获取正确的等级
|
||
|
|
level = position_levels.get(pos, '技术骨干岗') # 默认为技术骨干岗
|
||
|
|
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 = extract_sections(content)
|
||
|
|
|
||
|
|
# 如果某部分为空,提供默认内容
|
||
|
|
if not overview:
|
||
|
|
overview = f"{project_name}是{direction}领域的重要实践项目,通过本项目的实施,学生能够掌握相关的专业技能和实践经验。"
|
||
|
|
|
||
|
|
if not process:
|
||
|
|
process = f"本项目按照标准的{direction}流程进行实施,包括需求分析、方案设计、实施执行、测试验收等关键环节。"
|
||
|
|
|
||
|
|
if not keyPoints:
|
||
|
|
keyPoints = f"1. 掌握{direction}的核心技术\\n2. 熟悉项目实施的完整流程\\n3. 培养解决实际问题的能力\\n4. 提升团队协作和沟通能力"
|
||
|
|
|
||
|
|
# 创建详情数据
|
||
|
|
detail_item = {
|
||
|
|
"id": idx,
|
||
|
|
"name": project_name,
|
||
|
|
"positions": position_detail_list, # 使用带正确等级的岗位列表
|
||
|
|
"unit": unit_name,
|
||
|
|
"overview": overview,
|
||
|
|
"process": process,
|
||
|
|
"keyPoints": keyPoints
|
||
|
|
}
|
||
|
|
projects_detail.append(detail_item)
|
||
|
|
|
||
|
|
# 显示处理进度
|
||
|
|
if idx <= 3:
|
||
|
|
print(f"\n项目{idx}: {project_name}")
|
||
|
|
print(f" 岗位及等级:")
|
||
|
|
for pos_detail in position_detail_list:
|
||
|
|
print(f" - {pos_detail['position']}: {pos_detail['level']}")
|
||
|
|
|
||
|
|
# 生成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" - 已使用土木水利岗位简历中的正确等级标签")
|
||
|
|
print(f" - 等级包括:实习生岗、技术骨干岗、储备干部岗")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
update_project_positions_with_levels()
|