154 lines
6.8 KiB
Python
154 lines
6.8 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
import json
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
# 读取源数据
|
|||
|
|
with open('网页未导入数据/交通物流产业/交通物流项目案例.json', 'r', encoding='utf-8') as f:
|
|||
|
|
source_data = json.load(f)
|
|||
|
|
|
|||
|
|
# 读取现有的mock文件来获取项目列表部分
|
|||
|
|
with open('src/mocks/projectLibraryMock.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 提取getMockProjectsList函数
|
|||
|
|
projects_list_match = re.search(r'(export const getMockProjectsList.*?)export const getMockProjectDetail', content, re.DOTALL)
|
|||
|
|
if not projects_list_match:
|
|||
|
|
print("无法找到getMockProjectsList函数")
|
|||
|
|
exit(1)
|
|||
|
|
|
|||
|
|
projects_list_func = projects_list_match.group(1).rstrip()
|
|||
|
|
|
|||
|
|
# 定义岗位等级映射
|
|||
|
|
position_levels = {
|
|||
|
|
'WMS软件销售': '普通岗',
|
|||
|
|
'物流协调员': '普通岗',
|
|||
|
|
'仓储业务开发专员': '技术骨干岗',
|
|||
|
|
'AGV运维专员': '技术骨干岗',
|
|||
|
|
'AGV运维工程师': '高级管理岗',
|
|||
|
|
'物流审核员': '普通岗',
|
|||
|
|
'云物流调度负责人助理': '高级管理岗',
|
|||
|
|
'物流运营总监助理': '高级管理岗',
|
|||
|
|
'生产计划岗储备干部': '技术骨干岗',
|
|||
|
|
'国际物流储备经理': '高级管理岗',
|
|||
|
|
'供应链总监助理': '高级管理岗',
|
|||
|
|
'TMS销售专员': '普通岗',
|
|||
|
|
'海外运输经理助理': '高级管理岗',
|
|||
|
|
'海外物流协调员': '技术骨干岗',
|
|||
|
|
'海外仓设备运维工程师': '技术骨干岗',
|
|||
|
|
'售后支持专员': '普通岗',
|
|||
|
|
'采购专员': '普通岗',
|
|||
|
|
'港口安全员': '技术骨干岗'
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
# 构建新的getMockProjectDetail函数
|
|||
|
|
detail_func_parts = ['export const getMockProjectDetail = (id) => {']
|
|||
|
|
detail_func_parts.append(' const projects = [')
|
|||
|
|
|
|||
|
|
for idx, project in enumerate(source_data, 1):
|
|||
|
|
name = project['案例名称']
|
|||
|
|
content_text = project['项目案例内容']
|
|||
|
|
|
|||
|
|
# 使用更精确的分割方式
|
|||
|
|
# 1. 提取项目概述(到"# 二、项目整体流程介绍"之前)
|
|||
|
|
overview_match = re.search(r'^(.*?)(?=# 二、项目整体流程介绍)', content_text, re.DOTALL | re.MULTILINE)
|
|||
|
|
overview = overview_match.group(1).strip() if overview_match else ''
|
|||
|
|
|
|||
|
|
# 2. 提取项目流程(从"# 二、项目整体流程介绍"到"# 三、项目案例关键技术点"之间)
|
|||
|
|
process_match = re.search(r'# 二、项目整体流程介绍(.*?)(?=# 三、项目案例关键技术点|$)', content_text, re.DOTALL | re.MULTILINE)
|
|||
|
|
process = process_match.group(1).strip() if process_match else ''
|
|||
|
|
|
|||
|
|
# 3. 提取关键技术点(从"# 三、项目案例关键技术点"到结束)
|
|||
|
|
keypoints_match = re.search(r'# 三、项目案例关键技术点(.*?)$', content_text, re.DOTALL | re.MULTILINE)
|
|||
|
|
keypoints = keypoints_match.group(1).strip() if keypoints_match else ''
|
|||
|
|
|
|||
|
|
# 如果没有找到主要部分,尝试其他格式
|
|||
|
|
if not overview:
|
|||
|
|
# 如果没有"# 二、"格式,尝试提取到"##"之前的内容作为概述
|
|||
|
|
overview_match = re.search(r'^(.*?)(?=##)', content_text, re.DOTALL)
|
|||
|
|
overview = overview_match.group(1).strip() if overview_match else content_text[:1000]
|
|||
|
|
|
|||
|
|
if not process and not keypoints:
|
|||
|
|
# 如果没有明确的流程和技术点分隔,尝试找"##"开头的内容
|
|||
|
|
sections = re.split(r'(?=## )', content_text)
|
|||
|
|
if len(sections) > 1:
|
|||
|
|
# 如果有多个section,第二个作为流程,剩余作为技术点
|
|||
|
|
process = sections[1] if len(sections) > 1 else ''
|
|||
|
|
keypoints = '\n'.join(sections[2:]) if len(sections) > 2 else sections[-1] if len(sections) > 1 else ''
|
|||
|
|
|
|||
|
|
# 重要:对模板字符串内容进行转义
|
|||
|
|
overview = overview.replace('\\', '\\\\').replace('`', '\\`').replace('${', '\\${')
|
|||
|
|
process = process.replace('\\', '\\\\').replace('`', '\\`').replace('${', '\\${')
|
|||
|
|
keypoints = keypoints.replace('\\', '\\\\').replace('`', '\\`').replace('${', '\\${')
|
|||
|
|
|
|||
|
|
# 获取岗位列表并转换为对象数组
|
|||
|
|
positions_list = [
|
|||
|
|
'WMS软件销售', '物流协调员', '仓储业务开发专员', 'AGV运维专员',
|
|||
|
|
'AGV运维工程师', '物流审核员', '云物流调度负责人助理',
|
|||
|
|
'物流运营总监助理', '生产计划岗储备干部', '国际物流储备经理'
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
# 转换为对象数组格式
|
|||
|
|
applicable_positions = []
|
|||
|
|
for pos in positions_list[:5]: # 每个项目取5个岗位
|
|||
|
|
applicable_positions.append({
|
|||
|
|
'position': pos,
|
|||
|
|
'level': position_levels.get(pos, '普通岗')
|
|||
|
|
})
|
|||
|
|
|
|||
|
|
attachments = [
|
|||
|
|
{'name': f'{name}_项目方案.pdf', 'type': 'pdf'},
|
|||
|
|
{'name': f'{name}_技术文档.docx', 'type': 'docx'}
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
# 如果流程或技术点为空,使用备用内容
|
|||
|
|
if not process.strip():
|
|||
|
|
process = '项目流程详情请参考项目概述'
|
|||
|
|
if not keypoints.strip():
|
|||
|
|
keypoints = '技术要点详情请参考项目概述'
|
|||
|
|
|
|||
|
|
# 添加标题(如果原文没有)
|
|||
|
|
if not process.startswith('#'):
|
|||
|
|
process = '## 项目整体流程介绍\\n\\n' + process
|
|||
|
|
if not keypoints.startswith('#'):
|
|||
|
|
keypoints = '## 项目案例关键技术点\\n\\n' + keypoints
|
|||
|
|
|
|||
|
|
detail_func_parts.append(f''' {{
|
|||
|
|
id: {idx},
|
|||
|
|
name: "{name}",
|
|||
|
|
title: "{name}", // 添加title字段以兼容组件
|
|||
|
|
overview: `{overview}`,
|
|||
|
|
description: `{overview}`, // 添加description字段作为备用
|
|||
|
|
process: `{process}`,
|
|||
|
|
keyPoints: `{keypoints}`,
|
|||
|
|
applicablePositions: {json.dumps(applicable_positions, ensure_ascii=False)},
|
|||
|
|
attachments: {json.dumps(attachments, ensure_ascii=False)}
|
|||
|
|
}}{',' if idx < len(source_data) else ''}''')
|
|||
|
|
|
|||
|
|
detail_func_parts.append(' ];')
|
|||
|
|
detail_func_parts.append('')
|
|||
|
|
detail_func_parts.append(' const project = projects.find(p => p.id === parseInt(id));')
|
|||
|
|
detail_func_parts.append(' if (!project) {')
|
|||
|
|
detail_func_parts.append(' return {')
|
|||
|
|
detail_func_parts.append(' id: parseInt(id),')
|
|||
|
|
detail_func_parts.append(" name: '项目未找到',")
|
|||
|
|
detail_func_parts.append(" title: '项目未找到',")
|
|||
|
|
detail_func_parts.append(" overview: '项目详情未找到',")
|
|||
|
|
detail_func_parts.append(" description: '项目详情未找到',")
|
|||
|
|
detail_func_parts.append(" process: '项目流程未找到',")
|
|||
|
|
detail_func_parts.append(" keyPoints: '项目关键技术点未找到',")
|
|||
|
|
detail_func_parts.append(' applicablePositions: [],')
|
|||
|
|
detail_func_parts.append(' attachments: []')
|
|||
|
|
detail_func_parts.append(' };')
|
|||
|
|
detail_func_parts.append(' }')
|
|||
|
|
detail_func_parts.append('')
|
|||
|
|
detail_func_parts.append(' return project;')
|
|||
|
|
detail_func_parts.append('};')
|
|||
|
|
|
|||
|
|
# 组合完整文件内容
|
|||
|
|
new_content = projects_list_func + '\n\n' + '\n'.join(detail_func_parts)
|
|||
|
|
|
|||
|
|
# 写入文件
|
|||
|
|
with open('src/mocks/projectLibraryMock.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(new_content)
|
|||
|
|
|
|||
|
|
print("✅ 成功修复内容提取逻辑,所有项目内容已完整提取")
|