v0.8.6测试
This commit is contained in:
@@ -114,23 +114,39 @@ async function exportMoralityRecords() {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取每个学生的历史记录
|
||||
// 获取所有历史记录(不分页,获取全部)
|
||||
const historyRes = await apiGet('/api/admin/conduct/history', { page: 1, page_size: 10000 });
|
||||
if (!historyRes || !historyRes.success) {
|
||||
showToast('获取历史记录失败', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const allRecords = historyRes.data.records || [];
|
||||
|
||||
// 按学生ID分组历史记录
|
||||
const recordsByStudent = {};
|
||||
allRecords.forEach(record => {
|
||||
const sid = record.student_id;
|
||||
if (!recordsByStudent[sid]) {
|
||||
recordsByStudent[sid] = [];
|
||||
}
|
||||
recordsByStudent[sid].push(record);
|
||||
});
|
||||
|
||||
// 构建学生记录
|
||||
const studentRecords = [];
|
||||
for (const student of students) {
|
||||
const historyRes = await apiGet(`/api/student/conduct/${student.student_id}`, { limit: 1000 });
|
||||
if (historyRes && historyRes.success) {
|
||||
const records = historyRes.data.records || [];
|
||||
const positiveRecords = records.filter(r => r.points_change > 0).map(r => `${r.reason}(${r.points_change > 0 ? '+' : ''}${r.points_change})`);
|
||||
const negativeRecords = records.filter(r => r.points_change < 0).map(r => `${r.reason}(${r.points_change})`);
|
||||
|
||||
studentRecords.push({
|
||||
student_no: student.student_no,
|
||||
name: student.name,
|
||||
total_points: historyRes.data.total_points || 0,
|
||||
positive_history: positiveRecords.join(', '),
|
||||
negative_history: negativeRecords.join(', ')
|
||||
});
|
||||
}
|
||||
const studentRecords_list = recordsByStudent[student.student_id] || [];
|
||||
const positiveRecords = studentRecords_list.filter(r => r.points_change > 0).map(r => `${r.reason}(+${r.points_change})`);
|
||||
const negativeRecords = studentRecords_list.filter(r => r.points_change < 0).map(r => `${r.reason}(${r.points_change})`);
|
||||
|
||||
studentRecords.push({
|
||||
student_no: student.student_no,
|
||||
name: student.name,
|
||||
total_points: student.total_points || 0,
|
||||
positive_history: positiveRecords.join(','),
|
||||
negative_history: negativeRecords.join(',')
|
||||
});
|
||||
}
|
||||
|
||||
// 构建CSV内容
|
||||
@@ -154,6 +170,7 @@ async function exportMoralityRecords() {
|
||||
showToast(`导出成功,共${studentRecords.length}名学生`);
|
||||
} catch (err) {
|
||||
showToast('导出失败:' + err.message, 'error');
|
||||
console.error('导出失败:', err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user