import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { Transform, Type } from 'class-transformer'; import { ArrayNotEmpty, IsArray, IsBoolean, IsEnum, IsIn, IsInt, IsOptional, IsString, Max, MaxLength, Min, } from 'class-validator'; import { TraceCodeStatus } from '@artveris/shared'; import { PaginationDto } from '../../common/dto/pagination.dto'; import { ONCHAIN_FILTER_STATUSES, OnchainFilterStatus } from '../../common/dto/trace-code-selection.dto'; import { queryBoolean } from '../../common/utils/query-boolean.util'; export class GenerateBatchDto { @ApiProperty({ description: '所属作品(款)ID' }) @Type(() => Number) @IsInt() artworkId!: number; @ApiProperty({ description: '生成数量', minimum: 1, maximum: 10000 }) @Type(() => Number) @IsInt() @Min(1) @Max(10000) quantity!: number; @ApiPropertyOptional({ description: '批次编号(留空自动生成)' }) @IsOptional() @IsString() @MaxLength(50) batchNo?: string; @ApiPropertyOptional({ description: '分组 ID' }) @IsOptional() @Type(() => Number) @IsInt() groupId?: number; } export class QueryTraceCodeDto extends PaginationDto { @ApiPropertyOptional({ description: '作品(款)ID' }) @IsOptional() @Type(() => Number) @IsInt() artworkId?: number; @ApiPropertyOptional({ description: '批次 ID' }) @IsOptional() @Type(() => Number) @IsInt() batchId?: number; @ApiPropertyOptional({ description: '状态', enum: TraceCodeStatus }) @IsOptional() @IsEnum(TraceCodeStatus) status?: TraceCodeStatus; @ApiPropertyOptional({ description: '出库状态', enum: ['OUTBOUND', 'NOT_OUTBOUND'] }) @IsOptional() @IsIn(['OUTBOUND', 'NOT_OUTBOUND']) outboundStatus?: 'OUTBOUND' | 'NOT_OUTBOUND'; @ApiPropertyOptional({ description: '上链状态', enum: ONCHAIN_FILTER_STATUSES }) @IsOptional() @IsIn(ONCHAIN_FILTER_STATUSES) proofStatus?: OnchainFilterStatus; @ApiPropertyOptional({ description: '是否已经首次激活' }) @IsOptional() @Transform(queryBoolean) @IsBoolean() activated?: boolean; @ApiPropertyOptional({ description: '分组 ID' }) @IsOptional() @Type(() => Number) @IsInt() groupId?: number; @ApiPropertyOptional({ description: '关键词(追溯码/档案号/作品名称)' }) @IsOptional() @IsString() keyword?: string; } export class GroupDto { @ApiProperty({ description: '分组名称' }) @IsString() @MaxLength(50) name!: string; @ApiPropertyOptional({ description: '备注' }) @IsOptional() @IsString() @MaxLength(255) remark?: string; } export class BatchGroupDto { @ApiProperty({ description: '追溯码 ID 列表', type: [String] }) @IsArray() @ArrayNotEmpty() @IsString({ each: true }) ids!: string[]; @ApiPropertyOptional({ description: '目标分组 ID(null 表示移出分组)' }) @IsOptional() @Type(() => Number) @IsInt() groupId?: number | null; } export class BatchStatusDto { @ApiProperty({ description: '追溯码 ID 列表', type: [String] }) @IsArray() @ArrayNotEmpty() @IsString({ each: true }) ids!: string[]; @ApiProperty({ description: 'true 停用,false 启用' }) @IsBoolean() disabled!: boolean; @ApiPropertyOptional({ description: 'true 标记为异常(优先级高于 disabled)' }) @IsOptional() @IsBoolean() abnormal?: boolean; } export class UpdateTraceCodeDto { @ApiPropertyOptional({ description: '目标分组 ID,null 表示移出分组' }) @IsOptional() @Type(() => Number) @IsInt() groupId?: number | null; @ApiPropertyOptional({ description: '目标批次 ID' }) @IsOptional() @Type(() => Number) @IsInt() batchId?: number; @ApiPropertyOptional({ description: '新批次编号,填写后自动创建批次并移动到该批次' }) @IsOptional() @IsString() @MaxLength(50) batchNo?: string; @ApiPropertyOptional({ description: 'true 停用,false 启用' }) @IsOptional() @IsBoolean() disabled?: boolean; } export class BatchMoveDto { @ApiProperty({ description: '追溯码 ID 列表', type: [String] }) @IsArray() @ArrayNotEmpty() @IsString({ each: true }) ids!: string[]; @ApiPropertyOptional({ description: '目标批次 ID' }) @IsOptional() @Type(() => Number) @IsInt() batchId?: number; @ApiPropertyOptional({ description: '新批次编号,填写后自动创建批次并移动到该批次' }) @IsOptional() @IsString() @MaxLength(50) batchNo?: string; } export class BatchDeleteDto { @ApiProperty({ description: '追溯码 ID 列表', type: [String] }) @IsArray() @ArrayNotEmpty() @IsString({ each: true }) ids!: string[]; } export class QueryBatchDto extends PaginationDto { @ApiPropertyOptional({ description: '作品/款式 ID' }) @IsOptional() @Type(() => Number) @IsInt() artworkId?: number; @ApiPropertyOptional({ description: '关键词(批次编号)' }) @IsOptional() @IsString() keyword?: string; } export class ExportTraceCodeDto { @ApiPropertyOptional({ description: '作品(款)ID' }) @IsOptional() @Type(() => Number) @IsInt() artworkId?: number; @ApiPropertyOptional({ description: '分组 ID' }) @IsOptional() @Type(() => Number) @IsInt() groupId?: number; @ApiPropertyOptional({ description: '批次 ID' }) @IsOptional() @Type(() => Number) @IsInt() batchId?: number; @ApiPropertyOptional({ description: '状态', enum: TraceCodeStatus }) @IsOptional() @IsEnum(TraceCodeStatus) status?: TraceCodeStatus; @ApiPropertyOptional({ description: '出库状态', enum: ['OUTBOUND', 'NOT_OUTBOUND'] }) @IsOptional() @IsIn(['OUTBOUND', 'NOT_OUTBOUND']) outboundStatus?: 'OUTBOUND' | 'NOT_OUTBOUND'; @ApiPropertyOptional({ description: '是否已经首次激活' }) @IsOptional() @Transform(queryBoolean) @IsBoolean() activated?: boolean; @ApiPropertyOptional({ description: '关键词' }) @IsOptional() @IsString() keyword?: string; @ApiPropertyOptional({ description: '指定追溯码 ID(逗号分隔,用于导出所选)' }) @IsOptional() @IsString() ids?: string; }