refactor: 按甲方确认重构为一款多码(档案编号标识款、批次码、按款统计)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-30 12:02:44 +08:00
co-authored by Cursor
parent 67c5887f8f
commit a16e6f1165
34 changed files with 445 additions and 353 deletions
@@ -8,7 +8,7 @@ import { GeoService } from '../geo/geo.service';
import { REDIS_CLIENT } from '../redis/redis.module';
import { parseUserAgent } from '../common/utils/ua.util';
type TraceCodeWithBatch = Prisma.TraceCodeGetPayload<{ include: { batch: true } }>;
type TraceCodeWithRel = Prisma.TraceCodeGetPayload<{ include: { batch: true; artwork: true } }>;
export interface TraceContext {
ip: string;
@@ -55,9 +55,12 @@ export class PublicTraceService {
return { status: 'INVALID' as const };
}
const code = await this.prisma.traceCode.findUnique({ where: { id }, include: { batch: true } });
if (!code || !code.artworkId || code.status === TraceCodeStatus.UNBOUND) {
await this.writeLog(id, null, shortCode, QueryResult.INVALID, ctx, code ?? undefined);
const code = await this.prisma.traceCode.findUnique({
where: { id },
include: { batch: true, artwork: true },
});
if (!code) {
await this.writeLog(id, null, shortCode, QueryResult.INVALID, ctx);
return { status: 'INVALID' as const };
}
if (code.status === TraceCodeStatus.DISABLED) {
@@ -129,6 +132,7 @@ export class PublicTraceService {
artwork: {
title: artwork.title,
artist: artwork.artist,
archiveNo: artwork.archiveNo,
images: this.mapMedia(artwork.images),
fields: this.buildFields(artwork.template.fields, artwork.dynamicFields),
},
@@ -189,7 +193,7 @@ export class PublicTraceService {
shortCode: string,
result: QueryResult,
ctx: TraceContext,
code?: Partial<TraceCodeWithBatch>,
code?: Partial<TraceCodeWithRel>,
): Promise<void> {
try {
const device = parseUserAgent(ctx.userAgent);
@@ -199,8 +203,7 @@ export class PublicTraceService {
artworkId: artworkId ?? undefined,
shortCode,
code: code?.code ?? undefined,
sku: code?.sku ?? undefined,
archiveNo: code?.archiveNo ?? undefined,
archiveNo: code?.artwork?.archiveNo ?? undefined,
batchNo: code?.batch?.batchNo ?? undefined,
queryCount: code?.queryCount ?? undefined,
firstActivatedAt: code?.firstActivatedAt ?? undefined,