提交
This commit is contained in:
1 parent
ee73f69759
commit
74f751d0d1
70 files changed
+9340
-6930
No files matched your search
@@ -21,6 +21,7 @@ from app.core.auth import (
|
||||
store_session,
|
||||
)
|
||||
from app.core.response import success_response, error_response
|
||||
from app.core.config import settings
|
||||
from app.models.models import SysUser
|
||||
from app.crud.user import user_crud
|
||||
from app.core.utils import generate_uuid
|
||||
@@ -123,7 +124,7 @@ async def web_login(
|
||||
{
|
||||
"token": access_token,
|
||||
"refreshToken": refresh_token,
|
||||
"expiresIn": 7200,
|
||||
"expiresIn": settings.ACCESS_TOKEN_EXPIRE_MINUTES * 60,
|
||||
"userInfo": _build_user_info_payload(user, web_role),
|
||||
}
|
||||
)
|
||||
@@ -184,7 +185,7 @@ async def refresh_token(body: dict, db: Session = Depends(get_db)):
|
||||
{
|
||||
"token": new_access_token,
|
||||
"refreshToken": new_refresh_token,
|
||||
"expiresIn": 7200,
|
||||
"expiresIn": settings.ACCESS_TOKEN_EXPIRE_MINUTES * 60,
|
||||
}
|
||||
)
|
||||
except HTTPException:
|
||||
|
||||
+39
-15
@@ -1,7 +1,7 @@
|
||||
"""质量检测 — 第三方/实验室主数据、质检工单、质检任务 API"""
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -733,6 +733,26 @@ async def get_task_results(
|
||||
return error_response(str(e))
|
||||
|
||||
|
||||
@router.get("/qc-tasks/{task_id}/material-usages")
|
||||
async def get_task_material_usages(
|
||||
task_id: str,
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_menu_code("biz:qcTask:list")),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
t = task_svc.get_task(db, task_id, tenant_no=tenant_no)
|
||||
if not t:
|
||||
return error_response("任务不存在")
|
||||
return success_response(
|
||||
mu_svc.list_usages_by_task(db, task_id, tenant_no, user_info=user)
|
||||
)
|
||||
except PermissionError as e:
|
||||
return error_response(str(e), code=403)
|
||||
except Exception as e:
|
||||
return error_response(str(e))
|
||||
|
||||
|
||||
@router.post("/qc-tasks/{task_id}/complete-with-result")
|
||||
async def complete_task_with_result(
|
||||
task_id: str,
|
||||
@@ -748,26 +768,16 @@ async def complete_task_with_result(
|
||||
return error_response("任务不存在")
|
||||
was_done = (t.task_status or "").strip() == "ywc"
|
||||
if body.results:
|
||||
result_svc.save_results_for_task(db, task_id, body.results, tenant_no, user_id)
|
||||
result_svc.save_results_for_task(
|
||||
db, task_id, body.results, tenant_no, user_id, commit=False,
|
||||
)
|
||||
concl = (body.conclusion or "").strip()
|
||||
if concl not in ("tg", "btg"):
|
||||
return error_response("请选择检测结论(通过/不通过)")
|
||||
if body.third_party_attachments is not None:
|
||||
task_svc.update_task_attachments(
|
||||
db, task_id, attachments=body.third_party_attachments,
|
||||
tenant_no=tenant_no, user_id=user_id,
|
||||
)
|
||||
# 物料扣减(可选,仅当传了 materialUsages 时)
|
||||
if body.material_usages:
|
||||
task_obj_pre = task_svc.get_task(db, task_id, tenant_no=tenant_no)
|
||||
task_no = task_obj_pre.task_no if task_obj_pre else ""
|
||||
mu_svc.deduct_for_task(
|
||||
db,
|
||||
task_id,
|
||||
task_no=task_no,
|
||||
material_usages=body.material_usages,
|
||||
tenant_no=tenant_no,
|
||||
user_id=user_id,
|
||||
tenant_no=tenant_no, user_id=user_id, commit=False,
|
||||
)
|
||||
obj = task_svc.apply_task_result(
|
||||
db,
|
||||
@@ -776,16 +786,30 @@ async def complete_task_with_result(
|
||||
user_id=user_id,
|
||||
conclusion=concl,
|
||||
remark=body.remark,
|
||||
material_usages=body.material_usages,
|
||||
commit=False,
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(obj)
|
||||
if (obj.task_status or "").strip() == "ywc":
|
||||
wo_svc.try_complete_work_order(db, obj.work_order_id, tenant_no)
|
||||
return success_response(
|
||||
task_svc._task_to_dict(obj, work_order_no="", db=db, tenant_no=tenant_no),
|
||||
message="已保存" if was_done else "已完成",
|
||||
)
|
||||
except HTTPException as e:
|
||||
db.rollback()
|
||||
detail = e.detail
|
||||
msg = detail if isinstance(detail, str) else str(detail)
|
||||
return error_response(msg, code=e.status_code)
|
||||
except PermissionError as e:
|
||||
db.rollback()
|
||||
return error_response(str(e), code=403)
|
||||
except ValueError as e:
|
||||
db.rollback()
|
||||
return error_response(str(e))
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
return error_response(str(e))
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user