feat(sample): 展示样本状态并支持样本废弃与作废原因
生产/质检入库卡片展示样本状态并支持【样本废弃】;市场 Web 列表与移动市场部卡片补充样本状态及问号查看作废原因;样本表新增 void_desc,人工作废不联动接收但全部作废时自动作废协议(#131)。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7751cc0f4a
commit
0b4c8dfda8
53 files changed
+1527
-82
No files matched your search
@@ -47,10 +47,12 @@ from app.api.sample_cert_insurance import router as sample_cert_insurance_router
|
||||
from app.api.sample_code_correction import router as sample_code_correction_router
|
||||
from app.api.lab_sample_process import router as lab_sample_process_router
|
||||
from app.api.lab_sample_processing import router as lab_sample_processing_router
|
||||
from app.api.business_sample import router as business_sample_router
|
||||
|
||||
from app.api.project_management import router as project_management_router
|
||||
|
||||
__all__ = [
|
||||
"business_sample_router",
|
||||
"project_management_router",
|
||||
"lab_sample_process_router",
|
||||
"public_router",
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
"""业务样本:人工作废等跨模块入口。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.core.menu_guard import require_admin_or_super_admin
|
||||
from app.core.response import error_response, success_response
|
||||
from app.models.models import SysUser
|
||||
from app.services.protocol_reception_discard_sync import SAMPLE_VOID_STATUS, void_sample_manually
|
||||
|
||||
router = APIRouter(prefix="/web/admin", tags=["业务样本"])
|
||||
|
||||
|
||||
class VoidSampleBody(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
reception_source: str = Field(..., alias="receptionSource")
|
||||
void_desc: str = Field(..., alias="voidDesc")
|
||||
sample_id: Optional[str] = Field(None, alias="sampleId")
|
||||
sample_code: Optional[str] = Field(None, alias="sampleCode")
|
||||
protocol_id: Optional[str] = Field(None, alias="protocolId")
|
||||
|
||||
|
||||
def _get_tenant_no(db: Session, user: dict) -> str:
|
||||
user_id = user.get("user_id")
|
||||
if not user_id:
|
||||
raise PermissionError("用户身份信息缺失,无法确定租户")
|
||||
sys_user = db.query(SysUser).filter(SysUser.id == user_id).first()
|
||||
if not sys_user or not sys_user.tenant_no:
|
||||
raise PermissionError("用户租户信息缺失")
|
||||
return sys_user.tenant_no
|
||||
|
||||
|
||||
def _get_current_user_id(user: dict) -> str:
|
||||
user_id = user.get("user_id")
|
||||
if not user_id:
|
||||
raise PermissionError("用户身份信息缺失")
|
||||
return str(user_id)
|
||||
|
||||
|
||||
@router.put("/business-samples/void")
|
||||
async def void_business_sample(
|
||||
body: VoidSampleBody,
|
||||
db: Session = Depends(get_db),
|
||||
user: dict = Depends(require_admin_or_super_admin),
|
||||
):
|
||||
try:
|
||||
tenant_no = _get_tenant_no(db, user)
|
||||
user_id = _get_current_user_id(user)
|
||||
sample = void_sample_manually(
|
||||
db,
|
||||
source=body.reception_source,
|
||||
tenant_no=tenant_no,
|
||||
void_desc=body.void_desc,
|
||||
user_id=user_id,
|
||||
sample_id=body.sample_id,
|
||||
sample_code=body.sample_code,
|
||||
protocol_id=body.protocol_id,
|
||||
commit=True,
|
||||
)
|
||||
return success_response(
|
||||
{
|
||||
"id": sample.id,
|
||||
"sampleCode": getattr(sample, "sample_code", None) or "",
|
||||
"sampleStatus": SAMPLE_VOID_STATUS,
|
||||
"voidDate": getattr(sample, "void_date", None) or "",
|
||||
"voidDesc": getattr(sample, "void_desc", None) or "",
|
||||
}
|
||||
)
|
||||
except PermissionError as e:
|
||||
return error_response(403, str(e))
|
||||
except ValueError as e:
|
||||
return error_response(400, str(e))
|
||||
except Exception as e:
|
||||
return error_response(400, str(e))
|
||||
Reference in new issue
Block a user