feat: 优化建档草稿和审核详情入口

This commit is contained in:
Nixevol
2026-07-05 01:55:42 +08:00
parent b736b8a105
commit 41133a3db5
8 changed files with 314 additions and 64 deletions
+3
View File
@@ -1,8 +1,11 @@
import { Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bullmq';
import { QUEUE_NAMES } from '@artveris/shared';
import { ArtworkService } from './artwork.service';
import { ArtworkController } from './artwork.controller';
@Module({
imports: [BullModule.registerQueue({ name: QUEUE_NAMES.WATERMARK })],
controllers: [ArtworkController],
providers: [ArtworkService],
exports: [ArtworkService],
+51 -16
View File
@@ -1,6 +1,8 @@
import { Injectable } from '@nestjs/common';
import { InjectQueue } from '@nestjs/bullmq';
import { Prisma } from '@prisma/client';
import { AuditStatus, ErrorCode } from '@artveris/shared';
import { Queue } from 'bullmq';
import { AuditStatus, ErrorCode, QUEUE_NAMES } from '@artveris/shared';
import { PrismaService } from '../prisma/prisma.service';
import { StorageService } from '../storage/storage.service';
import { BusinessException } from '../common/exceptions/business.exception';
@@ -26,6 +28,7 @@ export class ArtworkService {
constructor(
private readonly prisma: PrismaService,
private readonly storage: StorageService,
@InjectQueue(QUEUE_NAMES.WATERMARK) private readonly watermarkQueue: Queue,
) {}
private mapMedia(items: unknown): Array<MediaItem & { url: string }> {
@@ -45,22 +48,54 @@ export class ArtworkService {
where: { id: dto.templateId, deletedAt: null },
});
if (!tpl) throw new BusinessException(ErrorCode.TEMPLATE_NOT_FOUND, '模板不存在', 404);
const artwork = await this.prisma.artwork.create({
data: {
templateId: dto.templateId,
title: dto.title,
artist: dto.artist,
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue,
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue,
createdBy: userId,
traceNodes: { create: DEFAULT_TRACE_NODES },
},
});
// 创建后回填档案编号(需要自增 id)
await this.prisma.artwork.update({
where: { id: artwork.id },
data: { archiveNo: this.buildArchiveNo(artwork.id) },
const traceNodes =
dto.traceNodes === undefined
? DEFAULT_TRACE_NODES
: dto.traceNodes.map((node, index) => ({
nodeType: node.nodeType,
title: node.title,
occurredAt: node.occurredAt ? new Date(node.occurredAt) : null,
location: node.location,
description: node.description,
mediaFiles: (node.mediaFiles ?? []) as unknown as Prisma.InputJsonValue,
sortOrder: node.sortOrder ?? index,
}));
const certificates = (dto.certificates ?? []).map((cert) => ({
name: cert.name,
issuer: cert.issuer,
issuedAt: cert.issuedAt ? new Date(cert.issuedAt) : null,
type: cert.type,
originFileUrl: cert.originKey,
}));
const artwork = await this.prisma.$transaction(async (tx) => {
const created = await tx.artwork.create({
data: {
templateId: dto.templateId,
title: dto.title,
artist: dto.artist,
status: dto.status,
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue,
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue,
createdBy: userId,
traceNodes: traceNodes.length ? { create: traceNodes } : undefined,
certificates: certificates.length ? { create: certificates } : undefined,
},
include: { certificates: true },
});
await tx.artwork.update({
where: { id: created.id },
data: { archiveNo: this.buildArchiveNo(created.id) },
});
return created;
});
await Promise.all(
artwork.certificates.map((cert) =>
this.watermarkQueue.add('generate', { certificateId: cert.id, originKey: cert.originFileUrl }),
),
);
return this.get(artwork.id);
}
+90 -1
View File
@@ -2,6 +2,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import {
IsArray,
IsDateString,
IsEnum,
IsInt,
IsNotEmpty,
@@ -12,7 +13,7 @@ import {
ValidateNested,
} from 'class-validator';
import { IsBoolean } from 'class-validator';
import { ArtworkStatus, AuditStatus } from '@artveris/shared';
import { ArtworkStatus, AuditStatus, CertType, NodeType } from '@artveris/shared';
import { PaginationDto } from '../../common/dto/pagination.dto';
export class MediaItemDto {
@@ -61,6 +62,94 @@ export class CreateArtworkDto {
@ValidateNested({ each: true })
@Type(() => MediaItemDto)
images?: MediaItemDto[];
@ApiPropertyOptional({ description: '状态', enum: ArtworkStatus })
@IsOptional()
@IsEnum(ArtworkStatus)
status?: ArtworkStatus;
@ApiPropertyOptional({ description: '创建时一并保存的溯源时间轴草稿', type: () => [CreateArtworkTraceNodeDto] })
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateArtworkTraceNodeDto)
traceNodes?: CreateArtworkTraceNodeDto[];
@ApiPropertyOptional({ description: '创建时一并保存的认证文件草稿', type: () => [CreateArtworkCertificateDto] })
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => CreateArtworkCertificateDto)
certificates?: CreateArtworkCertificateDto[];
}
export class CreateArtworkTraceNodeDto {
@ApiProperty({ description: '节点类型', enum: NodeType })
@IsEnum(NodeType)
nodeType!: NodeType;
@ApiProperty({ description: '节点标题' })
@IsString()
@IsNotEmpty()
@MaxLength(80)
title!: string;
@ApiPropertyOptional({ description: '发生时间' })
@IsOptional()
@IsDateString()
occurredAt?: string;
@ApiPropertyOptional({ description: '地点' })
@IsOptional()
@IsString()
@MaxLength(120)
location?: string;
@ApiPropertyOptional({ description: '说明' })
@IsOptional()
@IsString()
@MaxLength(2000)
description?: string;
@ApiPropertyOptional({ description: '图片/视频', type: [MediaItemDto] })
@IsOptional()
@IsArray()
@ValidateNested({ each: true })
@Type(() => MediaItemDto)
mediaFiles?: MediaItemDto[];
@ApiPropertyOptional({ description: '排序' })
@IsOptional()
@IsInt()
sortOrder?: number;
}
export class CreateArtworkCertificateDto {
@ApiProperty({ description: '证书名称' })
@IsString()
@IsNotEmpty()
@MaxLength(120)
name!: string;
@ApiPropertyOptional({ description: '颁发机构' })
@IsOptional()
@IsString()
@MaxLength(120)
issuer?: string;
@ApiPropertyOptional({ description: '颁发时间' })
@IsOptional()
@IsDateString()
issuedAt?: string;
@ApiProperty({ description: '类型', enum: CertType })
@IsEnum(CertType)
type!: CertType;
@ApiProperty({ description: '原始文件存储 key(上传接口返回)' })
@IsString()
@IsNotEmpty()
originKey!: string;
}
export class UpdateArtworkDto {