feat: add class roster export and attendance stats export
- GET /classes/:id/roster/export — Excel export with 姓名/学号/加入日期/状态 - GET /attendance-records/export — Excel export with 姓名/班级/日期/时段/状态/来源/备注/打卡时间 - Add findAllForExport to AttendanceService (no pagination) - Both use ExcelJS following classrooms controller downloadTemplate pattern
This commit is contained in:
@@ -9,7 +9,9 @@ import {
|
||||
Query,
|
||||
UseGuards,
|
||||
Request,
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import type { Response } from 'express';
|
||||
import { ClassesService } from './classes.service';
|
||||
import {
|
||||
CreateClassDto,
|
||||
@@ -22,6 +24,7 @@ import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard';
|
||||
import { OperationLogsService } from '../operation-logs/operation-logs.service';
|
||||
import { extractRequestInfo } from '../common/request-utils';
|
||||
import { RequirePermission } from '../auth/decorators/permission.decorator';
|
||||
import * as ExcelJS from 'exceljs';
|
||||
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('classes')
|
||||
@@ -103,6 +106,44 @@ export class ClassesController {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Get(':id/roster/export')
|
||||
@RequirePermission('class:view')
|
||||
async exportRoster(@Param('id') id: string, @Res() res: Response) {
|
||||
const classEntity = await this.service.findOne(+id);
|
||||
const classStudents = await this.service.getStudents(+id);
|
||||
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
const ws = workbook.addWorksheet('班级花名册');
|
||||
ws.columns = [
|
||||
{ header: '姓名', key: 'name', width: 15 },
|
||||
{ header: '学号', key: 'studentNo', width: 15 },
|
||||
{ header: '加入日期', key: 'joinDate', width: 15 },
|
||||
{ header: '状态', key: 'status', width: 10 },
|
||||
];
|
||||
ws.getRow(1).font = { bold: true };
|
||||
ws.getRow(1).fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'FFE0E0E0' } };
|
||||
|
||||
for (const cs of classStudents) {
|
||||
ws.addRow({
|
||||
name: cs.student?.name || '',
|
||||
studentNo: cs.student?.idNumber || '',
|
||||
joinDate: cs.joinDate || '',
|
||||
status: cs.status || '',
|
||||
});
|
||||
}
|
||||
|
||||
res.setHeader(
|
||||
'Content-Type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
);
|
||||
res.setHeader(
|
||||
'Content-Disposition',
|
||||
`attachment; filename=${encodeURIComponent(`班级花名册-${classEntity.name}`)}.xlsx`,
|
||||
);
|
||||
await workbook.xlsx.write(res);
|
||||
res.end();
|
||||
}
|
||||
|
||||
@Get(':id/students')
|
||||
@RequirePermission('class:view')
|
||||
getStudents(@Param('id') id: string) {
|
||||
|
||||
Reference in New Issue
Block a user