142 lines
4.9 KiB
JavaScript
142 lines
4.9 KiB
JavaScript
|
|
import fs from 'fs';
|
|||
|
|
|
|||
|
|
// 读取当前的 mockData.js 文件
|
|||
|
|
let mockDataContent = fs.readFileSync('src/data/mockData.js', 'utf-8');
|
|||
|
|
|
|||
|
|
// 定义新的 transformInterviewStatus 函数
|
|||
|
|
const newTransformInterviewStatusFunction = `// 转换面试状态数据
|
|||
|
|
const transformInterviewStatus = (statusData, jobsData) => {
|
|||
|
|
if (!Array.isArray(statusData)) {
|
|||
|
|
console.warn('statusData is not an array:', statusData);
|
|||
|
|
return [];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return statusData
|
|||
|
|
.map((status, index) => {
|
|||
|
|
if (!status || typeof status !== 'object') {
|
|||
|
|
console.warn('Invalid status item:', status);
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 从岗位数据中查找匹配的岗位详情
|
|||
|
|
const matchedJob = jobsData.find(job =>
|
|||
|
|
job["内推岗位名称"] === status["岗位名称"]
|
|||
|
|
);
|
|||
|
|
|
|||
|
|
// 解析日期
|
|||
|
|
let formattedDate;
|
|||
|
|
let interviewDate;
|
|||
|
|
|
|||
|
|
// 处理不同的日期格式
|
|||
|
|
const dateString = status["投递时间"] || "2024-01-01";
|
|||
|
|
if (dateString && dateString.includes('-')) {
|
|||
|
|
// 标准格式:YYYY-MM-DD
|
|||
|
|
formattedDate = dateString;
|
|||
|
|
interviewDate = new Date(dateString);
|
|||
|
|
} else if (dateString && dateString.includes('/')) {
|
|||
|
|
// 格式:YYYY/M/D
|
|||
|
|
const dateParts = dateString.split('/');
|
|||
|
|
if (dateParts.length === 3) {
|
|||
|
|
formattedDate = \`\${dateParts[0]}-\${dateParts[1].padStart(2, '0')}-\${dateParts[2].padStart(2, '0')}\`;
|
|||
|
|
interviewDate = new Date(parseInt(dateParts[0]), parseInt(dateParts[1]) - 1, parseInt(dateParts[2]));
|
|||
|
|
} else {
|
|||
|
|
formattedDate = dateString;
|
|||
|
|
interviewDate = new Date();
|
|||
|
|
}
|
|||
|
|
} else {
|
|||
|
|
formattedDate = dateString;
|
|||
|
|
interviewDate = new Date();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 根据面试状态确定状态码和文本
|
|||
|
|
let statusCode = 'PENDING';
|
|||
|
|
let statusText = status["面试状态"] || "已投递";
|
|||
|
|
|
|||
|
|
if (statusText === "已通过" || statusText === "收到Offer") {
|
|||
|
|
statusCode = 'OFFER';
|
|||
|
|
} else if (statusText === "未通过" || statusText === "面试未通过") {
|
|||
|
|
statusCode = 'FAILED';
|
|||
|
|
} else if (statusText === "面试中") {
|
|||
|
|
statusCode = 'INTERVIEW';
|
|||
|
|
} else if (statusText === "笔试中") {
|
|||
|
|
statusCode = 'TEST';
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
id: index + 1,
|
|||
|
|
position: status["岗位名称"] || "未知岗位",
|
|||
|
|
interviewTime: formattedDate,
|
|||
|
|
interviewDate: interviewDate,
|
|||
|
|
status: statusCode,
|
|||
|
|
statusText: statusText,
|
|||
|
|
progress: status["面试进度"] || 25,
|
|||
|
|
nextStep: status["下一步"] || "等待回复",
|
|||
|
|
job: matchedJob ? {
|
|||
|
|
salary: matchedJob["薪资"],
|
|||
|
|
tags: matchedJob["职位标签"] || [],
|
|||
|
|
location: matchedJob["工作地点"],
|
|||
|
|
education: matchedJob["学历要求"],
|
|||
|
|
companyInfo: matchedJob["公司介绍"],
|
|||
|
|
jobCategory: matchedJob["岗位相关标签"] || "专业相关岗位",
|
|||
|
|
remainingPositions: matchedJob["招聘人数"] ? parseInt(matchedJob["招聘人数"]) : 5,
|
|||
|
|
description: matchedJob["职位描述"],
|
|||
|
|
requirements: matchedJob["任职要求"]
|
|||
|
|
} : null
|
|||
|
|
};
|
|||
|
|
})
|
|||
|
|
.filter(item => item !== null)
|
|||
|
|
.sort((a, b) => b.interviewDate - a.interviewDate);
|
|||
|
|
};`;
|
|||
|
|
|
|||
|
|
// 查找并替换整个 transformInterviewStatus 函数
|
|||
|
|
const functionStartPattern = /\/\/ 转换面试状态数据\s*const transformInterviewStatus = \(statusData, jobsData\) => \{/;
|
|||
|
|
const functionEndPattern = /\};\s*(?=\/\/|const|export|$)/;
|
|||
|
|
|
|||
|
|
// 找到函数开始位置
|
|||
|
|
const startMatch = mockDataContent.match(functionStartPattern);
|
|||
|
|
if (startMatch) {
|
|||
|
|
const startIndex = startMatch.index;
|
|||
|
|
|
|||
|
|
// 从开始位置查找函数结束位置
|
|||
|
|
let braceCount = 0;
|
|||
|
|
let foundStart = false;
|
|||
|
|
let endIndex = startIndex;
|
|||
|
|
|
|||
|
|
for (let i = startIndex; i < mockDataContent.length; i++) {
|
|||
|
|
const char = mockDataContent[i];
|
|||
|
|
if (char === '{') {
|
|||
|
|
braceCount++;
|
|||
|
|
foundStart = true;
|
|||
|
|
} else if (char === '}') {
|
|||
|
|
braceCount--;
|
|||
|
|
if (foundStart && braceCount === 0) {
|
|||
|
|
endIndex = i + 1;
|
|||
|
|
// 查找分号
|
|||
|
|
if (mockDataContent[i + 1] === ';') {
|
|||
|
|
endIndex = i + 2;
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 替换函数
|
|||
|
|
const beforeFunction = mockDataContent.substring(0, startIndex);
|
|||
|
|
const afterFunction = mockDataContent.substring(endIndex);
|
|||
|
|
|
|||
|
|
mockDataContent = beforeFunction + newTransformInterviewStatusFunction + afterFunction;
|
|||
|
|
|
|||
|
|
// 备份原文件
|
|||
|
|
const backupFileName = \`src/data/mockData.js.backup_interview_fix_\${new Date().toISOString().replace(/[:.]/g, '-')}\`;
|
|||
|
|
fs.copyFileSync('src/data/mockData.js', backupFileName);
|
|||
|
|
console.log(\`原文件已备份到: \${backupFileName}\`);
|
|||
|
|
|
|||
|
|
// 保存修复后的文件
|
|||
|
|
fs.writeFileSync('src/data/mockData.js', mockDataContent, 'utf-8');
|
|||
|
|
console.log('transformInterviewStatus 函数已修复');
|
|||
|
|
|
|||
|
|
} else {
|
|||
|
|
console.log('未找到 transformInterviewStatus 函数');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('修复完成!');
|