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,7 +6,7 @@ from datetime import datetime
|
||||
|
||||
from app.database import get_db
|
||||
from app.models.plan import ProductionPlan
|
||||
from app.schemas.plan import PlanCreate, PlanUpdate, PlanOut
|
||||
from app.schemas.plan import PlanCreate, PlanUpdate, PlanOut, PlanTemplate
|
||||
from app.schemas.common import Response, PageResponse
|
||||
from app.services.auth_service import get_current_user
|
||||
|
||||
@@ -22,6 +22,16 @@ def _parse_dt(s):
|
||||
return None
|
||||
|
||||
|
||||
TEMPLATE_FIELDS = (
|
||||
"steel_grade", "incoming_thickness", "product_thickness",
|
||||
"deviation_upper", "deviation_lower",
|
||||
"incoming_width", "product_width",
|
||||
"packaging_req", "trim_req", "rolling_mode",
|
||||
"coil_diameter", "split_count", "next_process",
|
||||
"incoming_weight", "incoming_od", "split_weights",
|
||||
)
|
||||
|
||||
|
||||
@router.get("/", response_model=Response[PageResponse[PlanOut]])
|
||||
async def list_plans(
|
||||
page: int = 1,
|
||||
@@ -48,6 +58,16 @@ async def list_plans(
|
||||
return Response.ok(PageResponse(total=total, page=page, page_size=page_size, items=items))
|
||||
|
||||
|
||||
@router.get("/last-template", response_model=Response[PlanTemplate])
|
||||
async def get_last_template(db: AsyncSession = Depends(get_db), _ = Depends(get_current_user)):
|
||||
"""最近一条计划的工艺字段(不含计划号/卷号/时间),用于新增时回填。"""
|
||||
result = await db.execute(select(ProductionPlan).order_by(desc(ProductionPlan.created_at)).limit(1))
|
||||
p = result.scalar_one_or_none()
|
||||
if not p:
|
||||
return Response.ok(PlanTemplate())
|
||||
return Response.ok(PlanTemplate(**{k: getattr(p, k, None) for k in TEMPLATE_FIELDS}))
|
||||
|
||||
|
||||
@router.post("/", response_model=Response[PlanOut])
|
||||
async def create_plan(
|
||||
body: PlanCreate,
|
||||
@@ -98,3 +118,24 @@ async def confirm_plan(plan_id: int, db: AsyncSession = Depends(get_db), _ = Dep
|
||||
plan.status = "online"
|
||||
await db.flush()
|
||||
return Response.ok(PlanOut.model_validate(plan))
|
||||
|
||||
|
||||
@router.patch("/{plan_id}/start", response_model=Response[PlanOut])
|
||||
async def start_producing(plan_id: int, db: AsyncSession = Depends(get_db), _ = Depends(get_current_user)):
|
||||
"""移动到入口,开始生产:本条→producing,其它 producing→online(单卷在产)。"""
|
||||
result = await db.execute(select(ProductionPlan).where(ProductionPlan.id == plan_id))
|
||||
plan = result.scalar_one_or_none()
|
||||
if not plan:
|
||||
raise HTTPException(status_code=404, detail="计划不存在")
|
||||
# 其它正在生产的全部回退为在线(强制单卷在产)
|
||||
others = await db.execute(
|
||||
select(ProductionPlan).where(
|
||||
ProductionPlan.status == "producing",
|
||||
ProductionPlan.id != plan_id,
|
||||
)
|
||||
)
|
||||
for o in others.scalars():
|
||||
o.status = "online"
|
||||
plan.status = "producing"
|
||||
await db.flush()
|
||||
return Response.ok(PlanOut.model_validate(plan))
|
||||
|
||||
Reference in New Issue
Block a user