feat: 同步本地未提交的前后端更新(plan/quality/material/inspection/production 等模块)
This commit is contained in:
@@ -5,7 +5,7 @@ from typing import Optional
|
||||
from datetime import datetime
|
||||
|
||||
from app.database import get_db
|
||||
from app.models.plan import ProductionPlan, PlanStatus
|
||||
from app.models.plan import ProductionPlan
|
||||
from app.schemas.plan import PlanCreate, PlanUpdate, PlanOut
|
||||
from app.schemas.common import Response, PageResponse
|
||||
from app.services.auth_service import get_current_user
|
||||
@@ -34,10 +34,7 @@ async def list_plans(
|
||||
):
|
||||
query = select(ProductionPlan).order_by(desc(ProductionPlan.plan_date))
|
||||
if status:
|
||||
try:
|
||||
query = query.where(ProductionPlan.status == PlanStatus(status))
|
||||
except ValueError:
|
||||
pass
|
||||
query = query.where(ProductionPlan.status == status)
|
||||
_sd = _parse_dt(start_date)
|
||||
if _sd:
|
||||
query = query.where(ProductionPlan.plan_date >= _sd)
|
||||
@@ -98,6 +95,6 @@ async def confirm_plan(plan_id: int, db: AsyncSession = Depends(get_db), _ = Dep
|
||||
plan = result.scalar_one_or_none()
|
||||
if not plan:
|
||||
raise HTTPException(status_code=404, detail="计划不存在")
|
||||
plan.status = PlanStatus.CONFIRMED
|
||||
plan.status = "online"
|
||||
await db.flush()
|
||||
return Response.ok(PlanOut.model_validate(plan))
|
||||
|
||||
@@ -9,7 +9,7 @@ from app.models.quality import QcTask, QcTaskItem, QcDefect
|
||||
from app.schemas.quality import (
|
||||
QcTaskCreate, QcTaskUpdate, QcTaskOut,
|
||||
QcTaskItemCreate, QcTaskItemUpdate, QcTaskItemOut,
|
||||
QcDefectCreate, QcDefectUpdate, QcDefectOut,
|
||||
QcDefectCreate, QcDefectUpdate, QcDefectOut, QcDefectBulkSave,
|
||||
)
|
||||
from app.schemas.common import Response, PageResponse
|
||||
from app.services.auth_service import get_current_user
|
||||
@@ -158,6 +158,41 @@ async def create_defect(body: QcDefectCreate, db: AsyncSession = Depends(get_db)
|
||||
return Response.ok(QcDefectOut.model_validate(defect))
|
||||
|
||||
|
||||
@router.get("/defects/by-coil/{coil_no}", response_model=Response[list[QcDefectOut]])
|
||||
async def list_defects_by_coil(coil_no: str, db: AsyncSession = Depends(get_db), _=Depends(get_current_user)):
|
||||
r = await db.execute(
|
||||
select(QcDefect)
|
||||
.where(QcDefect.coil_no == coil_no, QcDefect.del_flag == 0)
|
||||
.order_by(QcDefect.seq_no.asc().nulls_last(), QcDefect.id.asc())
|
||||
)
|
||||
return Response.ok([QcDefectOut.model_validate(d) for d in r.scalars()])
|
||||
|
||||
|
||||
@router.post("/defects/bulk-save", response_model=Response[list[QcDefectOut]])
|
||||
async def bulk_save_defects(body: QcDefectBulkSave, db: AsyncSession = Depends(get_db), _=Depends(get_current_user)):
|
||||
"""按卷号替换全部缺陷记录(软删旧记录后批量插入)"""
|
||||
coil_no = body.coil_no
|
||||
# 软删旧记录
|
||||
old = await db.execute(select(QcDefect).where(QcDefect.coil_no == coil_no, QcDefect.del_flag == 0))
|
||||
for d in old.scalars():
|
||||
d.del_flag = 1
|
||||
# 插入新记录
|
||||
saved: list[QcDefect] = []
|
||||
for idx, item in enumerate(body.defects, start=1):
|
||||
data = item.model_dump()
|
||||
data["coil_no"] = coil_no
|
||||
if not data.get("seq_no"):
|
||||
data["seq_no"] = idx
|
||||
# 自动算长度
|
||||
if data.get("start_position") is not None and data.get("end_position") is not None and not data.get("length_val"):
|
||||
data["length_val"] = round(float(data["end_position"]) - float(data["start_position"]), 3)
|
||||
d = QcDefect(**data)
|
||||
db.add(d)
|
||||
saved.append(d)
|
||||
await db.flush()
|
||||
return Response.ok([QcDefectOut.model_validate(d) for d in saved])
|
||||
|
||||
|
||||
@router.put("/defects/{defect_id}", response_model=Response[QcDefectOut])
|
||||
async def update_defect(defect_id: int, body: QcDefectUpdate, db: AsyncSession = Depends(get_db), _=Depends(get_current_user)):
|
||||
r = await db.execute(select(QcDefect).where(QcDefect.id == defect_id, QcDefect.del_flag == 0))
|
||||
|
||||
Reference in New Issue
Block a user