feat: redesign report batch workflow

This commit is contained in:
hectorzhao
2026-09-03 11:04:32 +08:00
parent a50aafb1ec
commit dc201bf92e
15 changed files with 582 additions and 150 deletions
@@ -16,6 +16,7 @@ import { ApiTags } from '@nestjs/swagger';
import { RequireRecentAuthentication } from '../auth/require-recent-authentication.decorator';
import { CurrentSessionUserId } from '../auth/current-session-user.decorator';
import { ReportMaterialsService } from './report-materials.service';
import { ReportBatchDownloadService } from './batch-download.service';
import {
CreateImportProfileDto,
CreateReportBatchDto,
@@ -30,7 +31,10 @@ type DownloadResponse = { setHeader(name: string, value: string): void; send(con
@ApiTags('report-materials')
@Controller('admin/report-materials')
export class ReportMaterialsController {
constructor(private readonly service: ReportMaterialsService) {}
constructor(
private readonly service: ReportMaterialsService,
private readonly batchDownloads: ReportBatchDownloadService,
) {}
@Get('pending')
listPending(
@@ -156,6 +160,16 @@ export class ReportMaterialsController {
return this.service.listBatches({ keyword, startAt, endAt, page: Number(page), pageSize: Number(pageSize) });
}
@Get('batches/:id/download')
async downloadBatch(@Param('id') id: string, @Res() response: DownloadResponse) {
this.sendDownload(response, await this.batchDownloads.exportBundle(await this.service.getBatch(id)));
}
@Get('batches/:id/files/:fileId/download')
async downloadBatchFile(@Param('id') id: string, @Param('fileId') fileId: string, @Res() response: DownloadResponse) {
this.sendDownload(response, await this.batchDownloads.exportFile(await this.service.getBatch(id), fileId));
}
@Get('batches/:id')
getBatch(@Param('id') id: string) {
return this.service.getBatch(id);
@@ -212,4 +226,13 @@ export class ReportMaterialsController {
response.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(exported.fileName)}`);
response.send(exported.content);
}
private sendDownload(
response: DownloadResponse,
exported: { fileName: string; contentType: string; content: Buffer },
) {
response.setHeader('Content-Type', exported.contentType);
response.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(exported.fileName)}`);
response.send(exported.content);
}
}