refactor: 清理冗余代码并修复提示文案

This commit is contained in:
Nixevol
2026-07-05 08:55:32 +08:00
parent a0ccf3805b
commit 7ac43cf96b
6 changed files with 17 additions and 18 deletions
@@ -53,7 +53,7 @@ export class CertificateService {
}
async update(id: number, dto: UpdateCertificateDto) {
const cert = await this.ensureCert(id);
await this.ensureCert(id);
const updated = await this.prisma.certificate.update({
where: { id },
data: {
@@ -25,9 +25,7 @@ import { OutboundDto } from './dto/outbound.dto';
import { QueryImportRowsDto } from './dto/import-session.dto';
const ZIP_MAX_SIZE = 30 * 1024 * 1024;
const IMAGE_MAX_SIZE = 10 * 1024 * 1024;
const SESSION_TTL_DAYS = 2;
const ALLOWED_IMAGE_EXT = new Set(['.jpg', '.jpeg', '.png', '.webp']);
@Injectable()
export class OutboundService {
+13 -13
View File
@@ -8,7 +8,7 @@ import * as ExcelJS from 'exceljs';
import * as QRCode from 'qrcode';
import AdmZip from 'adm-zip';
import dayjs from 'dayjs';
import { ArtworkStatus, BatchStatus, ErrorCode, JobType, QUEUE_NAMES, TraceCodeStatus } from '@artveris/shared';
import { BatchStatus, 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';
@@ -63,7 +63,7 @@ export class TraceCodeService {
const artwork = await this.prisma.artwork.findFirst({
where: { id: dto.artworkId, deletedAt: null },
});
if (!artwork) throw new BusinessException(ErrorCode.ARTWORK_NOT_FOUND, '鑹烘湳鍝佷笉瀛樺湪', 404);
if (!artwork) throw new BusinessException(ErrorCode.ARTWORK_NOT_FOUND, '艺术品不存在', 404);
if (dto.groupId !== undefined && dto.groupId !== null) await this.ensureGroup(dto.groupId);
@@ -90,7 +90,7 @@ export class TraceCodeService {
return { batchId: batch.id, batchNo, jobId: job.id, quantity: dto.quantity };
}
// ===== 鍒嗙粍绠$悊 =====
// ===== 分组管理 =====
listGroups(artworkId?: number) {
return this.prisma.traceCodeGroup.findMany({
where: artworkId ? { traceCodes: { some: { artworkId } } } : undefined,
@@ -121,7 +121,7 @@ export class TraceCodeService {
return g;
}
// ===== 鎵归噺鎿嶄綔 =====
// ===== 批量操作 =====
async batchSetGroup(dto: BatchGroupDto) {
const ids = dto.ids.map((i) => BigInt(i));
await this.prisma.traceCode.updateMany({
@@ -134,7 +134,7 @@ export class TraceCodeService {
async batchSetStatus(dto: BatchStatusDto) {
const ids = dto.ids.map((i) => BigInt(i));
if (dto.abnormal) {
// 鏍囪寮傚父锛氱敤浜庤繍钀ヤ汉涓烘爣娉ㄧ枒浼艰澶嶅埗/鐩楃敤鐨勭爜
// 标记异常:用于运营人员标注疑似被复制/盗用的码
await this.prisma.traceCode.updateMany({
where: { id: { in: ids } },
data: { status: TraceCodeStatus.ABNORMAL },
@@ -145,7 +145,7 @@ export class TraceCodeService {
data: { status: TraceCodeStatus.DISABLED },
});
} else {
// 鍚敤锛氬凡婵€娲昏繃鐨勬仮澶嶄负 ACTIVE锛屽惁鍒欐仮澶嶄负 INACTIVE
// 启用:已激活过的恢复为 ACTIVE,否则恢复为 INACTIVE
await this.prisma.$transaction([
this.prisma.traceCode.updateMany({
where: { id: { in: ids }, firstActivatedAt: { not: null } },
@@ -184,12 +184,12 @@ export class TraceCodeService {
}
if (!options.batchId) {
throw new BusinessException(ErrorCode.BAD_REQUEST, '璇烽€夋嫨鐩爣鎵规鎴栧~鍐欐柊鎵规缂栧彿');
throw new BusinessException(ErrorCode.BAD_REQUEST, '请选择目标批次或填写新批次编号');
}
const targetBatch = await this.prisma.batch.findUnique({ where: { id: options.batchId } });
if (!targetBatch || targetBatch.artworkId !== options.artworkId) {
throw new BusinessException(ErrorCode.BAD_REQUEST, '鐩爣鎵规涓嶅瓨鍦ㄦ垨涓嶅睘浜庡綋鍓嶈壓鏈搧妗f');
throw new BusinessException(ErrorCode.BAD_REQUEST, '目标批次不存在或不属于当前艺术品档案');
}
return targetBatch;
}
@@ -213,11 +213,11 @@ export class TraceCodeService {
select: { id: true, artworkId: true, batchId: true },
});
if (codes.length !== ids.length) {
throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '閮ㄥ垎杩芥函鐮佷笉瀛樺湪', 404);
throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '部分追溯码不存在', 404);
}
const artworkIds = new Set(codes.map((c) => c.artworkId));
if (artworkIds.size !== 1) {
throw new BusinessException(ErrorCode.BAD_REQUEST, '鍙兘鎵归噺绉诲姩鍚屼竴鑹烘湳鍝佹。妗堜笅鐨勮拷婧爜');
throw new BusinessException(ErrorCode.BAD_REQUEST, '只能批量移动同一艺术品档案下的追溯码');
}
const artworkId = codes[0].artworkId;
@@ -263,7 +263,7 @@ export class TraceCodeService {
async updateOne(id: string, dto: UpdateTraceCodeDto, userId?: number) {
const traceCodeId = BigInt(id);
const code = await this.prisma.traceCode.findUnique({ where: { id: traceCodeId } });
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '杩芥函鐮佷笉瀛樺湪', 404);
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '追溯码不存在', 404);
const data: Prisma.TraceCodeUncheckedUpdateInput = {};
let targetBatchId: number | undefined;
@@ -339,7 +339,7 @@ export class TraceCodeService {
select: { id: true, batchId: true },
});
if (codes.length !== ids.length) {
throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '閮ㄥ垎杩芥函鐮佷笉瀛樺湪', 404);
throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '部分追溯码不存在', 404);
}
const batchCounts = new Map<number, number>();
for (const code of codes) {
@@ -452,7 +452,7 @@ export class TraceCodeService {
async getQrPng(id: bigint): Promise<Buffer> {
const code = await this.prisma.traceCode.findUnique({ where: { id } });
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '杩芥函鐮佷笉瀛樺湪', 404);
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '追溯码不存在', 404);
return QRCode.toBuffer(code.url || this.buildTraceUrl(code.shortCode), {
type: 'png',
width: 320,