feat(api): category-based family grouping, tree family info and custom goods family attribution

This commit is contained in:
yeuimu
2026-08-28 12:43:58 +08:00
parent d63f1a6f35
commit c8531bfe08
10 changed files with 190 additions and 36 deletions
@@ -41,6 +41,10 @@ export interface OriginGoodsTreeNode {
variantCount: number;
sizeRowCount: number;
packageRowCount: number;
familyId: string | null;
familyName: string | null;
familyCode: string | null;
familyStale: boolean | null;
}
/** A category node in the hierarchical tree, with origin goods as leaves. */
@@ -129,7 +133,11 @@ export class OriginGoodsService {
this.prisma.originGood.findMany({
where: { delisted: false, source: 'SDS' },
orderBy: { goodName: 'asc' },
include: { detail: true, _count: { select: { variants: true } } },
include: {
detail: true,
_count: { select: { variants: true } },
family: { select: { id: true, familyName: true, familyCode: true, stale: true } },
},
}),
this.prisma.good.groupBy({
by: ['originGoodId'],
@@ -271,6 +279,10 @@ export class OriginGoodsService {
variantCount: og._count.variants,
sizeRowCount: this.jsonRows(og.detail?.sizeChart),
packageRowCount: this.jsonRows(og.detail?.packageSpecs),
familyId: og.family?.id.toString() ?? null,
familyName: og.family?.familyName ?? null,
familyCode: og.family?.familyCode ?? null,
familyStale: og.family?.stale ?? null,
}));
const childTotal = childNodes.reduce((s, n) => s + n.totalCount, 0);
@@ -322,6 +334,10 @@ export class OriginGoodsService {
variantCount: og._count.variants,
sizeRowCount: this.jsonRows(og.detail?.sizeChart),
packageRowCount: this.jsonRows(og.detail?.packageSpecs),
familyId: og.family?.id.toString() ?? null,
familyName: og.family?.familyName ?? null,
familyCode: og.family?.familyCode ?? null,
familyStale: og.family?.stale ?? null,
})),
});
}