diff --git a/backend/app/services/line_service.py b/backend/app/services/line_service.py index b0ef04f..e9ad8e0 100644 --- a/backend/app/services/line_service.py +++ b/backend/app/services/line_service.py @@ -66,13 +66,27 @@ async def _saddle_plan(db: AsyncSession): async def ensure_online(db: AsyncSession): - """保证恰好一条 online(队首,最早录入的 ready)。鞍座上的计划不参与队列。""" + """单卷在产:有卷在上卷鞍座/生产中时不保留在线队首;否则把最早 ready 置为唯一在线。""" res = await db.execute( select(ProductionPlan).where(ProductionPlan.status == "online", ProductionPlan.on_saddle != 1) ) online = list(res.scalars()) + + # 是否已有在产/在鞍座的卷 + res2 = await db.execute( + select(ProductionPlan).where( + (ProductionPlan.status == "producing") | (ProductionPlan.on_saddle == 1) + ) + ) + active = res2.scalars().first() is not None + + if active: + # 正在生产时,不再保留「在线」队首,全部回退 ready,等当前卷完成 + for p in online: + p.status = "ready" + return + if len(online) > 1: - # 仅保留最早的一条为 online,其余回退 ready online.sort(key=lambda p: (p.plan_date or datetime.max, p.id)) for p in online[1:]: p.status = "ready"