fix(entry): 恢复入口跟踪全部设备工位,修复鞍座联动状态竞争
- 还原入口跟踪原有设备网格(2行):上卷小车/称重位/地辊/倒卷小车,仅上卷鞍座保留一个 - 移动可在所有入口设备间进行,仅「上卷鞍座」进入生产环节 - 修复 ensure_online 误将鞍座暂存计划回退导致卡死:移动到鞍座直接置生产中, ensure_online 排除 on_saddle 计划 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -66,8 +66,10 @@ async def _saddle_plan(db: AsyncSession):
|
||||
|
||||
|
||||
async def ensure_online(db: AsyncSession):
|
||||
"""保证恰好一条 online(队首,最早录入的 ready)。"""
|
||||
res = await db.execute(select(ProductionPlan).where(ProductionPlan.status == "online"))
|
||||
"""保证恰好一条 online(队首,最早录入的 ready)。鞍座上的计划不参与队列。"""
|
||||
res = await db.execute(
|
||||
select(ProductionPlan).where(ProductionPlan.status == "online", ProductionPlan.on_saddle != 1)
|
||||
)
|
||||
online = list(res.scalars())
|
||||
if len(online) > 1:
|
||||
# 仅保留最早的一条为 online,其余回退 ready
|
||||
@@ -88,25 +90,27 @@ async def ensure_online(db: AsyncSession):
|
||||
|
||||
|
||||
async def move_to_saddle(db: AsyncSession, plan: ProductionPlan):
|
||||
"""把在线计划移动到上卷鞍座(staged,等待速度/投入生产)。"""
|
||||
"""把计划移动到上卷鞍座:上卷即获得速度 → 生产中。"""
|
||||
occupied = await _saddle_plan(db)
|
||||
if occupied and occupied.id != plan.id:
|
||||
raise ValueError("上卷鞍座已被占用,请等待当前钢卷生产完成")
|
||||
now = datetime.now()
|
||||
plan.on_saddle = 1
|
||||
plan.position = SADDLE_NAME
|
||||
plan.saddle_at = datetime.now()
|
||||
plan.run_started_at = None
|
||||
plan.run_speed = 0
|
||||
plan.run_length_m = 0
|
||||
if plan.status not in ("producing", "produced"):
|
||||
plan.status = "online"
|
||||
plan.saddle_at = now
|
||||
if plan.status != "produced":
|
||||
plan.run_started_at = now
|
||||
plan.run_speed = SIM_SPEED_M_MIN
|
||||
plan.run_length_m = 0
|
||||
plan.status = "producing"
|
||||
await ensure_online(db)
|
||||
|
||||
|
||||
async def commit_plan(db: AsyncSession, plan: ProductionPlan):
|
||||
"""投入生产:鞍座计划有速度 → 生产中。"""
|
||||
"""投入生产(兜底):鞍座计划置为生产中。"""
|
||||
if plan.on_saddle != 1:
|
||||
await move_to_saddle(db, plan)
|
||||
return
|
||||
if plan.run_started_at is None:
|
||||
plan.run_started_at = datetime.now()
|
||||
plan.run_speed = SIM_SPEED_M_MIN
|
||||
@@ -166,17 +170,11 @@ async def _produce(db: AsyncSession, plan: ProductionPlan):
|
||||
|
||||
|
||||
async def advance_saddle(db: AsyncSession):
|
||||
"""推进鞍座计划:staged 自动获得速度 → 生产中;累计长度到 2000m → 完成。"""
|
||||
"""推进鞍座计划:累计带头长度到 2000m → 生产完成。"""
|
||||
plan = await _saddle_plan(db)
|
||||
if not plan:
|
||||
return
|
||||
now = datetime.now()
|
||||
# staged(在线且在鞍座)自动获得速度,模拟 PLC 速度信号
|
||||
if plan.status == "online" and plan.run_started_at is None:
|
||||
plan.run_started_at = now
|
||||
plan.run_speed = SIM_SPEED_M_MIN
|
||||
plan.status = "producing"
|
||||
await ensure_online(db)
|
||||
if plan.status == "producing" and plan.run_started_at:
|
||||
elapsed = (now - plan.run_started_at).total_seconds()
|
||||
plan.run_length_m = min(TARGET_LENGTH_M, (plan.run_speed or 0) / 60.0 * elapsed)
|
||||
|
||||
Reference in New Issue
Block a user