From 1a6deea4bb1fe3757df6e0117db968c3a981afdd Mon Sep 17 00:00:00 2001 From: wangyu <823267011@qq.com> Date: Mon, 29 Jun 2026 15:06:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(linkage):=20=E5=8D=95=E5=8D=B7=E5=9C=A8?= =?UTF-8?q?=E4=BA=A7=E6=97=B6=E4=B8=8D=E5=86=8D=E4=BF=9D=E7=95=99=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E9=98=9F=E9=A6=96=EF=BC=8C=E9=81=BF=E5=85=8D=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E4=B8=AD=E4=BB=8D=E6=98=BE=E7=A4=BA=E5=9C=A8=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ensure_online:当有卷在上卷鞍座/生产中时,所有在线计划回退为准备好; 当前卷生产完成后再把最早准备好的置为唯一在线 Co-Authored-By: Claude Opus 4.8 --- backend/app/services/line_service.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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"