汇总近期业务改动:催缴菜单与后端、样本信息快捷登记与进度、运费关联、客户档案扩展、协议优惠/期次与押金划转,并同步 SQL 迁移与管理端页面收敛。 Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.6 KiB
Python
74 lines
2.6 KiB
Python
"""科研捐赠样本采集信息 API"""
|
|
from typing import Optional
|
|
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.core.menu_guard import require_any_menu_code
|
|
from app.core.response import error_response, success_response
|
|
from app.crud import research_donation_sample_collection as svc
|
|
from app.crud.research_donation_sample_collection import total_pages
|
|
from app.models.models import SysUser
|
|
|
|
router = APIRouter(prefix="/web/admin", tags=["科研捐赠样本采集信息"])
|
|
|
|
_SAMPLE_INFO_MENU = require_any_menu_code(
|
|
"research-donation:sample-info:list",
|
|
)
|
|
|
|
|
|
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 _page_payload(items: list, total: int, page: int, page_size: int) -> dict:
|
|
return {
|
|
"list": items,
|
|
"total": total,
|
|
"page": page,
|
|
"pageSize": page_size,
|
|
"totalPages": total_pages(total, page_size),
|
|
}
|
|
|
|
|
|
@router.get("/research-donation-sample-collections/list")
|
|
async def list_donation_sample_collections(
|
|
page: int = Query(1, ge=1),
|
|
pageSize: int = Query(10, ge=1, le=100),
|
|
keyword: Optional[str] = None,
|
|
sampleStatus: Optional[str] = Query(None, alias="sampleStatus"),
|
|
collectionFlag: Optional[str] = Query(None, alias="collectionFlag"),
|
|
receptionFlag: Optional[str] = Query(None, alias="receptionFlag"),
|
|
qcFlag: Optional[str] = Query(None, alias="qcFlag"),
|
|
storageFlag: Optional[str] = Query(None, alias="storageFlag"),
|
|
db: Session = Depends(get_db),
|
|
user: dict = Depends(_SAMPLE_INFO_MENU),
|
|
):
|
|
try:
|
|
tenant_no = _get_tenant_no(db, user)
|
|
items, total = svc.list_donation_sample_collections(
|
|
db,
|
|
page=page,
|
|
page_size=pageSize,
|
|
tenant_no=tenant_no,
|
|
keyword=keyword,
|
|
sample_status=sampleStatus,
|
|
collection_flag=collectionFlag,
|
|
reception_flag=receptionFlag,
|
|
qc_flag=qcFlag,
|
|
storage_flag=storageFlag,
|
|
user_info=user,
|
|
)
|
|
return success_response(_page_payload(items, total, page, pageSize))
|
|
except PermissionError as e:
|
|
return error_response(403, str(e))
|
|
except Exception as e:
|
|
return error_response(400, str(e))
|