174 lines
5.8 KiB
JavaScript
174 lines
5.8 KiB
JavaScript
import fs from 'fs';
|
||
|
||
// 读取CSV文件
|
||
const csvContent = fs.readFileSync('日历课程表.csv', 'utf-8');
|
||
const lines = csvContent.split('\n');
|
||
|
||
// 解析CSV数据
|
||
const calendarEvents = [];
|
||
let eventId = 1;
|
||
|
||
// 获取当前日期
|
||
const today = new Date();
|
||
const currentYear = today.getFullYear();
|
||
const currentMonth = today.getMonth() + 1;
|
||
const currentDay = today.getDate();
|
||
|
||
// 颜色映射
|
||
const unitColors = {
|
||
'岗位体系认知': '#3b82f6',
|
||
'产业认知课': '#10b981',
|
||
'旅游产业全景与文旅基础知识': '#f59e0b',
|
||
'文旅服务:形象、沟通与体验的融合艺术': '#ef4444',
|
||
'文旅活动企划与实施': '#8b5cf6',
|
||
'设计能力提升': '#06b6d4',
|
||
'AIGC人工智能生成内容': '#ec4899',
|
||
'全栈新媒体运营赋能文旅营销': '#14b8a6',
|
||
'活动策划基础': '#f97316',
|
||
'智慧文旅应用': '#6366f1'
|
||
};
|
||
|
||
// 课程状态映射
|
||
const getEventStatus = (statusStr, dateStr) => {
|
||
const [year, month, day] = dateStr.split('/').map(Number);
|
||
const eventDate = new Date(year, month - 1, day);
|
||
const today = new Date();
|
||
today.setHours(0, 0, 0, 0);
|
||
eventDate.setHours(0, 0, 0, 0);
|
||
|
||
if (statusStr === '已结束') return 'completed';
|
||
if (statusStr === '未开始') {
|
||
// 检查是否是近期(7天内)
|
||
const daysDiff = Math.floor((eventDate - today) / (1000 * 60 * 60 * 24));
|
||
if (daysDiff >= 0 && daysDiff <= 7) return 'upcoming';
|
||
return 'future';
|
||
}
|
||
return 'pending';
|
||
};
|
||
|
||
// 处理每一行数据(跳过标题行)
|
||
for (let i = 1; i < lines.length; i++) {
|
||
const line = lines[i].trim();
|
||
if (!line) continue;
|
||
|
||
const parts = line.split(',');
|
||
if (parts.length < 10) continue;
|
||
|
||
const date = parts[0];
|
||
const weekday = parts[1];
|
||
const courseStatus = parts[2];
|
||
const courseName = parts[3];
|
||
const publicCourse = parts[4];
|
||
const time = parts[5];
|
||
const teacher = parts[6];
|
||
const unit = parts[7];
|
||
const status = parts[8];
|
||
const className = parts[9];
|
||
|
||
// 只处理有课的数据
|
||
if (courseStatus === '有课' && courseName) {
|
||
const [year, month, day] = date.split('/').map(Number);
|
||
const timeRange = time.split('~');
|
||
// 修复时间格式,去除中文冒号
|
||
const startTime = (timeRange[0] || '20:00').replace(':', ':');
|
||
const endTime = (timeRange[1] || '21:00').replace(':', ':');
|
||
|
||
// 截断过长的课程名称
|
||
const truncatedTitle = courseName.length > 12 ? courseName.substring(0, 11) + '...' : courseName;
|
||
|
||
const event = {
|
||
id: eventId++,
|
||
title: truncatedTitle,
|
||
fullTitle: courseName, // 保留完整标题
|
||
teacher: teacher,
|
||
unit: unit,
|
||
startTime: `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')} ${startTime}`,
|
||
endTime: `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')} ${endTime}`,
|
||
type: 'course',
|
||
color: unitColors[unit] || '#6b7280',
|
||
textColor: '#1d2129', // 添加文字颜色
|
||
description: `${unit} - ${teacher}老师`,
|
||
status: getEventStatus(status, date),
|
||
weekday: weekday
|
||
};
|
||
|
||
calendarEvents.push(event);
|
||
}
|
||
|
||
// 处理公开课
|
||
if (publicCourse && publicCourse !== '') {
|
||
const [year, month, day] = date.split('/').map(Number);
|
||
const timeRange = time.split('~');
|
||
const startTime = (timeRange[0] || '20:00').replace(':', ':');
|
||
const endTime = (timeRange[1] || '21:00').replace(':', ':');
|
||
|
||
// 截断过长的公开课名称
|
||
const truncatedTitle = publicCourse.length > 12 ? publicCourse.substring(0, 11) + '...' : publicCourse;
|
||
|
||
const publicEvent = {
|
||
id: eventId++,
|
||
title: truncatedTitle,
|
||
fullTitle: publicCourse,
|
||
teacher: '公开课讲师',
|
||
unit: '公开课',
|
||
startTime: `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')} ${startTime}`,
|
||
endTime: `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')} ${endTime}`,
|
||
type: 'public',
|
||
color: '#9333ea',
|
||
textColor: '#1d2129',
|
||
description: '职业技能公开课',
|
||
status: 'upcoming',
|
||
weekday: weekday
|
||
};
|
||
|
||
calendarEvents.push(publicEvent);
|
||
}
|
||
}
|
||
|
||
// 生成allTasks数据(用于Dashboard的任务列表)
|
||
const allTasks = calendarEvents
|
||
.filter(event => {
|
||
const eventDate = new Date(event.startTime.split(' ')[0]);
|
||
const today = new Date();
|
||
const daysDiff = Math.floor((eventDate - today) / (1000 * 60 * 60 * 24));
|
||
return daysDiff >= -30 && daysDiff <= 30; // 只保留前后30天的任务
|
||
})
|
||
.map((event, index) => {
|
||
const [date, time] = event.startTime.split(' ');
|
||
const typeMap = {
|
||
'course': 'HOMEWORK',
|
||
'public': 'OTHER',
|
||
'lab': 'PROJECT',
|
||
'meeting': 'INTERVIEW'
|
||
};
|
||
|
||
return {
|
||
id: index + 1,
|
||
title: `完成${event.title}课程学习`,
|
||
date: date,
|
||
time: time,
|
||
type: typeMap[event.type] || 'HOMEWORK',
|
||
courseName: event.title,
|
||
status: event.status === 'completed' ? 'COMPLETED' :
|
||
event.status === 'upcoming' ? 'PENDING' : 'PENDING',
|
||
teacherName: event.teacher,
|
||
teacherAvatar: "https://p1-arco.byteimg.com/tos-cn-i-uwbnlip3yd/3ee5f13fb09879ecb5185e440cef6eb9.png~tplv-uwbnlip3yd-webp.webp",
|
||
duration: "1小时"
|
||
};
|
||
});
|
||
|
||
// 输出结果
|
||
console.log('// 日历事件数据(从CSV生成)');
|
||
console.log('calendarEvents:', JSON.stringify(calendarEvents, null, 2));
|
||
console.log('\n// 任务列表数据(从日历事件生成)');
|
||
console.log('allTasks:', JSON.stringify(allTasks.slice(0, 20), null, 2)); // 只显示前20个任务
|
||
|
||
// 写入到文件
|
||
const output = {
|
||
calendarEvents,
|
||
allTasks
|
||
};
|
||
|
||
fs.writeFileSync('calendarData.json', JSON.stringify(output, null, 2));
|
||
console.log('\n数据已保存到 calendarData.json');
|
||
console.log(`总共生成了 ${calendarEvents.length} 个日历事件和 ${allTasks.length} 个任务`); |