diff --git a/backend/app/api/production.py b/backend/app/api/production.py index 65733721..25238839 100644 --- a/backend/app/api/production.py +++ b/backend/app/api/production.py @@ -2340,24 +2340,32 @@ async def list_production_tasks_by_work_orders( return success_response( {"list": [], "total": 0, "page": 1, "pageSize": body.page_size, "totalPages": 0} ) + # 当前页工单卡片需要这些工单下的全部任务;避免单页 pageSize 上限静默截断 effective_page_size = min(max(body.page_size, len(wo_ids) * 100), 500) - items, total = production_task_svc.list_production_tasks( - db, - tenant_no=tenant_no, - page=1, - page_size=effective_page_size, - work_order_ids=wo_ids, - user_info=user, - include_step_summary=body.include_step_summary, - ) - tp = production_task_svc.total_pages(total, effective_page_size) + all_items = [] + total = 0 + page = 1 + while page <= 20: + items, total = production_task_svc.list_production_tasks( + db, + tenant_no=tenant_no, + page=page, + page_size=effective_page_size, + work_order_ids=wo_ids, + user_info=user, + include_step_summary=body.include_step_summary, + ) + all_items.extend(items or []) + if not items or len(all_items) >= int(total or 0): + break + page += 1 return success_response( { - "list": items, + "list": all_items, "total": total, "page": 1, - "pageSize": effective_page_size, - "totalPages": tp, + "pageSize": len(all_items), + "totalPages": 1 if all_items else 0, } ) diff --git a/backend/app/crud/production_task.py b/backend/app/crud/production_task.py index e059fd1b..8408e8a5 100644 --- a/backend/app/crud/production_task.py +++ b/backend/app/crud/production_task.py @@ -1406,12 +1406,13 @@ def list_production_tasks( page_wo_ids = [wo.id for wo in page_work_orders if getattr(wo, "id", None)] if not page_wo_ids: return [], int(total) - task_page_size = min(max(page_size * 100, len(page_wo_ids) * 20), 500) + # 当页工单下全部匹配任务(工单页通常 ≤100);避免 500 上限静默截断卡片子任务 + task_fetch_cap = min(max(len(page_wo_ids) * 100, page_size * 100), 5000) rows = ( _filtered() .filter(BizProductionTask.work_order_id.in_(page_wo_ids)) .order_by(BizProductionTask.create_time.desc()) - .limit(task_page_size) + .limit(task_fetch_cap) .all() ) # 按工单页序重排;同工单内保持 create_time DESC diff --git a/web-admin/src/utils/production-mine-task-groups.ts b/web-admin/src/utils/production-mine-task-groups.ts index 02fd063d..3cf044e6 100644 --- a/web-admin/src/utils/production-mine-task-groups.ts +++ b/web-admin/src/utils/production-mine-task-groups.ts @@ -195,6 +195,10 @@ export async function fetchAllMineProductionTasks( return all } +/** + * @deprecated 列表路径禁止使用:会对本页工单 N+1 打详情。 + * 「我的生产任务」卡片字段请用 buildWorkOrderFromTasks / buildMineTableRows。 + */ export async function enrichMineEntriesWithWorkOrders( entries: MineWorkOrderEntry[] ): Promise { diff --git a/web-admin/src/views/production/production-work-order/composables/useProductionWorkOrderTabPage.ts b/web-admin/src/views/production/production-work-order/composables/useProductionWorkOrderTabPage.ts index 853feeef..66f64aeb 100644 --- a/web-admin/src/views/production/production-work-order/composables/useProductionWorkOrderTabPage.ts +++ b/web-admin/src/views/production/production-work-order/composables/useProductionWorkOrderTabPage.ts @@ -10,7 +10,6 @@ import { import { fetchMineProductionTasksByWorkOrderPage, groupMineTasksByWorkOrder, - enrichMineEntriesWithWorkOrders, buildMineTableRows } from '@/utils/production-mine-task-groups' import { @@ -131,8 +130,8 @@ export function useProductionWorkOrderTabPage( excludeVoidProtocol: resolveExcludeVoidProtocolParam(), ...buildPlannedStartTimeParams() }) - let entries = groupMineTasksByWorkOrder(pageRes.list || []) - entries = await enrichMineEntriesWithWorkOrders(entries) + // 与质检 mine 一致:工单卡片字段由任务聚合摘要构建,避免对本页工单 N+1 打详情 + const entries = groupMineTasksByWorkOrder(pageRes.list || []) const tableModel = buildMineTableRows(entries) tableData.value = tableModel.rows presetTasksByWorkOrderId.value = tableModel.presetTasksByWorkOrderId