- 包含4个产业方向的前端项目:智能开发、智能制造、大健康、财经商贸 - 已清理node_modules、.yoyo等大文件,项目大小从2.6GB优化至631MB - 配置完善的.gitignore文件 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
153 lines
5.7 KiB
Python
153 lines
5.7 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
|
||
import re
|
||
import json
|
||
|
||
print("重新构建Mock文件结构...")
|
||
|
||
# 读取文件
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
|
||
# 备份
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js.backup_restructure', 'w', encoding='utf-8') as f:
|
||
f.write(content)
|
||
|
||
# 处理每个岗位群
|
||
# 1. 移除错误嵌套的questions
|
||
# 2. 在正确位置添加questions
|
||
|
||
industries_data = {
|
||
'health_1': 'health_2',
|
||
'health_2': 'health_3',
|
||
'health_3': 'health_4',
|
||
'health_4': 'health_5',
|
||
'health_5': 'health_6',
|
||
'health_6': 'health_7',
|
||
'health_7': 'health_8',
|
||
'health_8': 'health_9',
|
||
'health_9': 'health_10',
|
||
'health_10': 'health_11',
|
||
'health_11': None # 最后一个
|
||
}
|
||
|
||
fixed_count = 0
|
||
|
||
for industry_id, next_id in industries_data.items():
|
||
print(f"处理 {industry_id}...")
|
||
|
||
# 查找industry块
|
||
pattern = rf'"id":\s*"{industry_id}"'
|
||
match = re.search(pattern, content)
|
||
|
||
if not match:
|
||
print(f" 未找到 {industry_id}")
|
||
continue
|
||
|
||
start_pos = match.start()
|
||
|
||
# 找结束位置
|
||
if next_id:
|
||
next_pattern = rf'"id":\s*"{next_id}"'
|
||
next_match = re.search(next_pattern, content[start_pos + 10:])
|
||
if next_match:
|
||
end_pos = start_pos + 10 + next_match.start()
|
||
else:
|
||
continue
|
||
else:
|
||
# 最后一个industry
|
||
end_match = re.search(r'\n\];', content[start_pos:])
|
||
if end_match:
|
||
end_pos = start_pos + end_match.start()
|
||
else:
|
||
end_pos = len(content)
|
||
|
||
# 获取industry内容
|
||
industry_content = content[start_pos:end_pos]
|
||
|
||
# 检查是否有错误嵌套的questions(在第一个position内部)
|
||
# 查找第一个position对象的结束
|
||
first_position_pattern = r'"requirements":\s*\[[^\]]*?\]\s*,\s*"questions":\s*\['
|
||
if re.search(first_position_pattern, industry_content):
|
||
print(f" 发现错误嵌套的questions")
|
||
|
||
# 找到questions数组的完整内容
|
||
questions_start_match = re.search(r'"questions":\s*\[', industry_content)
|
||
if questions_start_match:
|
||
qs_start = questions_start_match.start()
|
||
|
||
# 使用括号计数找到questions的结束
|
||
bracket_count = 0
|
||
in_questions = False
|
||
qs_end = -1
|
||
|
||
for i in range(qs_start, len(industry_content)):
|
||
if industry_content[i] == '[':
|
||
if not in_questions and '"questions"' in industry_content[max(0, i-20):i]:
|
||
in_questions = True
|
||
bracket_count = 1
|
||
elif in_questions:
|
||
bracket_count += 1
|
||
elif industry_content[i] == ']' and in_questions:
|
||
bracket_count -= 1
|
||
if bracket_count == 0:
|
||
qs_end = i + 1
|
||
break
|
||
|
||
if qs_end > 0:
|
||
# 提取questions内容
|
||
questions_content = industry_content[qs_start:qs_end].strip()
|
||
|
||
# 移除错误的questions和后面多余的']'
|
||
# 找到"requirements": [...],后面的内容
|
||
req_end_match = re.search(r'"requirements":\s*\[[^\]]*?\]', industry_content)
|
||
if req_end_match:
|
||
req_end = req_end_match.end()
|
||
|
||
# 查找questions后面的多余']'
|
||
extra_bracket_match = re.search(r'\]\s*\n\]', industry_content[qs_end:qs_end + 50])
|
||
if extra_bracket_match:
|
||
# 移除从requirements后的逗号到多余']'的内容
|
||
clean_part1 = industry_content[:req_end]
|
||
clean_part2 = industry_content[qs_end + extra_bracket_match.end() - 1:] # -1 保留一个']'
|
||
clean_industry = clean_part1 + '\n }' + clean_part2
|
||
else:
|
||
# 简单移除questions部分
|
||
clean_industry = industry_content[:req_end] + '\n }' + industry_content[qs_end:]
|
||
|
||
# 现在在positions数组后添加questions
|
||
# 找到positions数组的结束
|
||
positions_end_pattern = r'"positions":\s*\[[^\]]*?\n\s*\]'
|
||
positions_match = re.search(positions_end_pattern, clean_industry, re.DOTALL)
|
||
|
||
if positions_match:
|
||
pos_end = positions_match.end() - 1 # 在']'之前
|
||
|
||
# 构建新的industry内容
|
||
new_industry = clean_industry[:pos_end] + '\n ],\n ' + questions_content + clean_industry[pos_end:]
|
||
|
||
# 替换原内容
|
||
content = content[:start_pos] + new_industry + content[end_pos:]
|
||
fixed_count += 1
|
||
print(f" ✓ 修复了 {industry_id}")
|
||
else:
|
||
print(f" 无法找到positions数组结束")
|
||
else:
|
||
print(f" 无法找到questions结束")
|
||
else:
|
||
print(f" 无法找到questions开始")
|
||
else:
|
||
print(f" 结构正常")
|
||
|
||
# 清理多余的符号
|
||
content = re.sub(r',\s*,', ',', content)
|
||
content = re.sub(r',\s*\]', ']', content)
|
||
content = re.sub(r',\s*\}', '}', content)
|
||
content = re.sub(r'\}\s*\]', '}]', content)
|
||
|
||
# 写回文件
|
||
with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f:
|
||
f.write(content)
|
||
|
||
print(f"\n✓ 完成!修复了 {fixed_count} 个岗位群") |