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:
parent
1f5bb62805
commit
b67dfa0f4c
|
|
@ -368,6 +368,7 @@ export class PrePlantingApplicationService {
|
||||||
async getMerges(userId: bigint): Promise<{
|
async getMerges(userId: bigint): Promise<{
|
||||||
mergeNo: string;
|
mergeNo: string;
|
||||||
sourceOrderNos: string[];
|
sourceOrderNos: string[];
|
||||||
|
totalPortions: number;
|
||||||
treeCount: number;
|
treeCount: number;
|
||||||
contractStatus: string;
|
contractStatus: string;
|
||||||
contractSignedAt: Date | null;
|
contractSignedAt: Date | null;
|
||||||
|
|
@ -376,9 +377,20 @@ export class PrePlantingApplicationService {
|
||||||
}[]> {
|
}[]> {
|
||||||
return this.prisma.$transaction(async (tx) => {
|
return this.prisma.$transaction(async (tx) => {
|
||||||
const merges = await this.mergeRepo.findByUserId(tx, userId);
|
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) => ({
|
return merges.map((m) => ({
|
||||||
mergeNo: m.mergeNo,
|
mergeNo: m.mergeNo,
|
||||||
sourceOrderNos: m.sourceOrderNos,
|
sourceOrderNos: m.sourceOrderNos,
|
||||||
|
totalPortions: m.sourceOrderNos.reduce((sum, no) => sum + (portionByOrderNo.get(no) ?? 1), 0),
|
||||||
treeCount: m.treeCount,
|
treeCount: m.treeCount,
|
||||||
contractStatus: m.contractStatus,
|
contractStatus: m.contractStatus,
|
||||||
contractSignedAt: m.contractSignedAt,
|
contractSignedAt: m.contractSignedAt,
|
||||||
|
|
|
||||||
|
|
@ -669,7 +669,7 @@ class _PrePlantingPositionPageState
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
_buildInfoChip(
|
_buildInfoChip(
|
||||||
Icons.layers_outlined,
|
Icons.layers_outlined,
|
||||||
'${merge.sourceOrderNos.length} 份合并',
|
'${merge.totalPortions > 0 ? merge.totalPortions : merge.sourceOrderNos.length} 份合并',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue