feat: add GET /archive/:studentId/report-html endpoint

This commit is contained in:
2026-07-07 09:50:05 +08:00
parent 9f43f50867
commit 36978813cf
2 changed files with 48 additions and 0 deletions

View File

@@ -84,6 +84,33 @@ export class ArchiveReportService {
}
}
async generateReportHtml(studentId: number): Promise<string> {
const [student, profile, enrollments, exams, learnings, result, attendances] =
await Promise.all([
this.studentRepo.findOne({ where: { id: studentId } }),
this.profileRepo.findOne({ where: { studentId } }),
this.enrollmentRepo.find({ where: { studentId }, order: { startDate: 'ASC' } }),
this.examRepo.find({ where: { studentId }, order: { examDate: 'ASC' } }),
this.learningRepo.find({ where: { studentId }, order: { recordDate: 'DESC' } }),
this.resultRepo.findOne({ where: { studentId } }),
this.attendanceRepo.find({ where: { studentId }, order: { attendanceDate: 'ASC' } }),
]);
if (!student) throw new Error('学生不存在');
const data: ReportData = {
student,
profile,
enrollments,
exams,
learnings,
result,
attendances,
};
return this.buildHtml(data);
}
private css(): string {
return `
@page { size: A4; margin: 0; }

View File

@@ -360,4 +360,25 @@ export class ArchiveController {
});
return this.reportService.generateReport(+studentId, res);
}
@Get(':studentId/report-html')
@RequirePermission('student:view')
async generateReportHtml(
@Param('studentId') studentId: string,
@Request() req: AuthenticatedRequest,
) {
const { ipAddress, userAgent } = extractRequestInfo(req);
await this.logService.log({
userId: req.user?.id,
username: req.user?.username,
module: 'archive',
action: 'generate_report_html',
targetId: +studentId,
targetType: 'student',
ipAddress,
userAgent,
});
const html = await this.reportService.generateReportHtml(+studentId);
return { html };
}
}