diff --git a/backend/services/planting-service/src/pre-planting/application/services/pre-planting-application.service.ts b/backend/services/planting-service/src/pre-planting/application/services/pre-planting-application.service.ts index 46c7fbc5..22f94a89 100644 --- a/backend/services/planting-service/src/pre-planting/application/services/pre-planting-application.service.ts +++ b/backend/services/planting-service/src/pre-planting/application/services/pre-planting-application.service.ts @@ -368,6 +368,7 @@ export class PrePlantingApplicationService { async getMerges(userId: bigint): Promise<{ mergeNo: string; sourceOrderNos: string[]; + totalPortions: number; treeCount: number; contractStatus: string; contractSignedAt: Date | null; @@ -376,9 +377,20 @@ export class PrePlantingApplicationService { }[]> { return this.prisma.$transaction(async (tx) => { const merges = await this.mergeRepo.findByUserId(tx, userId); + if (merges.length === 0) return []; + + // 批量查询所有合并的来源订单份数 + const allOrderNos = merges.flatMap((m) => m.sourceOrderNos); + const orderRecords = await tx.prePlantingOrder.findMany({ + where: { orderNo: { in: allOrderNos } }, + select: { orderNo: true, portionCount: true }, + }); + const portionByOrderNo = new Map(orderRecords.map((o) => [o.orderNo, o.portionCount])); + return merges.map((m) => ({ mergeNo: m.mergeNo, sourceOrderNos: m.sourceOrderNos, + totalPortions: m.sourceOrderNos.reduce((sum, no) => sum + (portionByOrderNo.get(no) ?? 1), 0), treeCount: m.treeCount, contractStatus: m.contractStatus, contractSignedAt: m.contractSignedAt, diff --git a/frontend/mobile-app/lib/features/pre_planting/presentation/pages/pre_planting_position_page.dart b/frontend/mobile-app/lib/features/pre_planting/presentation/pages/pre_planting_position_page.dart index de126c9a..10a2a326 100644 --- a/frontend/mobile-app/lib/features/pre_planting/presentation/pages/pre_planting_position_page.dart +++ b/frontend/mobile-app/lib/features/pre_planting/presentation/pages/pre_planting_position_page.dart @@ -669,7 +669,7 @@ class _PrePlantingPositionPageState const SizedBox(width: 16), _buildInfoChip( Icons.layers_outlined, - '${merge.sourceOrderNos.length} 份合并', + '${merge.totalPortions > 0 ? merge.totalPortions : merge.sourceOrderNos.length} 份合并', ), ], ),