fix: 统一追溯码并修正天河链存证跳转
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user