feat: 接入天河链存证接口

This commit is contained in:
Nixevol
2026-07-06 18:25:55 +08:00
parent 3efc1ecd88
commit 07114b759d
26 changed files with 412 additions and 236 deletions
+1 -25
View File
@@ -1,9 +1,8 @@
import { Processor, WorkerHost } from '@nestjs/bullmq';
import { Logger } from '@nestjs/common';
import { Job } from 'bullmq';
import { createHash } from 'crypto';
import * as ExcelJS from 'exceljs';
import { JobStatus, ProofStatus, QUEUE_NAMES } from '@artveris/shared';
import { JobStatus, QUEUE_NAMES } from '@artveris/shared';
import { PrismaService } from '../prisma/prisma.service';
import { StorageService } from '../storage/storage.service';
import { JobsService } from '../jobs/jobs.service';
@@ -55,27 +54,6 @@ export class ImportProcessor extends WorkerHost {
remark: row.remark || undefined,
},
});
if (row.txHash) {
const dup = await this.prisma.blockchainProof.findFirst({
where: { traceCodeId: code.id, txHash: row.txHash },
});
if (!dup) {
const dataHash = '0x' + createHash('sha256').update(`${code.code}:${row.txHash}`).digest('hex');
await this.prisma.blockchainProof.create({
data: {
traceCodeId: code.id,
dataHash,
txHash: row.txHash,
blockHeight: row.blockHeight ?? null,
chainName: '手工登记',
onchainAt: row.onchainAt ?? new Date(),
status: ProofStatus.ONCHAIN,
rawResponse: { source: 'import' },
},
});
}
}
await this.prisma.outboundImportRow.update({ where: { id: row.id }, data: { status: 'IMPORTED', reason: null } });
success++;
} catch (e) {
@@ -116,7 +94,6 @@ export class ImportProcessor extends WorkerHost {
{ header: '批次编号', key: 'batchNo', width: 22 },
{ header: '出库时间', key: 'outTime', width: 22 },
{ header: '图片数量', key: 'imageCount', width: 10 },
{ header: '上链哈希', key: 'txHash', width: 30 },
{ header: '处理状态', key: 'status', width: 14 },
{ header: '原因', key: 'reason', width: 40 },
];
@@ -128,7 +105,6 @@ export class ImportProcessor extends WorkerHost {
batchNo: row.batchNo || '',
outTime: row.outTime?.toISOString() || '',
imageCount: jsonArray(row.outImageKeys).length,
txHash: row.txHash || '',
status: row.status,
reason: row.reason || '',
});