fix(production): 去掉我的生产任务列表工单详情 N+1 并避免批量任务截断 (#179)

承接 #178:mine 去掉工单详情 N+1;list-by-work-orders/pageBy 避免任务静默截断。
This commit was merged in pull request #179.
This commit is contained in:
cykj committed 2026-12-02 09:32:41 +00:00
commit 8370573edc
4 files changed
+30 -18

No files matched your search

+21 -13
View File
@@ -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,
}
)
+3 -2
View File
@@ -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
@@ -195,6 +195,10 @@ export async function fetchAllMineProductionTasks(
return all
}
/**
* @deprecated 列表路径禁止使用:会对本页工单 N+1 打详情。
* 「我的生产任务」卡片字段请用 buildWorkOrderFromTasks / buildMineTableRows。
*/
export async function enrichMineEntriesWithWorkOrders(
entries: MineWorkOrderEntry[]
): Promise<MineWorkOrderEntry[]> {
@@ -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