From 36978813cf84954acbe98cbce1e9430403267ce2 Mon Sep 17 00:00:00 2001 From: wangziqi Date: Tue, 7 Jul 2026 09:50:05 +0800 Subject: [PATCH] feat: add GET /archive/:studentId/report-html endpoint --- .../src/archive/archive-report.service.ts | 27 +++++++++++++++++++ apps/server/src/archive/archive.controller.ts | 21 +++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/apps/server/src/archive/archive-report.service.ts b/apps/server/src/archive/archive-report.service.ts index 6702639..09da77f 100644 --- a/apps/server/src/archive/archive-report.service.ts +++ b/apps/server/src/archive/archive-report.service.ts @@ -84,6 +84,33 @@ export class ArchiveReportService { } } + async generateReportHtml(studentId: number): Promise { + 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; } diff --git a/apps/server/src/archive/archive.controller.ts b/apps/server/src/archive/archive.controller.ts index 68f198e..0a885fa 100644 --- a/apps/server/src/archive/archive.controller.ts +++ b/apps/server/src/archive/archive.controller.ts @@ -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 }; + } }