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
@@ -33,6 +33,10 @@ export class OutboundService {
async updateSingle(traceCodeId: bigint, dto: OutboundDto) {
const code = await this.prisma.traceCode.findUnique({ where: { id: traceCodeId } });
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '追溯码不存在', 404);
// 一物一码只能出库一次:已登记出库时间的不可重复登记
if (code.outTime) {
throw new BusinessException(ErrorCode.BAD_REQUEST, '该追溯码已登记出库,不可重复出库');
}
const imageKeys = dto.outImageKeys ?? (dto.outImageKey ? [dto.outImageKey] : []);
const data: Prisma.TraceCodeUpdateInput = {};
if ('outTime' in dto) data.outTime = dto.outTime ? new Date(dto.outTime) : null;