refactor: 按甲方确认重构为一款多码(档案编号标识款、批次码、按款统计)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Nixevol
2026-06-30 12:02:44 +08:00
co-authored by Cursor
parent 67c5887f8f
commit a16e6f1165
34 changed files with 445 additions and 353 deletions
+20 -13
View File
@@ -12,14 +12,14 @@ export class DashboardService {
const [
totalArtworks,
boundCodes,
totalCodes,
activatedCodes,
totalQueries,
todayQueries,
abnormalQueries,
] = await this.prisma.$transaction([
this.prisma.artwork.count({ where: { deletedAt: null } }),
this.prisma.traceCode.count({ where: { artworkId: { not: null } } }),
this.prisma.traceCode.count(),
this.prisma.traceCode.count({ where: { status: TraceCodeStatus.ACTIVE } }),
this.prisma.queryLog.count(),
this.prisma.queryLog.count({ where: { queriedAt: { gte: todayStart } } }),
@@ -30,7 +30,7 @@ export class DashboardService {
return {
totalArtworks,
boundCodes,
totalCodes,
activatedCodes,
totalQueries,
todayQueries,
@@ -58,19 +58,26 @@ export class DashboardService {
return Object.entries(buckets).map(([date, count]) => ({ date, count }));
}
// 高频查询作品榜
// 高频查询作品榜:按款聚合(该款所有码查询次数之和)
async topArtworks(limit: number) {
const codes = await this.prisma.traceCode.findMany({
where: { artworkId: { not: null }, queryCount: { gt: 0 } },
orderBy: { queryCount: 'desc' },
const grouped = await this.prisma.traceCode.groupBy({
by: ['artworkId'],
_sum: { queryCount: true },
orderBy: { _sum: { queryCount: 'desc' } },
take: limit,
include: { artwork: { select: { id: true, title: true } } },
});
return codes.map((c) => ({
artworkId: c.artworkId,
title: c.artwork?.title ?? '-',
shortCode: c.shortCode,
queryCount: c.queryCount,
const ids = grouped.map((g) => g.artworkId);
if (!ids.length) return [];
const artworks = await this.prisma.artwork.findMany({
where: { id: { in: ids } },
select: { id: true, title: true, archiveNo: true },
});
const map = new Map(artworks.map((a) => [a.id, a]));
return grouped.map((g) => ({
artworkId: g.artworkId,
title: map.get(g.artworkId)?.title ?? '-',
archiveNo: map.get(g.artworkId)?.archiveNo ?? '',
queryCount: g._sum.queryCount ?? 0,
}));
}
}