feat: add GET /archive/:studentId/report-html endpoint
This commit is contained in:
@@ -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 {
|
private css(): string {
|
||||||
return `
|
return `
|
||||||
@page { size: A4; margin: 0; }
|
@page { size: A4; margin: 0; }
|
||||||
|
|||||||
@@ -360,4 +360,25 @@ export class ArchiveController {
|
|||||||
});
|
});
|
||||||
return this.reportService.generateReport(+studentId, res);
|
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 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user