题库导入功能完成,考试计划功能完成。
This commit is contained in:
@@ -142,13 +142,15 @@ export class QuizModel {
|
||||
}
|
||||
|
||||
// 获取所有答题记录(管理员用)
|
||||
static async findAllRecords(limit = 10, offset = 0): Promise<{ records: QuizRecord[]; total: number }> {
|
||||
static async findAllRecords(limit = 10, offset = 0): Promise<{ records: any[]; total: number }> {
|
||||
const recordsSql = `
|
||||
SELECT r.id, r.user_id as userId, u.name as userName, u.phone as userPhone,
|
||||
r.total_score as totalScore, r.correct_count as correctCount, r.total_count as totalCount,
|
||||
r.created_at as createdAt
|
||||
r.created_at as createdAt, r.subject_id as subjectId, s.name as subjectName,
|
||||
r.task_id as taskId
|
||||
FROM quiz_records r
|
||||
JOIN users u ON r.user_id = u.id
|
||||
LEFT JOIN exam_subjects s ON r.subject_id = s.id
|
||||
ORDER BY r.created_at DESC
|
||||
LIMIT ? OFFSET ?
|
||||
`;
|
||||
@@ -160,8 +162,29 @@ export class QuizModel {
|
||||
get(countSql)
|
||||
]);
|
||||
|
||||
// 对于每条记录,计算该考试任务的参与人数
|
||||
const processedRecords = await Promise.all(records.map(async (record) => {
|
||||
let examCount = 0;
|
||||
if (record.taskId) {
|
||||
// 统计该任务的参与人数
|
||||
const taskCountSql = `SELECT COUNT(DISTINCT user_id) as count FROM quiz_records WHERE task_id = ?`;
|
||||
const taskCountResult = await get(taskCountSql, [record.taskId]);
|
||||
examCount = taskCountResult.count || 0;
|
||||
} else if (record.subjectId) {
|
||||
// 统计该科目的参与人数
|
||||
const subjectCountSql = `SELECT COUNT(DISTINCT user_id) as count FROM quiz_records WHERE subject_id = ?`;
|
||||
const subjectCountResult = await get(subjectCountSql, [record.subjectId]);
|
||||
examCount = subjectCountResult.count || 0;
|
||||
}
|
||||
|
||||
return {
|
||||
...record,
|
||||
examCount
|
||||
};
|
||||
}));
|
||||
|
||||
return {
|
||||
records,
|
||||
records: processedRecords,
|
||||
total: countResult.total
|
||||
};
|
||||
}
|
||||
@@ -215,7 +238,7 @@ export class QuizModel {
|
||||
averageScore: number;
|
||||
typeStats: Array<{ type: string; total: number; correct: number; correctRate: number }>;
|
||||
}> {
|
||||
const totalUsersSql = `SELECT COUNT(DISTINCT user_id) as total FROM quiz_records`;
|
||||
const totalUsersSql = `SELECT COUNT(*) as total FROM users`;
|
||||
const totalRecordsSql = `SELECT COUNT(*) as total FROM quiz_records`;
|
||||
const averageScoreSql = `SELECT AVG(total_score) as average FROM quiz_records`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user