feat: 无修改时禁止提交审核

This commit is contained in:
Nixevol
2026-07-05 03:35:20 +08:00
parent a195adba1b
commit 29e608e782
5 changed files with 154 additions and 5 deletions
+71 -4
View File
@@ -278,6 +278,9 @@ export class ArtworkService {
const artwork = await this.ensureExists(id);
const shouldApplyDirectly = artwork.status !== ArtworkStatus.ACTIVE || artwork.auditStatus !== AuditStatus.APPROVED;
if (!this.hasSnapshotChanged(current, afterSnapshot)) {
throw new BusinessException(ErrorCode.VALIDATION_FAILED, '作品内容未发生变化,无需提交审核', 400);
}
const revisionTitle = dto.revisionTitle || '作品内容修改';
const revisionReason = dto.revisionReason || null;
@@ -454,7 +457,7 @@ export class ArtworkService {
return nodes.map((node, index) => ({
nodeType: node.nodeType,
title: node.title,
occurredAt: node.occurredAt ?? null,
occurredAt: this.normalizeDateOnly(node.occurredAt),
location: node.location ?? null,
description: node.description ?? null,
mediaFiles: (node.mediaFiles ?? []) as MediaItem[],
@@ -466,7 +469,7 @@ export class ArtworkService {
return certs.map((cert) => ({
name: cert.name,
issuer: cert.issuer ?? null,
issuedAt: cert.issuedAt ?? null,
issuedAt: this.normalizeDateOnly(cert.issuedAt),
type: cert.type,
originKey: cert.originKey,
watermarkKey: cert.watermarkKey ?? null,
@@ -512,7 +515,7 @@ export class ArtworkService {
.map((node) => ({
nodeType: node.nodeType,
title: node.title,
occurredAt: node.occurredAt ? node.occurredAt.toISOString() : null,
occurredAt: this.normalizeDateOnly(node.occurredAt),
location: node.location,
description: node.description,
mediaFiles: (Array.isArray(node.mediaFiles) ? node.mediaFiles : []) as unknown as MediaItem[],
@@ -521,7 +524,7 @@ export class ArtworkService {
certificates: record.certificates.map((cert) => ({
name: cert.name,
issuer: cert.issuer,
issuedAt: cert.issuedAt ? cert.issuedAt.toISOString() : null,
issuedAt: this.normalizeDateOnly(cert.issuedAt),
type: cert.type,
originKey: cert.originFileUrl,
watermarkKey: cert.watermarkFileUrl,
@@ -529,6 +532,70 @@ export class ArtworkService {
};
}
private hasSnapshotChanged(before: ArtworkSnapshot, after: ArtworkSnapshot): boolean {
return JSON.stringify(this.normalizeSnapshotForCompare(before)) !== JSON.stringify(this.normalizeSnapshotForCompare(after));
}
private normalizeSnapshotForCompare(snapshot: ArtworkSnapshot) {
return {
artwork: {
templateId: Number(snapshot.artwork.templateId),
title: snapshot.artwork.title ?? '',
artist: snapshot.artwork.artist ?? '',
status: snapshot.artwork.status,
dynamicFields: this.normalizeJson(snapshot.artwork.dynamicFields ?? {}),
images: this.normalizeMedia(snapshot.artwork.images),
},
traceNodes: snapshot.traceNodes.map((node, index) => ({
nodeType: node.nodeType,
title: node.title ?? '',
occurredAt: this.normalizeDateOnly(node.occurredAt),
location: node.location ?? '',
description: node.description ?? '',
mediaFiles: this.normalizeMedia(node.mediaFiles),
sortOrder: index,
})),
certificates: snapshot.certificates.map((cert) => ({
name: cert.name ?? '',
issuer: cert.issuer ?? '',
issuedAt: this.normalizeDateOnly(cert.issuedAt),
type: cert.type,
originKey: cert.originKey,
watermarkKey: cert.watermarkKey ?? '',
})),
};
}
private normalizeMedia(items?: MediaItem[]) {
return (items ?? []).map((item) => ({
key: item.key,
name: item.name ?? '',
type: item.type ?? '',
}));
}
private normalizeJson(value: unknown): unknown {
if (Array.isArray(value)) return value.map((item) => this.normalizeJson(item));
if (value && typeof value === 'object') {
return Object.keys(value as Record<string, unknown>)
.sort()
.reduce<Record<string, unknown>>((acc, key) => {
const item = (value as Record<string, unknown>)[key];
if (item !== undefined) acc[key] = this.normalizeJson(item);
return acc;
}, {});
}
return value ?? null;
}
private normalizeDateOnly(value?: string | Date | null): string | null {
if (!value) return null;
if (value instanceof Date) return value.toISOString().slice(0, 10);
const date = new Date(value);
if (!Number.isNaN(date.getTime())) return date.toISOString().slice(0, 10);
return value.slice(0, 10);
}
private snapshotWithUrls(input: unknown) {
const snapshot = input as ArtworkSnapshot | Record<string, never>;
if (!('artwork' in snapshot)) return snapshot;