feat: 展示单件出库时间轴记录
This commit is contained in:
@@ -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<bigint | null> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user