feat(plan): 计划详细面板 + 来料重量/外径/分卷重量 + 在线/生产中状态机 + 入口移动 + 上次模板回填
- backend: plan 增加 incoming_weight/incoming_od/split_weights(JSON) 字段及迁移
- backend: GET /plan/last-template 返回最近一条计划的工艺字段用于新增回填(多端共享)
- backend: PATCH /plan/{id}/start 设为 producing,强制单卷在产(其他 producing 回退 online)
- backend: 生成实绩时按卷号自动把对应计划状态置为 produced
- frontend: 新增计划默认状态 online;新增时调用 last-template 自动回填
- frontend: Plan 表格行点击展开 计划详细 面板(按截图布局)
- frontend: Plan 行操作增加「移动」(ready/online → producing)
- frontend: 物料跟踪页加 在线计划队列 + 入口移动按钮,显示当前生产中卷
- frontend: 计划弹窗新增 轧制模式/来料重量/来料外径/1-6#分卷重量
This commit is contained in:
@@ -6,10 +6,28 @@ from datetime import datetime
|
||||
|
||||
from app.database import get_db
|
||||
from app.models.production import ProductionRecord
|
||||
from app.models.plan import ProductionPlan
|
||||
from app.schemas.production import ProductionRecordCreate, ProductionRecordUpdate, ProductionRecordOut
|
||||
from app.schemas.common import Response, PageResponse
|
||||
from app.services.auth_service import get_current_user
|
||||
|
||||
|
||||
async def _mark_plan_produced(db: AsyncSession, record: ProductionRecord):
|
||||
"""根据实绩记录的卷号自动把对应计划标记为 produced。"""
|
||||
candidates = []
|
||||
for v in (getattr(record, "hot_coil_no", None), record.coil_no, getattr(record, "sub_coil_no", None)):
|
||||
if v and v not in candidates:
|
||||
candidates.append(v)
|
||||
if not candidates:
|
||||
return
|
||||
q = select(ProductionPlan).where(
|
||||
(ProductionPlan.cold_coil_no.in_(candidates)) | (ProductionPlan.hot_coil_no.in_(candidates))
|
||||
)
|
||||
res = await db.execute(q)
|
||||
for plan in res.scalars():
|
||||
if plan.status != "produced":
|
||||
plan.status = "produced"
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -60,6 +78,8 @@ async def create_record(
|
||||
record = ProductionRecord(**body.model_dump())
|
||||
db.add(record)
|
||||
await db.flush()
|
||||
await _mark_plan_produced(db, record)
|
||||
await db.flush()
|
||||
return Response.ok(ProductionRecordOut.model_validate(record))
|
||||
|
||||
|
||||
@@ -86,4 +106,6 @@ async def update_record(
|
||||
for k, v in body.model_dump(exclude_none=True).items():
|
||||
setattr(record, k, v)
|
||||
await db.flush()
|
||||
await _mark_plan_produced(db, record)
|
||||
await db.flush()
|
||||
return Response.ok(ProductionRecordOut.model_validate(record))
|
||||
|
||||
Reference in New Issue
Block a user