fix(linkage): 单卷在产时不再保留在线队首,避免生产中仍显示在线
- ensure_online:当有卷在上卷鞍座/生产中时,所有在线计划回退为准备好; 当前卷生产完成后再把最早准备好的置为唯一在线 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user