fix: 优化追溯码管理入口和筛选

This commit is contained in:
Nixevol
2026-07-05 03:59:35 +08:00
parent 6a5cebf07b
commit eecc4ceb6e
9 changed files with 58 additions and 26 deletions
@@ -50,8 +50,9 @@ export class TraceCodeController {
@Get('trace-code-groups')
@ApiOperation({ summary: '分组列表' })
groups() {
return this.service.listGroups();
groups(@Query('artworkId') artworkId?: string) {
const id = artworkId ? Number(artworkId) : undefined;
return this.service.listGroups(id && Number.isFinite(id) ? id : undefined);
}
@Post('trace-code-groups')
@@ -65,6 +65,8 @@ export class TraceCodeService {
});
if (!artwork) throw new BusinessException(ErrorCode.ARTWORK_NOT_FOUND, '鑹烘湳鍝佷笉瀛樺湪', 404);
if (dto.groupId !== undefined && dto.groupId !== null) await this.ensureGroup(dto.groupId);
const batchNo = dto.batchNo || `B${dayjs().format('YYYYMMDDHHmmss')}`;
const exists = await this.prisma.batch.findUnique({ where: { batchNo } });
if (exists) {
@@ -89,8 +91,9 @@ export class TraceCodeService {
}
// ===== 鍒嗙粍绠$悊 =====
listGroups() {
listGroups(artworkId?: number) {
return this.prisma.traceCodeGroup.findMany({
where: artworkId ? { traceCodes: { some: { artworkId } } } : undefined,
orderBy: { id: 'desc' },
include: { _count: { select: { traceCodes: true } } },
});
@@ -394,8 +397,13 @@ export class TraceCodeService {
OR: [
{ shortCode: { contains: query.keyword } },
{ code: { contains: query.keyword } },
{ url: { contains: query.keyword } },
{ remark: { contains: query.keyword } },
{ artwork: { archiveNo: { contains: query.keyword } } },
{ artwork: { title: { contains: query.keyword } } },
{ artwork: { artist: { contains: query.keyword } } },
{ batch: { batchNo: { contains: query.keyword } } },
{ group: { name: { contains: query.keyword } } },
],
});
}