feat: 实现批量生码、二维码导出与公开溯源激活计数
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
Res,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { Response } from 'express';
|
||||
import { RoleType } from '@artveris/shared';
|
||||
import { TraceCodeService } from './trace-code.service';
|
||||
import {
|
||||
BindArtworkDto,
|
||||
GenerateBatchDto,
|
||||
QueryBatchDto,
|
||||
QueryTraceCodeDto,
|
||||
} from './dto/trace-code.dto';
|
||||
import { Roles } from '../common/decorators/roles.decorator';
|
||||
import { CurrentUser, AuthUser } from '../common/decorators/current-user.decorator';
|
||||
|
||||
@ApiTags('批量生码')
|
||||
@ApiBearerAuth()
|
||||
@Controller()
|
||||
export class TraceCodeController {
|
||||
constructor(private readonly service: TraceCodeService) {}
|
||||
|
||||
@Post('trace-codes/batch')
|
||||
@Roles(RoleType.OPERATOR)
|
||||
@ApiOperation({ summary: '按批次异步生成追溯码' })
|
||||
generate(@Body() dto: GenerateBatchDto, @CurrentUser() user: AuthUser) {
|
||||
return this.service.generateBatch(dto, user.id);
|
||||
}
|
||||
|
||||
@Get('batches')
|
||||
@ApiOperation({ summary: '批次列表' })
|
||||
batches(@Query() query: QueryBatchDto) {
|
||||
return this.service.listBatches(query);
|
||||
}
|
||||
|
||||
@Get('trace-codes')
|
||||
@ApiOperation({ summary: '追溯码列表' })
|
||||
list(@Query() query: QueryTraceCodeDto) {
|
||||
return this.service.list(query);
|
||||
}
|
||||
|
||||
@Get('trace-codes/export')
|
||||
@Roles(RoleType.OPERATOR)
|
||||
@ApiOperation({ summary: '导出追溯码 Excel' })
|
||||
export(@Query('batchId') batchId: string | undefined, @Res() res: Response) {
|
||||
return this.service.exportExcel(batchId ? Number(batchId) : undefined, res);
|
||||
}
|
||||
|
||||
@Get('trace-codes/:id/qrcode')
|
||||
@ApiOperation({ summary: '获取追溯码二维码 PNG' })
|
||||
async qrcode(@Param('id') id: string, @Res() res: Response) {
|
||||
const buf = await this.service.getQrPng(BigInt(id));
|
||||
res.setHeader('Content-Type', 'image/png');
|
||||
res.end(buf);
|
||||
}
|
||||
|
||||
@Put('trace-codes/:id/bind')
|
||||
@Roles(RoleType.OPERATOR)
|
||||
@ApiOperation({ summary: '绑定艺术品' })
|
||||
bind(@Param('id') id: string, @Body() dto: BindArtworkDto) {
|
||||
return this.service.bind(BigInt(id), dto.artworkId);
|
||||
}
|
||||
|
||||
@Put('trace-codes/:id/unbind')
|
||||
@Roles(RoleType.OPERATOR)
|
||||
@ApiOperation({ summary: '解绑艺术品' })
|
||||
unbind(@Param('id') id: string) {
|
||||
return this.service.unbind(BigInt(id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user