76 lines
2.9 KiB
JavaScript
76 lines
2.9 KiB
JavaScript
|
|
import fs from 'fs';
|
||
|
|
|
||
|
|
const calendarData = JSON.parse(fs.readFileSync('./src/data/intelligentManufacturingCalendar.json', 'utf8'));
|
||
|
|
|
||
|
|
// 模拟transformCalendarCourses函数的逻辑
|
||
|
|
const transformedEvents = calendarData
|
||
|
|
.filter(course => {
|
||
|
|
if (course['上课状态'] === '休息') return false;
|
||
|
|
if (!course['日期']) return false;
|
||
|
|
return course['个人课程表'] || course['公共课'] || course['企业高管公开课'];
|
||
|
|
})
|
||
|
|
.slice(0, 5) // 只处理前5个
|
||
|
|
.map(course => {
|
||
|
|
const dateStr = course['日期'];
|
||
|
|
const [year, month, day] = dateStr.split('/').map(Number);
|
||
|
|
|
||
|
|
const courseName = course['个人课程表'] ||
|
||
|
|
course['公共课'] ||
|
||
|
|
course['企业高管公开课'] ||
|
||
|
|
'未命名课程';
|
||
|
|
|
||
|
|
const timeStr = course['上课时间'] || '20:00~21:00';
|
||
|
|
let startTime = '20:00';
|
||
|
|
let endTime = '21:00';
|
||
|
|
|
||
|
|
if (timeStr && timeStr.includes('~')) {
|
||
|
|
const timeParts = timeStr.split('~').map(t => t.trim());
|
||
|
|
if (timeParts[0]) startTime = timeParts[0];
|
||
|
|
if (timeParts[1]) endTime = timeParts[1];
|
||
|
|
}
|
||
|
|
|
||
|
|
// 根据课程类型确定type
|
||
|
|
let eventType = 'class';
|
||
|
|
if (course['公共课']) {
|
||
|
|
if (course['公共课'].includes('AI')) {
|
||
|
|
eventType = 'ai-course';
|
||
|
|
} else {
|
||
|
|
eventType = 'public-course';
|
||
|
|
}
|
||
|
|
} else if (course['个人课程表']) {
|
||
|
|
if (course['所属单元(个人课程)'] && course['所属单元(个人课程)'].includes('垂直')) {
|
||
|
|
eventType = 'vertical-skill';
|
||
|
|
} else {
|
||
|
|
eventType = 'compound-skill';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
id: `event-${course['日期']}`,
|
||
|
|
title: courseName,
|
||
|
|
date: `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`,
|
||
|
|
startTime: `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')} ${startTime}`,
|
||
|
|
endTime: `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')} ${endTime}`,
|
||
|
|
type: eventType,
|
||
|
|
unit: course['所属单元(个人课程)'] || course['所属单元(公共课)'] || '',
|
||
|
|
teacher: course['导师姓名查询'] || '',
|
||
|
|
location: course['上课地点'] || '线上'
|
||
|
|
};
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('转换后的前5个日历事件:');
|
||
|
|
transformedEvents.forEach((event, index) => {
|
||
|
|
console.log(`\n事件 ${index + 1}:`);
|
||
|
|
console.log(' 课程名称:', event.title);
|
||
|
|
console.log(' 日期:', event.date);
|
||
|
|
console.log(' 时间:', event.startTime.split(' ')[1], '-', event.endTime.split(' ')[1]);
|
||
|
|
console.log(' 类型:', event.type);
|
||
|
|
console.log(' 单元:', event.unit);
|
||
|
|
console.log(' 导师:', event.teacher);
|
||
|
|
});
|
||
|
|
|
||
|
|
console.log('\n总计成功转换的事件数量预估:', calendarData.filter(course => {
|
||
|
|
if (course['上课状态'] === '休息') return false;
|
||
|
|
if (!course['日期']) return false;
|
||
|
|
return course['个人课程表'] || course['公共课'] || course['企业高管公开课'];
|
||
|
|
}).length);
|