feat(linkage): 计划-鞍座-实绩-停机联动 + 成本管理页

后端:
- 计划录入即「准备好」,队首(最早)自动「在线」(唯一)
- 新增上卷鞍座联动引擎 line_service:移动→鞍座→(有速度/投入生产)→生产中
  →带头达2000m→生产完成并自动产生实绩、持久化运行数据
- 停机自动检测:线速度为0持续>10min 自动新增待补充停机记录,恢复后自动结束
- /plan/start=移动到鞍座, 新增 /plan/{id}/commit 投入生产, /plan/saddle/current,
  /plan/seed 批量插入(轧制力模式);后台引擎循环自动推进
- 新增成本管理:CostRecord 模型 + /cost CRUD + 9 类成本项(乳化液/盐酸/碱/电/水/蒸汽…)

前端:
- 入口跟踪重构为单个上卷鞍座工位(实时速度/带头长度进度/投入生产)+待上卷卡片+队列,
  计划列表/卡片/队列均可「移动」
- 新增成本管理页(成本项切换 + 柱+线图 + 明细表 + 时间筛选 + 新增),布局参考乳化液耗量统计

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-29 13:57:59 +08:00
parent 2144f13b88
commit 9fb3dcb785
18 changed files with 969 additions and 149 deletions

View File

@@ -9,6 +9,8 @@ from app.models.pdi import PDIRecord
from app.models.quality import QcTask, QcTaskItem, QcDefect
from app.models.energy import EnergyRecord
from app.models.inspection import EqpChecklist, EqpChecklistItem, EqpInspectionRecord, EqpInspectionDetail
from app.models.line_state import LineState
from app.models.cost import CostRecord
__all__ = [
"User",
@@ -22,4 +24,5 @@ __all__ = [
"QcTask", "QcTaskItem", "QcDefect",
"EnergyRecord",
"EqpChecklist", "EqpChecklistItem", "EqpInspectionRecord", "EqpInspectionDetail",
"LineState", "CostRecord",
]

View File

@@ -0,0 +1,20 @@
from sqlalchemy import Column, Integer, String, Float, DateTime, Text, func
from app.database import Base
class CostRecord(Base):
"""成本/消耗记录(乳化液、盐酸、电、水、蒸汽等)"""
__tablename__ = "cost_records"
id = Column(Integer, primary_key=True, index=True)
item = Column(String(30), index=True, nullable=False, comment="成本项编码")
item_name = Column(String(50), comment="成本项名称")
unit = Column(String(20), comment="计量单位")
record_date = Column(DateTime, nullable=False, index=True, comment="记录时间")
shift_a = Column(Float, default=0, comment="A班量")
shift_b = Column(Float, default=0, comment="B班量")
unit_cost = Column(Float, default=0, comment="吨耗量")
remark = Column(Text, comment="备注")
created_by = Column(String(50))
created_at = Column(DateTime, server_default=func.now())
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())

View File

@@ -0,0 +1,13 @@
from sqlalchemy import Column, Integer, Float, DateTime, func
from app.database import Base
class LineState(Base):
"""产线运行状态单例id=1用于停机自动检测。"""
__tablename__ = "line_state"
id = Column(Integer, primary_key=True, index=True)
speed = Column(Float, default=0, comment="当前线速度 m/min")
zero_since = Column(DateTime, comment="速度为0的起始时间")
open_downtime_id = Column(Integer, comment="当前未结束的自动停机记录id")
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())

View File

@@ -35,6 +35,14 @@ class ProductionPlan(Base):
incoming_od = Column(Float, comment="来料外径 mm")
split_weights = Column(JSON, comment="分卷重量 [t,...]")
# 上卷鞍座 / 生产联动
on_saddle = Column(Integer, default=0, comment="是否在上卷鞍座 0/1")
saddle_at = Column(DateTime, comment="移动到鞍座时间")
run_started_at = Column(DateTime, comment="投入生产(有速度)时间")
run_speed = Column(Float, default=0, comment="当前线速度 m/min")
run_length_m = Column(Float, default=0, comment="带头已生产长度 m")
produced_at = Column(DateTime, comment="生产完成时间")
# 兼容历史字段
shift = Column(String(10), comment="班次")
plan_quantity = Column(Integer, default=0)