|
|
@ -4,7 +4,20 @@ const xlsx = require('xlsx');
|
|
|
|
const pool = require('../db');
|
|
|
|
const pool = require('../db');
|
|
|
|
|
|
|
|
|
|
|
|
const classManager = {
|
|
|
|
const classManager = {
|
|
|
|
addClass: (req, res) => {
|
|
|
|
addClass: async (req, res) => {
|
|
|
|
|
|
|
|
// 创建students表的SQL语句
|
|
|
|
|
|
|
|
const createTableQuery = `
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS students (
|
|
|
|
|
|
|
|
student_id INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
|
|
|
|
student_name VARCHAR(255) NOT NULL,
|
|
|
|
|
|
|
|
score DECIMAL(5, 2),
|
|
|
|
|
|
|
|
call_count INT DEFAULT 0
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 先创建表
|
|
|
|
|
|
|
|
await pool.query(createTableQuery);
|
|
|
|
|
|
|
|
|
|
|
|
const filePath = req.file.path;
|
|
|
|
const filePath = req.file.path;
|
|
|
|
|
|
|
|
|
|
|
|
// 读取并解析Excel文件
|
|
|
|
// 读取并解析Excel文件
|
|
|
@ -42,6 +55,10 @@ const classManager = {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
res.status(200).json({ message: 'Class added successfully!' });
|
|
|
|
res.status(200).json({ message: 'Class added successfully!' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error('Error creating students table:', err);
|
|
|
|
|
|
|
|
res.status(500).json({ message: 'Error creating table during class addition.' });
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|