feat: 强化出库上链一致性(确认中即已上链/出库时间必填/上链须先出库)

This commit is contained in:
Nixevol
2026-07-10 17:53:57 +08:00
parent f364d2d194
commit e1e1cf7308
6 changed files with 24 additions and 5 deletions
+10 -3
View File
@@ -326,7 +326,9 @@ function rowIsOutbound(row: any) {
return Boolean(row.outTime || getOutImages(row).length);
}
function rowIsOnchain(row: any) {
return Boolean(row?.latestProof);
// 已提交上链即视为已上链:ONCHAIN(已确认)/CONFIRMING(确认中)/PENDING(待处理) 均不允许重复上链,仅 FAILED 可重试
const s = row?.latestAnyProof?.status;
return s === 'ONCHAIN' || s === 'CONFIRMING' || s === 'PENDING';
}
function outboundMenuLabel(row: any) {
if (rowIsOnchain(row)) return t('pages.traceCode.onchainInfo');
@@ -336,7 +338,7 @@ function outboundMenuLabel(row: any) {
const targetOutbound = computed(() => rowIsOutbound(outboundTarget.value));
const targetOnchain = computed(() => rowIsOnchain(outboundTarget.value));
const outboundReadonly = computed(() => targetOutbound.value || targetOnchain.value);
const targetProof = computed<any>(() => outboundTarget.value?.latestProof ?? null);
const targetProof = computed<any>(() => outboundTarget.value?.latestProof ?? outboundTarget.value?.latestAnyProof ?? null);
const outboundModalTitle = computed(() => outboundMenuLabel(outboundTarget.value));
const columns = computed<DataTableColumns<any>>(() => {
@@ -819,7 +821,8 @@ function getOutImages(row: any) {
function openOutboundModal(row: any) {
outboundTarget.value = row;
outboundForm.outTime = formatDateTime(row.outTime);
// 出库时间必填:未出库时默认此刻;已出库时回显既有时间(只读)
outboundForm.outTime = row.outTime ? formatDateTime(row.outTime) : dayjs().format('YYYY-MM-DD HH:mm');
outboundForm.remark = row.remark || '';
outImages.value = getOutImages(row);
outboundModal.value = true;
@@ -827,6 +830,10 @@ function openOutboundModal(row: any) {
async function saveOutbound(triggerOnchain: boolean) {
if (!outboundTarget.value) return;
if (!outboundReadonly.value && !outboundForm.outTime) {
message.warning(t('pages.outbound.outTimeRequired'));
return;
}
if (triggerOnchain) {
outboundTriggering.value = true;
} else {
+2 -1
View File
@@ -466,7 +466,8 @@
"FAILED": "Failed",
"EXPIRED": "Expired"
},
"onchainAutoTip": "On-chain hash, attestation link, and on-chain time are written automatically from the configured blockchain API response."
"onchainAutoTip": "On-chain hash, attestation link, and on-chain time are written automatically from the configured blockchain API response.",
"outTimeRequired": "Outbound time is required"
},
"blockchain": {
"title": "Blockchain Attestation",
+2 -1
View File
@@ -466,7 +466,8 @@
"FAILED": "失败",
"EXPIRED": "已过期"
},
"onchainAutoTip": "链上哈希、存证链接、上链时间由当前配置的区块链接口返回后自动写入。"
"onchainAutoTip": "链上哈希、存证链接、上链时间由当前配置的区块链接口返回后自动写入。",
"outTimeRequired": "出库时间不能为空"
},
"blockchain": {
"title": "区块链存证",
@@ -5,6 +5,7 @@ import { ErrorCode, ProofStatus, QUEUE_NAMES } from '@artveris/shared';
import { PrismaService } from '../prisma/prisma.service';
import { BusinessException } from '../common/exceptions/business.exception';
import { StorageService } from '../storage/storage.service';
import { isOutbound } from '../outbound/outbound.util';
import { BlockchainService } from './blockchain.service';
@Injectable()
@@ -36,6 +37,10 @@ export class AttestationService {
if (!code.artworkId || !code.artwork) {
throw new BusinessException(ErrorCode.BAD_REQUEST, '追溯码未绑定作品,无法上链');
}
// 上链代表已登记出库:未出库不允许上链(杜绝「已上链未登记」的不一致状态)
if (!isOutbound(code)) {
throw new BusinessException(ErrorCode.BAD_REQUEST, '该追溯码尚未登记出库,请先登记出库再上链');
}
// 防重复上链:已存在「上链成功/上链中/待上链」的存证则拒绝;仅失败(FAILED)的可再次发起。
const active = await this.prisma.blockchainProof.findFirst({
@@ -38,6 +38,10 @@ export class OutboundService {
if (isOutbound(code)) {
throw new BusinessException(ErrorCode.BAD_REQUEST, '该追溯码已登记出库,不可重复出库');
}
// 出库时间必填:出库登记必须有出库时间
if (!dto.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;