diff --git a/aidocs/project_context.md b/aidocs/project_context.md index 8a977b8..2e2f938 100644 --- a/aidocs/project_context.md +++ b/aidocs/project_context.md @@ -102,6 +102,7 @@ - 后台列表横向滚动(2026-07-04):主数据表(艺术品档案、模板、内容审核、查询日志、用户、追溯码面板)统一给 `n-data-table` 设置 `scroll-x`,并为弹性文本列补明确宽度与必要的 `ellipsis`,避免浏览器宽度不足或字段过多时列被强行压缩、操作列消失;横向滚动发生在列表内部,纵向仍保持表体内滚动与底部分页固定。 - 后台操作列约定(2026-07-04):主列表的操作列统一 `fixed: 'right'` 且 `align: 'center'`,表头和内容居中;全局 `.table-fill` 为 Naive UI 右固定列补不透明表头/单元格背景与左侧阴影分隔,避免横向滚动时固定操作列透明叠在其他字段上。 - 上链录入弱化区块高度(2026-07-04):原版 PRD 要求 C 端可展示区块高度,但后台运营手工录入时不应把它作为重点字段。追溯码管理的“登记出库/上链”弹窗和 `Outbound.vue` 单条录入页默认只展示交易/存证哈希与上链时间,区块高度收进“更多上链信息”折叠项,仍作为可选字段保存到 `BlockchainProof.blockHeight`。 +- 单件出库记录进入 C 端时间轴(2026-07-04):出库实况图/出库时间是 `TraceCode` 单件实物级数据,档案时间轴节点是 `Artwork.traceNodes` 档案级数据,二者不再依赖同一条手工节点。`PublicTraceService.trace` 在公开溯源返回时,如果当前追溯码存在 `outTime` 或 `outImage`,会自动在 `timeline` 末尾追加“本件出库记录”节点(`nodeType=OUTBOUND`,媒体来自 `TraceCode.outImage`),因此即使后台删除档案级“出库/流转”时间轴节点,C 端仍能展示该实物自己的出库记录。`AttestationService.trigger` 的上链摘要同步纳入 `batchNo`、`outTime`、`outImage`,保证触发上链时单件出库记录参与存证摘要。 ## 当前代码基准与注意事项 diff --git a/apps/api/src/blockchain/attestation.service.ts b/apps/api/src/blockchain/attestation.service.ts index cbbcfd1..fd82a72 100644 --- a/apps/api/src/blockchain/attestation.service.ts +++ b/apps/api/src/blockchain/attestation.service.ts @@ -18,6 +18,7 @@ export class AttestationService { const code = await this.prisma.traceCode.findUnique({ where: { id: traceCodeId }, include: { + batch: true, artwork: { include: { traceNodes: true, certificates: true } }, }, }); @@ -32,6 +33,11 @@ export class AttestationService { title: code.artwork.title, artist: code.artwork.artist, archiveNo: code.artwork.archiveNo, + batchNo: code.batch.batchNo, + outbound: { + outTime: code.outTime, + outImage: code.outImage, + }, dynamicFields: code.artwork.dynamicFields, nodes: code.artwork.traceNodes.map((n) => ({ type: n.nodeType, title: n.title })), certificates: code.artwork.certificates.map((c) => c.name), diff --git a/apps/api/src/public-trace/public-trace.service.ts b/apps/api/src/public-trace/public-trace.service.ts index 328d3bb..9e42b4c 100644 --- a/apps/api/src/public-trace/public-trace.service.ts +++ b/apps/api/src/public-trace/public-trace.service.ts @@ -15,6 +15,8 @@ export interface TraceContext { } const MAP_TTL = 3600; // 短码→id 映射缓存 1 小时 +const OUTBOUND_TRACE_TITLE = '本件出库记录'; +const OUTBOUND_TRACE_DESC = '该追溯码对应实物的出库实况记录。'; @Injectable() export class PublicTraceService { @@ -33,6 +35,42 @@ export class PublicTraceService { .map((i) => ({ name: i.name, type: i.type, url: this.storage.getUrl(i.key) })); } + private buildTimeline( + nodes: Array<{ + nodeType: string; + title: string; + occurredAt: Date | null; + location: string | null; + description: string | null; + mediaFiles: unknown; + }>, + code: { outTime?: Date | null; outImage?: string | null }, + ) { + const timeline = nodes.map((n) => ({ + nodeType: n.nodeType, + title: n.title, + occurredAt: n.occurredAt, + location: n.location, + description: n.description, + media: this.mapMedia(n.mediaFiles), + })); + + if (code.outTime || code.outImage) { + timeline.push({ + nodeType: 'OUTBOUND', + title: OUTBOUND_TRACE_TITLE, + occurredAt: code.outTime ?? null, + location: null, + description: OUTBOUND_TRACE_DESC, + media: code.outImage + ? [{ name: '出库实况图', type: 'image', url: this.storage.getUrl(code.outImage) }] + : [], + }); + } + + return timeline; + } + private async resolveId(shortCode: string): Promise { const cacheKey = `trace:map:${shortCode}`; const cached = await this.redis.get(cacheKey); @@ -134,14 +172,7 @@ export class PublicTraceService { images: this.mapMedia(artwork.images), fields: this.buildFields(artwork.template.fields, artwork.dynamicFields), }, - timeline: artwork.traceNodes.map((n) => ({ - nodeType: n.nodeType, - title: n.title, - occurredAt: n.occurredAt, - location: n.location, - description: n.description, - media: this.mapMedia(n.mediaFiles), - })), + timeline: this.buildTimeline(artwork.traceNodes, code), certificates: artwork.certificates.map((c) => ({ name: c.name, issuer: c.issuer,