fix: 修复出库追溯码默认加载

This commit is contained in:
Nixevol
2026-07-03 04:35:05 +08:00
parent 9eda1b722a
commit bc6a4e9cc2
5 changed files with 109 additions and 30 deletions
+3 -3
View File
@@ -6,12 +6,12 @@ export class OutboundDto {
@ApiPropertyOptional({ description: '出库时间' })
@IsOptional()
@IsDateString()
outTime?: string;
outTime?: string | null;
@ApiPropertyOptional({ description: '出库实况图存储 key' })
@IsOptional()
@IsString()
outImageKey?: string;
outImageKey?: string | null;
@ApiPropertyOptional({ description: '上链哈希值(填写则记录上链结果)' })
@IsOptional()
@@ -35,5 +35,5 @@ export class OutboundDto {
@IsOptional()
@IsString()
@MaxLength(255)
remark?: string;
remark?: string | null;
}
+6 -5
View File
@@ -4,6 +4,7 @@ import { Queue } from 'bullmq';
import { Response } from 'express';
import { createHash } from 'crypto';
import * as ExcelJS from 'exceljs';
import { Prisma } from '@prisma/client';
import {
ErrorCode,
JobType,
@@ -35,13 +36,13 @@ 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);
const data: Prisma.TraceCodeUpdateInput = {};
if ('outTime' in dto) data.outTime = dto.outTime ? new Date(dto.outTime) : null;
if ('outImageKey' in dto) data.outImage = dto.outImageKey || null;
if ('remark' in dto) data.remark = dto.remark || null;
const updated = await this.prisma.traceCode.update({
where: { id: traceCodeId },
data: {
outTime: dto.outTime ? new Date(dto.outTime) : undefined,
outImage: dto.outImageKey,
remark: dto.remark,
},
data,
});
// 录入了上链哈希则记录一条已上链存证(手工登记,不触发 Mock 链)
if (dto.txHash) {
+20 -1
View File
@@ -9,6 +9,7 @@ import * as QRCode from 'qrcode';
import dayjs from 'dayjs';
import { ArtworkStatus, ErrorCode, JobType, QUEUE_NAMES, TraceCodeStatus } from '@artveris/shared';
import { PrismaService } from '../prisma/prisma.service';
import { StorageService } from '../storage/storage.service';
import { BusinessException } from '../common/exceptions/business.exception';
import { buildPage } from '../common/utils/pagination.util';
import { JobsService } from '../jobs/jobs.service';
@@ -28,6 +29,7 @@ export class TraceCodeService {
private readonly prisma: PrismaService,
private readonly jobs: JobsService,
private readonly config: ConfigService,
private readonly storage: StorageService,
@InjectQueue(QUEUE_NAMES.GEN_CODE) private readonly genQueue: Queue,
) {}
@@ -173,6 +175,11 @@ export class TraceCodeService {
artwork: { select: { id: true, title: true, archiveNo: true } },
batch: { select: { id: true, batchNo: true } },
group: { select: { id: true, name: true } },
proofs: {
where: { status: 'ONCHAIN' },
orderBy: [{ onchainAt: 'desc' }, { id: 'desc' }],
take: 1,
},
},
orderBy: { id: 'desc' },
skip: query.skip,
@@ -180,7 +187,19 @@ export class TraceCodeService {
}),
this.prisma.traceCode.count({ where }),
]);
return buildPage(list, total, query.page, query.pageSize);
return buildPage(
list.map((code) => {
const { proofs, ...rest } = code;
return {
...rest,
outImageUrl: code.outImage ? this.storage.getUrl(code.outImage) : null,
latestProof: proofs[0] ?? null,
};
}),
total,
query.page,
query.pageSize,
);
}
async getQrPng(id: bigint): Promise<Buffer> {