diff --git a/backend/app/services/line_service.py b/backend/app/services/line_service.py index b7aa844..b0ef04f 100644 --- a/backend/app/services/line_service.py +++ b/backend/app/services/line_service.py @@ -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) diff --git a/frontend/src/views/EntryTracking.vue b/frontend/src/views/EntryTracking.vue index eaa1ae6..29b42e8 100644 --- a/frontend/src/views/EntryTracking.vue +++ b/frontend/src/views/EntryTracking.vue @@ -1,7 +1,7 @@