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
@@ -27,6 +27,22 @@ export class AttestationService {
throw new BusinessException(ErrorCode.BAD_REQUEST, '追溯码未绑定作品,无法上链');
}
// 防重复上链:已存在「上链成功/上链中/待上链」的存证则拒绝;仅失败(FAILED)的可再次发起。
const active = await this.prisma.blockchainProof.findFirst({
where: {
traceCodeId,
status: { in: [ProofStatus.ONCHAIN, ProofStatus.CONFIRMING, ProofStatus.PENDING] },
},
orderBy: { id: 'desc' },
});
if (active) {
const msg =
active.status === ProofStatus.ONCHAIN
? '该追溯码已上链,不可重复上链'
: '该追溯码正在上链处理中,请稍候';
throw new BusinessException(ErrorCode.BAD_REQUEST, msg);
}
const summary = {
shortCode: code.shortCode,
code: code.code,