fix: 统一追溯码并修正天河链存证跳转
This commit is contained in:
@@ -325,3 +325,11 @@
|
||||
- 需求以「一款档案 Artwork → 多批次 Batch → 每套实物 TraceCode(一物一码)」为准;`docs/` 里旧「绑定防伪码/SKU/一物一码」表述仅作背景。
|
||||
- 改后端 enum/模型需同步 `packages/shared/enums.ts` 并加 Prisma 迁移;改运行时可配置项走系统设置而非硬编码。
|
||||
- Windows/PowerShell 环境:`&&` 不可用,读中文输出前先设 UTF-8;`nest --watch` 运行时勿删 `apps/api/dist`。
|
||||
|
||||
## 2026-07-13 · 统一追溯码与天河 DApp 浏览器跳转
|
||||
|
||||
- 删除历史遗留的第二套 18 位完整编码:`TraceCode.code` 与 `QueryLog.code` 已从 Prisma 模型、生成任务、种子、查询日志、搜索、导出、公开接口和客户端中移除;12 位纯数字 `TraceCode.shortCode` 是唯一业务追溯码,数据库内部仅另保留自增主键 `id`。迁移:`20260713070000_remove_redundant_trace_code`。
|
||||
- 链上 `dataHash` 的新记录摘要只包含 `shortCode` 等实际业务字段;历史 proof 的既有 `dataHash` 不重算。旧备份恢复时会主动丢弃 `traceCode.code/queryLog.code`,保证升级前备份仍可恢复。
|
||||
- C 端不再展示第二套“唯一追溯码”。导出 xlsx 删除“完整编码”列,只保留 12 位追溯码、链接与二维码。
|
||||
- 天河链“查看存证”使用 NFT 发行返回的 mint 交易哈希 `BlockchainProof.txHash`,公开接口响应时动态构造 DApp 浏览器交易详情链接,不信任数据库历史 `explorerUrl`:测试环境 `https://test.explorer.tianhecloud.com/#/tiChain/transDetail?hash=<txHash>`,正式环境 `https://explorer.tianhecloud.com/#/tiChain/transDetail?hash=<txHash>`。环境取系统设置 `tianheEnv`,自定义环境再按 API Base URL 是否含 `test.` 推断。
|
||||
- 验证:Prisma Client 生成成功;当前开发库迁移完成且 9 个迁移全部最新;后端 8 套件 33 项单测通过;`pnpm build` 全量构建通过。为释放 Windows Prisma DLL 锁,验证前停止了本项目 API 开发进程,admin/client Vite 未停止。
|
||||
|
||||
@@ -379,7 +379,6 @@
|
||||
"generate": "Generate Trace Codes",
|
||||
"generatedCount": "Generated",
|
||||
"shortCode": "Trace Code",
|
||||
"code": "Trace Code",
|
||||
"url": "Link",
|
||||
"keywordPlaceholder": "Trace code / link / archive no. / name / artist / batch / group / note",
|
||||
"queryCount": "Queries",
|
||||
|
||||
@@ -379,7 +379,6 @@
|
||||
"generate": "生成追溯码",
|
||||
"generatedCount": "已生成",
|
||||
"shortCode": "追溯码",
|
||||
"code": "追溯码",
|
||||
"url": "链接",
|
||||
"keywordPlaceholder": "追溯码 / 链接 / 档案编号 / 名称 / 艺术家 / 批次 / 分组 / 备注",
|
||||
"queryCount": "查询次数",
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
-- 12 位 short_code 已是唯一业务追溯码,移除历史遗留的第二套完整编码。
|
||||
ALTER TABLE `query_log` DROP COLUMN `code`;
|
||||
ALTER TABLE `trace_code` DROP INDEX `trace_code_code_key`, DROP COLUMN `code`;
|
||||
@@ -307,7 +307,6 @@ model Batch {
|
||||
|
||||
model TraceCode {
|
||||
id BigInt @id @default(autoincrement())
|
||||
code String @unique
|
||||
shortCode String @unique @map("short_code")
|
||||
artworkId Int @map("artwork_id")
|
||||
batchId Int @map("batch_id")
|
||||
@@ -370,7 +369,6 @@ model QueryLog {
|
||||
traceCodeId BigInt? @map("trace_code_id")
|
||||
artworkId Int? @map("artwork_id")
|
||||
shortCode String? @map("short_code")
|
||||
code String?
|
||||
archiveNo String? @map("archive_no")
|
||||
batchNo String? @map("batch_no")
|
||||
queryCount Int? @map("query_count")
|
||||
|
||||
@@ -11,7 +11,6 @@ const prisma = new PrismaClient();
|
||||
const storageDir = resolve(process.env.STORAGE_LOCAL_DIR || './storage');
|
||||
const ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
const shortId = customAlphabet(ALPHABET, 10);
|
||||
const codeId = customAlphabet(ALPHABET, 18);
|
||||
// 公开短码须为 12 位纯数字(与 TRACE_CODE_PATTERN=/^\d{12}$/ 一致),否则 C 端公开溯源会判 INVALID
|
||||
const numericId = customAlphabet('0123456789', 12);
|
||||
function uniqueShortCode(used: Set<string>): string {
|
||||
@@ -221,7 +220,6 @@ async function ensureSampleData(): Promise<void> {
|
||||
const isActive = artworkActive && k < 2; // 该款前两套已激活
|
||||
const code = await prisma.traceCode.create({
|
||||
data: {
|
||||
code: codeId(),
|
||||
shortCode,
|
||||
artworkId: artwork.id,
|
||||
batchId: batch.id,
|
||||
@@ -241,7 +239,6 @@ async function ensureSampleData(): Promise<void> {
|
||||
traceCodeId: code.id,
|
||||
artworkId: artwork.id,
|
||||
shortCode,
|
||||
code: code.code,
|
||||
archiveNo: `ARTVERIS-${String(artwork.id).padStart(6, '0')}`,
|
||||
batchNo: batch.batchNo,
|
||||
queryCount: 3 + k,
|
||||
@@ -256,7 +253,7 @@ async function ensureSampleData(): Promise<void> {
|
||||
},
|
||||
});
|
||||
}
|
||||
const dataHash = '0x' + createHash('sha256').update(JSON.stringify({ c: code.code })).digest('hex');
|
||||
const dataHash = '0x' + createHash('sha256').update(JSON.stringify({ shortCode })).digest('hex');
|
||||
const txHash = '0x' + randomBytes(32).toString('hex');
|
||||
await prisma.blockchainProof.create({
|
||||
data: {
|
||||
|
||||
@@ -343,7 +343,14 @@ export class BackupService {
|
||||
await (tx as any)[model].deleteMany();
|
||||
}
|
||||
for (const model of MODELS) {
|
||||
const rows = Array.isArray(db[model]) ? db[model].map(reviveRow) : [];
|
||||
const rows = Array.isArray(db[model])
|
||||
? db[model].map((row: unknown) => {
|
||||
const revived = reviveRow(row as Record<string, any>) as Record<string, unknown>;
|
||||
// 兼容移除第二套完整编码前生成的历史备份。
|
||||
if (model === 'traceCode' || model === 'queryLog') delete revived.code;
|
||||
return revived;
|
||||
})
|
||||
: [];
|
||||
if (rows.length) await (tx as any)[model].createMany({ data: rows });
|
||||
}
|
||||
}, { timeout: 120000 });
|
||||
|
||||
@@ -60,7 +60,6 @@ export class AttestationService {
|
||||
|
||||
const summary = {
|
||||
shortCode: code.shortCode,
|
||||
code: code.code,
|
||||
title: code.artwork.title,
|
||||
artist: code.artwork.artist,
|
||||
archiveNo: code.artwork.archiveNo,
|
||||
|
||||
@@ -22,7 +22,7 @@ function mockHttpsRequestOnce(responseJson: unknown, statusCode = 200) {
|
||||
|
||||
// 放在 jest.mock 之后导入,确保 provider 拿到被 mock 的 https
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const { TianheProvider } = require('./tianhe.provider') as typeof import('./tianhe.provider');
|
||||
const { TianheProvider, buildTianheExplorerTxUrl } = require('./tianhe.provider') as typeof import('./tianhe.provider');
|
||||
|
||||
describe('TianheProvider', () => {
|
||||
const provider = new TianheProvider({
|
||||
@@ -37,6 +37,16 @@ describe('TianheProvider', () => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it('按天河环境生成 DApp 浏览器交易详情地址', () => {
|
||||
const txHash = '0xabc/123';
|
||||
expect(buildTianheExplorerTxUrl('https://test.api.tichain.tianhecloud.com', txHash)).toBe(
|
||||
'https://test.explorer.tianhecloud.com/#/tiChain/transDetail?hash=0xabc%2F123',
|
||||
);
|
||||
expect(
|
||||
buildTianheExplorerTxUrl('https://custom-api.example.com', txHash, 'production'),
|
||||
).toBe('https://explorer.tianhecloud.com/#/tiChain/transDetail?hash=0xabc%2F123');
|
||||
});
|
||||
|
||||
it('按天河链 upload 文档映射交易哈希、存证链接和文件哈希', async () => {
|
||||
const response = {
|
||||
code: 0,
|
||||
|
||||
@@ -71,6 +71,15 @@ function redactSecrets(obj: Record<string, unknown>): Record<string, unknown> {
|
||||
return masked;
|
||||
}
|
||||
|
||||
export function buildTianheExplorerTxUrl(baseUrl: string, txHash: string, environment?: string): string {
|
||||
const testEnvironment =
|
||||
environment === 'test' || (environment !== 'production' && baseUrl.toLowerCase().includes('test.'));
|
||||
const explorerBase = testEnvironment
|
||||
? 'https://test.explorer.tianhecloud.com'
|
||||
: 'https://explorer.tianhecloud.com';
|
||||
return `${explorerBase}/#/tiChain/transDetail?hash=${encodeURIComponent(txHash)}`;
|
||||
}
|
||||
|
||||
export class TianheProvider implements AttestationProvider {
|
||||
readonly name = 'tianhe';
|
||||
private readonly logger = new Logger('TianheAPI');
|
||||
@@ -89,16 +98,9 @@ export class TianheProvider implements AttestationProvider {
|
||||
return required(this.opts.baseUrl, 'Base URL').replace(/\/+$/, '');
|
||||
}
|
||||
|
||||
// 天河区块浏览器域名:测试 test.explorer.tianhecloud.com / 生产 explorer.tianhecloud.com(由 API base 是否含 test. 判定)
|
||||
private explorerBase(): string {
|
||||
return this.baseUrl().includes('test.')
|
||||
? 'https://test.explorer.tianhecloud.com'
|
||||
: 'https://explorer.tianhecloud.com';
|
||||
}
|
||||
|
||||
// 交易详情页:客户凭 mint 交易哈希可查看状态/区块高度/追溯码(productId)/存证链接(feature),比裸 UDFS JSON 规范
|
||||
// DApp 浏览器交易详情页使用 mint 交易哈希,不使用 API 地址或本地 dataHash。
|
||||
explorerTxUrl(txHash: string): string {
|
||||
return `${this.explorerBase()}/#/tiChain/transDetail?hash=${encodeURIComponent(txHash)}`;
|
||||
return buildTianheExplorerTxUrl(this.baseUrl(), txHash);
|
||||
}
|
||||
|
||||
private credentials() {
|
||||
|
||||
@@ -4,8 +4,10 @@ import { Prisma } from '@prisma/client';
|
||||
import { ArtworkStatus, AuditStatus, QueryResult, ProofStatus, TRACE_CODE_PATTERN, TraceCodeStatus } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { SettingsService } from '../settings/settings.service';
|
||||
import { REDIS_CLIENT } from '../redis/redis.module';
|
||||
import { parseUserAgent } from '../common/utils/ua.util';
|
||||
import { buildTianheExplorerTxUrl } from '../blockchain/tianhe.provider';
|
||||
|
||||
type TraceCodeWithRel = Prisma.TraceCodeGetPayload<{ include: { batch: true; artwork: true } }>;
|
||||
type ArtworkWithRel = Prisma.ArtworkGetPayload<{
|
||||
@@ -32,6 +34,7 @@ export class PublicTraceService {
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly storage: StorageService,
|
||||
private readonly settings: SettingsService,
|
||||
@Inject(REDIS_CLIENT) private readonly redis: Redis,
|
||||
) {}
|
||||
|
||||
@@ -183,17 +186,17 @@ export class PublicTraceService {
|
||||
|
||||
const result = firstActivate ? QueryResult.FIRST_ACTIVATE : QueryResult.REPEAT;
|
||||
await this.writeLog(id, artwork.id, shortCode, result, ctx, { ...code, ...updated });
|
||||
const explorerUrl = await this.resolveExplorerUrl(proof);
|
||||
|
||||
return {
|
||||
status: 'OK' as const,
|
||||
code: code.code,
|
||||
queriedAt: now,
|
||||
antiCounterfeit: {
|
||||
firstQuery: firstActivate,
|
||||
queryCount: updated.queryCount,
|
||||
firstActivatedAt: updated.firstActivatedAt,
|
||||
},
|
||||
...this.buildArtworkPayload(artwork, code, proof),
|
||||
...this.buildArtworkPayload(artwork, code, proof, explorerUrl),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -235,10 +238,10 @@ export class PublicTraceService {
|
||||
|
||||
const now = new Date();
|
||||
const firstQuery = state === 'inactive';
|
||||
const explorerUrl = await this.resolveExplorerUrl(proof);
|
||||
return {
|
||||
status: 'OK' as const,
|
||||
preview: true,
|
||||
code: code.code,
|
||||
queriedAt: now,
|
||||
antiCounterfeit: firstQuery
|
||||
? { firstQuery: true, queryCount: 1, firstActivatedAt: now }
|
||||
@@ -247,7 +250,7 @@ export class PublicTraceService {
|
||||
queryCount: code.queryCount > 0 ? code.queryCount : 2,
|
||||
firstActivatedAt: code.firstActivatedAt ?? now,
|
||||
},
|
||||
...this.buildArtworkPayload(artwork, code, proof),
|
||||
...this.buildArtworkPayload(artwork, code, proof, explorerUrl),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -266,6 +269,7 @@ export class PublicTraceService {
|
||||
tokenId: bigint | null;
|
||||
contractAddress: string | null;
|
||||
} | null,
|
||||
explorerUrl: string | null,
|
||||
) {
|
||||
return {
|
||||
artwork: {
|
||||
@@ -291,7 +295,7 @@ export class PublicTraceService {
|
||||
blockHeight: proof.blockHeight,
|
||||
chainName: proof.chainName,
|
||||
onchainAt: proof.onchainAt,
|
||||
explorerUrl: proof.explorerUrl,
|
||||
explorerUrl,
|
||||
tokenId: proof.tokenId,
|
||||
contractAddress: proof.contractAddress,
|
||||
}
|
||||
@@ -299,6 +303,18 @@ export class PublicTraceService {
|
||||
};
|
||||
}
|
||||
|
||||
private async resolveExplorerUrl(
|
||||
proof: { txHash: string | null; chainName: string | null; explorerUrl: string | null } | null,
|
||||
): Promise<string | null> {
|
||||
const tianheProof =
|
||||
proof?.chainName === '天河链' ||
|
||||
/tianhe|tichain/i.test(proof?.chainName || '') ||
|
||||
/tianhecloud\.com/i.test(proof?.explorerUrl || '');
|
||||
if (!proof?.txHash || !tianheProof) return proof?.explorerUrl ?? null;
|
||||
const settings = await this.settings.getAllRaw();
|
||||
return buildTianheExplorerTxUrl(settings.tianheBaseUrl || '', proof.txHash, settings.tianheEnv);
|
||||
}
|
||||
|
||||
private buildFields(
|
||||
fields: Array<{ fieldKey: string; label: string; type: string }>,
|
||||
dynamic: unknown,
|
||||
@@ -336,7 +352,6 @@ export class PublicTraceService {
|
||||
traceCodeId: traceCodeId ?? undefined,
|
||||
artworkId: artworkId ?? undefined,
|
||||
shortCode,
|
||||
code: code?.code ?? undefined,
|
||||
archiveNo: code?.artwork?.archiveNo ?? undefined,
|
||||
batchNo: code?.batch?.batchNo ?? undefined,
|
||||
queryCount: code?.queryCount ?? undefined,
|
||||
|
||||
@@ -9,7 +9,7 @@ import { PaginationDto } from '../common/dto/pagination.dto';
|
||||
import { buildOrderBy } from '../common/utils/sort.util';
|
||||
|
||||
class QueryLogQueryDto extends PaginationDto {
|
||||
@ApiPropertyOptional({ description: '关键词(追溯码 / 完整编码 / 档案编号)' })
|
||||
@ApiPropertyOptional({ description: '关键词(追溯码 / 档案编号)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
keyword?: string;
|
||||
@@ -53,7 +53,6 @@ export class QueryLogController {
|
||||
if (query.keyword) {
|
||||
where.OR = [
|
||||
{ shortCode: { contains: query.keyword } },
|
||||
{ code: { contains: query.keyword } },
|
||||
{ archiveNo: { contains: query.keyword } },
|
||||
];
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ export class QueryTraceCodeDto extends PaginationDto {
|
||||
@IsInt()
|
||||
groupId?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: '关键词(追溯码/完整编码/档案号/作品名称)' })
|
||||
@ApiPropertyOptional({ description: '关键词(追溯码/档案号/作品名称)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
keyword?: string;
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { Job } from 'bullmq';
|
||||
import { customAlphabet } from 'nanoid';
|
||||
import { BatchStatus, JobStatus, QUEUE_NAMES } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { JobsService } from '../jobs/jobs.service';
|
||||
import { TraceCodeService } from './trace-code.service';
|
||||
import { TraceCodeGeneratorService } from './trace-code-generator.service';
|
||||
|
||||
const ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
const codeId = customAlphabet(ALPHABET, 18);
|
||||
|
||||
interface GenJobData {
|
||||
batchId: number;
|
||||
artworkId: number;
|
||||
@@ -45,7 +41,6 @@ export class GenCodeProcessor extends WorkerHost {
|
||||
const shortCodes = await this.generator.generate(n);
|
||||
const rows = shortCodes.map((shortCode) => {
|
||||
return {
|
||||
code: codeId(),
|
||||
shortCode,
|
||||
artworkId,
|
||||
batchId,
|
||||
|
||||
@@ -409,7 +409,6 @@ export class TraceCodeService {
|
||||
and.push({
|
||||
OR: [
|
||||
{ shortCode: { contains: query.keyword } },
|
||||
{ code: { contains: query.keyword } },
|
||||
{ url: { contains: query.keyword } },
|
||||
{ remark: { contains: query.keyword } },
|
||||
{ artwork: { archiveNo: { contains: query.keyword } } },
|
||||
@@ -508,7 +507,6 @@ export class TraceCodeService {
|
||||
{ header: '批次编号', key: 'batchNo', width: 22 },
|
||||
{ header: '分组', key: 'group', width: 14 },
|
||||
{ header: '追溯码', key: 'shortCode', width: 16 },
|
||||
{ header: '完整编码', key: 'code', width: 24 },
|
||||
{ header: '链接', key: 'url', width: 40 },
|
||||
{ header: '二维码', key: 'qr', width: 18 },
|
||||
{ header: '生成时间', key: 'createdAt', width: 22 },
|
||||
@@ -525,7 +523,6 @@ export class TraceCodeService {
|
||||
title: c.artwork?.title ?? '',
|
||||
batchNo: c.batch?.batchNo ?? '',
|
||||
group: c.group?.name ?? '',
|
||||
code: c.code,
|
||||
shortCode: c.shortCode,
|
||||
url: { text: url, hyperlink: url },
|
||||
qr: '',
|
||||
@@ -540,7 +537,7 @@ export class TraceCodeService {
|
||||
qrImages.push({ name: `images/${c.shortCode}.png`, buffer: qr });
|
||||
const imageId = wb.addImage({ buffer: qr as unknown as ExcelJS.Buffer, extension: 'png' });
|
||||
ws.addImage(imageId, {
|
||||
tl: { col: 7.15, row: row.number - 0.9 },
|
||||
tl: { col: 6.15, row: row.number - 0.9 },
|
||||
ext: { width: 84, height: 84 },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
"repeatDesc": "This code has been activated. Please note the query count.",
|
||||
"queryCount": "Queried {n} times",
|
||||
"firstActivatedAt": "First activated: {t}",
|
||||
"queriedAt": "This query: {t}",
|
||||
"code": "Trace Code"
|
||||
"queriedAt": "This query: {t}"
|
||||
},
|
||||
"section": {
|
||||
"basic": "Basic Info",
|
||||
@@ -25,7 +24,6 @@
|
||||
},
|
||||
"chain": {
|
||||
"archiveNo": "Archive No.",
|
||||
"code": "Trace Code",
|
||||
"hash": "Tx Hash",
|
||||
"dataHash": "Data Hash",
|
||||
"tokenId": "Token ID",
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
"repeatDesc": "该防伪码已激活,请留意查询次数是否异常。",
|
||||
"queryCount": "累计查询 {n} 次",
|
||||
"firstActivatedAt": "首次激活:{t}",
|
||||
"queriedAt": "本次查询:{t}",
|
||||
"code": "唯一追溯码"
|
||||
"queriedAt": "本次查询:{t}"
|
||||
},
|
||||
"section": {
|
||||
"basic": "基础信息",
|
||||
@@ -25,7 +24,6 @@
|
||||
},
|
||||
"chain": {
|
||||
"archiveNo": "档案编号",
|
||||
"code": "唯一追溯码",
|
||||
"hash": "交易哈希",
|
||||
"dataHash": "数据哈希",
|
||||
"tokenId": "数字藏品编号",
|
||||
|
||||
@@ -175,15 +175,6 @@
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="data.queriedAt" class="anti-meta">{{ t('anti.queriedAt', { t: fmt(data.queriedAt) }) }}</div>
|
||||
<div v-if="data.code" class="anti-code">
|
||||
{{ t('anti.code') }}:<span class="mono">{{ data.code }}</span>
|
||||
<button class="icon-copy anti-copy" :aria-label="t('chain.copy')" :title="t('chain.copy')" @click="copy(data.code)">
|
||||
<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true">
|
||||
<rect x="9" y="9" width="11" height="11" rx="2" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
<path d="M5 15V5a2 2 0 0 1 2-2h8" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -303,16 +294,6 @@
|
||||
<span class="chain-k">{{ t('chain.archiveNo') }}</span>
|
||||
<span class="chain-v mono">{{ data.artwork.archiveNo }}</span>
|
||||
</div>
|
||||
<div class="chain-row">
|
||||
<span class="chain-k">{{ t('chain.code') }}</span>
|
||||
<span class="chain-v mono">{{ data.code || '-' }}</span>
|
||||
<button v-if="data.code" class="icon-copy" :aria-label="t('chain.copy')" :title="t('chain.copy')" @click="copy(data.code)">
|
||||
<svg viewBox="0 0 24 24" width="15" height="15" aria-hidden="true">
|
||||
<rect x="9" y="9" width="11" height="11" rx="2" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
<path d="M5 15V5a2 2 0 0 1 2-2h8" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<template v-if="data.blockchain">
|
||||
<div class="chain-row">
|
||||
<span class="chain-k">{{ t('chain.hash') }}</span>
|
||||
@@ -356,7 +337,13 @@
|
||||
<span class="chain-k">{{ t('chain.onchainAt') }}</span>
|
||||
<span class="chain-v">{{ fmt(data.blockchain.onchainAt) }}</span>
|
||||
</div>
|
||||
<a v-if="data.blockchain.explorerUrl" class="chain-link" :href="data.blockchain.explorerUrl" target="_blank">
|
||||
<a
|
||||
v-if="data.blockchain.explorerUrl"
|
||||
class="chain-link"
|
||||
:href="data.blockchain.explorerUrl"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{{ t('chain.explorer') }} →
|
||||
</a>
|
||||
</template>
|
||||
@@ -394,15 +381,6 @@
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="data?.queriedAt" class="anti-meta">{{ t('anti.queriedAt', { t: fmt(data.queriedAt) }) }}</div>
|
||||
<div v-if="data?.code" class="anti-code">
|
||||
{{ t('anti.code') }}:<span class="mono">{{ data.code }}</span>
|
||||
<button class="icon-copy anti-copy" :aria-label="t('chain.copy')" :title="t('chain.copy')" @click="copy(data.code)">
|
||||
<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true">
|
||||
<rect x="9" y="9" width="11" height="11" rx="2" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
<path d="M5 15V5a2 2 0 0 1 2-2h8" fill="none" stroke="currentColor" stroke-width="1.7" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1019,15 +997,6 @@ watch(
|
||||
font-size: 12px;
|
||||
opacity: 0.85;
|
||||
}
|
||||
.anti-code {
|
||||
font-size: 12px;
|
||||
opacity: 0.85;
|
||||
margin-top: 2px;
|
||||
word-break: break-all;
|
||||
}
|
||||
.code-copy {
|
||||
display: none;
|
||||
}
|
||||
.carousel {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
@@ -1453,15 +1422,6 @@ watch(
|
||||
.icon-copy:active {
|
||||
background: var(--soft-bg);
|
||||
}
|
||||
.anti-copy {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
margin-left: 6px;
|
||||
border-color: rgba(255, 255, 255, 0.38);
|
||||
background: rgba(255, 255, 255, 0.12);
|
||||
color: #fff;
|
||||
vertical-align: middle;
|
||||
}
|
||||
.chain-link {
|
||||
display: inline-block;
|
||||
margin-top: 10px;
|
||||
|
||||
@@ -261,7 +261,7 @@
|
||||
- 在指定艺术品档案下按批次生成指定数量的唯一追溯码。
|
||||
- 每个追溯码关联唯一的 12 位数字码与短网址。
|
||||
- 生成二维码图片或二维码数据。
|
||||
- 导出 **ZIP 包**:内含一个 xlsx(字段:档案编号、名称、批次编号、分组、追溯码、完整编码、链接、内嵌二维码、生成时间)与 `images/{追溯码}.png` 二维码图片,便于批量打印。
|
||||
- 导出 **ZIP 包**:内含一个 xlsx(字段:档案编号、名称、批次编号、分组、追溯码、链接、内嵌二维码、生成时间)与 `images/{追溯码}.png` 二维码图片,便于批量打印。
|
||||
|
||||
#### 验收标准
|
||||
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ flowchart LR
|
||||
## 九、C 端与查验
|
||||
|
||||
- C 端溯源页区块链卡展示:链名、交易哈希、数据哈希(平台本地对结构化溯源信息计算的 sha256 指纹)、数字商品编号(tokenId)、合约地址、区块高度、上链时间;
|
||||
- 「查看存证」跳转天河区块浏览器**交易详情页**(`transDetail?hash=...`),可看到交易状态、区块高度、发行动作、productId(追溯码)与 feature(作品主图);
|
||||
- 「查看存证」按当前天河环境动态跳转 DApp 浏览器**交易详情页**(`transDetail?hash=<mintTxHash>`):测试环境使用 `test.explorer.tianhecloud.com`,正式环境使用 `explorer.tianhecloud.com`;链接不沿用数据库中的历史接口 URL;
|
||||
- 数据哈希为平台自算指纹,用于内容比对,并非链上存证文件哈希(平台不上传存证文件)。
|
||||
|
||||
## 十、生产上线检查单
|
||||
|
||||
@@ -175,7 +175,7 @@ flowchart LR
|
||||
|
||||
- 表名、字段名使用 `snake_case`;字符集 `utf8mb4`,排序规则 `utf8mb4_0900_ai_ci`。
|
||||
- 主键策略:配置/主数据表用 `INT` 自增;高写入量表(`trace_code`、`query_log`)用 `BIGINT` 自增;在接口层将 `BigInt` 序列化为字符串,避免 JS 精度问题。
|
||||
- 公开标识:`trace_code.code`(内部唯一追溯码)与 `short_code`(公开随机短码)均唯一并建索引;短码不含业务含义、防枚举。
|
||||
- 公开标识:`trace_code.short_code` 是每件实物唯一的 12 位追溯码并建唯一索引;不含档案、批次或内部主键信息。
|
||||
- 时间字段:统一 `created_at`、`updated_at`;主数据表用 `deleted_at` 实现软删除。
|
||||
- 枚举:用 Prisma `enum` 映射 MySQL 枚举,集中在 `packages/shared` 复用。
|
||||
- 动态字段:`artwork.dynamic_fields`、节点/证书媒体等用 `JSON` 列存储。
|
||||
@@ -266,7 +266,6 @@ erDiagram
|
||||
}
|
||||
TRACE_CODE {
|
||||
bigint id PK
|
||||
string code UK
|
||||
string short_code UK
|
||||
int artwork_id FK
|
||||
int batch_id FK
|
||||
@@ -297,7 +296,6 @@ erDiagram
|
||||
bigint trace_code_id FK
|
||||
int artwork_id
|
||||
string short_code
|
||||
string code
|
||||
string archive_no
|
||||
string batch_no
|
||||
datetime queried_at
|
||||
@@ -348,7 +346,6 @@ JobStatus = PENDING | PROCESSING | SUCCESS | PARTIAL | FAILED
|
||||
```prisma
|
||||
model TraceCode {
|
||||
id BigInt @id @default(autoincrement())
|
||||
code String @unique
|
||||
shortCode String @unique @map("short_code") // 12 位纯数字
|
||||
artworkId Int @map("artwork_id")
|
||||
batchId Int @map("batch_id")
|
||||
@@ -528,7 +525,7 @@ sequenceDiagram
|
||||
|
||||
## 8. 关键技术实现要点
|
||||
|
||||
- **追溯码生成与防枚举**:`short_code` 为 12 位纯数字,由「每日递增序号 + `traceCodeSalt` + 上海时区日期」经 4 轮 Feistel 可逆置换生成(`trace_code_daily_sequence` 表,日容量 100 万),看似不连续、不含业务信息;`short_code → id` 映射写入 Redis(命中 1 小时、未命中负缓存 60 秒),配合 `@nestjs/throttler` 对 `public/trace` 每 IP 限流防枚举。完整编码 `code` 另用 18 位 nanoid。
|
||||
- **追溯码生成与防枚举**:`short_code` 是唯一业务追溯码,为 12 位纯数字,由「每日递增序号 + `traceCodeSalt` + 上海时区日期」经 4 轮 Feistel 可逆置换生成(`trace_code_daily_sequence` 表,日容量 100 万),看似不连续、不含业务信息;`short_code → id` 映射写入 Redis(命中 1 小时、未命中负缓存 60 秒),配合 `@nestjs/throttler` 对 `public/trace` 每 IP 限流防枚举。
|
||||
- **防伪激活与计数并发安全**:首次激活用**条件更新** `updateMany(where: {id, status: INACTIVE})`,以返回 `count` 判定唯一首激者,杜绝并发首扫双双判定 firstQuery、`queryCount` 丢增量;非首次走原子 `increment`。
|
||||
- **动态字段**:模板定义字段(`template_field`),作品数据存 `artwork.dynamic_fields`(JSON),用户端按模板顺序渲染、空值不展示。
|
||||
- **文件存储抽象**:定义 `StorageService` 接口(`save/getUrl/read/remove/listKeys` 等),默认本地磁盘(API 单端口托管 `/uploads`);`STORAGE_DRIVER=oss` 切 S3 兼容对象存储,业务零改动;后台支持「测试 → 迁移 → 切换」在线迁移存储。
|
||||
|
||||
Reference in New Issue
Block a user