fix: 追溯码出库与上链防重复(一物一码只能出库/上链一次)

- 出库:单件登记 + 导入预览 + 导入提交 三处校验 outTime 已存在则拒绝重复出库
- 上链:trigger 存在 ONCHAIN/CONFIRMING/PENDING 存证即拒绝重复上链;FAILED 仍可 retry
- 实测重复出库/重复上链均返回 400 拒绝
This commit is contained in:
Nixevol
2026-07-10 12:06:57 +08:00
parent 223f8912dd
commit 4530a83117
5 changed files with 25 additions and 0 deletions
@@ -42,6 +42,8 @@ export class ImportProcessor extends WorkerHost {
try {
const code = await this.prisma.traceCode.findUnique({ where: { shortCode: row.shortCode || '' } });
if (!code) throw new Error('追溯码不存在');
// 预览到提交之间可能已被出库:再次校验,避免重复出库
if (code.outTime) throw new Error('该追溯码已登记出库,不可重复出库');
const imageItems = jsonArray<{ key: string; url?: string; name?: string; type?: string }>(row.outImageKeys);
await this.prisma.traceCode.update({
where: { id: code.id },