feat: add report material workflows and gateway safeguards
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { BadRequestException, Body, Controller, Get, Param, Post, Put, Query, UploadedFile, UseInterceptors } from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { RequireRecentAuthentication } from '../auth/require-recent-authentication.decorator';
|
||||
import { CreateImportProfileDto, CreateReportBatchDto, ImportCommitDto, ReportMaterialsService } from './report-materials.service';
|
||||
|
||||
type UploadedWorkbook = { originalname: string; mimetype: string; size: number; buffer: Buffer };
|
||||
|
||||
@ApiTags('report-materials')
|
||||
@Controller('admin/report-materials')
|
||||
export class ReportMaterialsController {
|
||||
constructor(private readonly service: ReportMaterialsService) {}
|
||||
|
||||
@Get('pending')
|
||||
listPending(@Query('reportType') reportType?: 'signature' | 'drainage', @Query('tenantId') tenantId?: string, @Query('applicationId') applicationId?: string) {
|
||||
return this.service.listPending({ reportType, tenantId, applicationId });
|
||||
}
|
||||
|
||||
@Get('import-profiles')
|
||||
listImportProfiles(@Query('reportType') reportType?: 'signature' | 'drainage') {
|
||||
return this.service.listImportProfiles(reportType);
|
||||
}
|
||||
|
||||
@Post('import-profiles')
|
||||
@RequireRecentAuthentication()
|
||||
saveImportProfile(@Body() body: CreateImportProfileDto) {
|
||||
return this.service.saveImportProfile(body);
|
||||
}
|
||||
|
||||
@Post('imports/analyze')
|
||||
@UseInterceptors(FileInterceptor('file', { limits: { fileSize: 100 * 1024 * 1024, files: 1, fields: 12, parts: 13 } }))
|
||||
analyzeImport(@UploadedFile() file: UploadedWorkbook, @Body() body: Record<string, string>) {
|
||||
if (!file) throw new BadRequestException('请选择 XLSX 文件');
|
||||
return this.service.analyzeImport(file, {
|
||||
tenantId: body.tenantId,
|
||||
applicationId: body.applicationId || undefined,
|
||||
reportType: body.reportType as 'signature' | 'drainage',
|
||||
sheetName: body.sheetName || undefined,
|
||||
headerRowCount: Number(body.headerRowCount || 1),
|
||||
dataStartRow: Number(body.dataStartRow || 2),
|
||||
profileId: body.profileId || undefined,
|
||||
});
|
||||
}
|
||||
|
||||
@Put('imports/:id/commit')
|
||||
@RequireRecentAuthentication()
|
||||
commitImport(@Param('id') id: string, @Body() body: ImportCommitDto) {
|
||||
return this.service.commitImport(id, body);
|
||||
}
|
||||
|
||||
@Get('batches')
|
||||
listBatches() {
|
||||
return this.service.listBatches();
|
||||
}
|
||||
|
||||
@Post('batches')
|
||||
@RequireRecentAuthentication()
|
||||
createBatch(@Body() body: CreateReportBatchDto) {
|
||||
return this.service.createBatch(body);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user