fix(planting-service+app): 合并列表补充 totalPortions,前端显示实际份数而非订单数

- getMerges 批量查来源订单 portionCount,按合并分组求和后返回 totalPortions
- 预种明细合并卡片改用 totalPortions 显示份数,fallback 才用订单数

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-04 08:58:45 -08:00
parent 1f5bb62805
commit b67dfa0f4c
2 changed files with 13 additions and 1 deletions

View File

@ -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,

View File

@ -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} 份合并',
),
],
),