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
+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);
}