This commit is contained in:
zlwu committed 2026-10-17 11:46:53 +08:00
1 parent 48dcf991dc
commit be2226e4ca
100 files changed
+61340 -40975

No files matched your search

+21
View File
@@ -9,6 +9,7 @@ from sqlalchemy.orm import Session
from sqlalchemy import and_ as sa_and, func as sa_func
from app.core.database import get_db
from app.core.data_scope import get_user_dept_id
from app.core.menu_guard import require_admin_or_super_admin
from app.core.response import error_response, success_response
from app.core.utils import parse_datetime
@@ -354,6 +355,7 @@ async def create_collection_protocol(
collector = user_id
obj = cp_svc.create_collection_protocol(
db,
create_dept_id=get_user_dept_id(db, user_id) or "",
protocol_no=body.protocol_no or "",
protocol_no_id=body.protocol_no_id,
protocol_status=body.protocol_status,
@@ -544,6 +546,8 @@ async def submit_collection_protocol_audit(
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
if not _protocol_accessible(db, protocol_id, tenant_no, user):
return error_response(403, "无权访问该协议或协议不存在")
try:
cp_svc.create_audit(
db,
@@ -560,6 +564,23 @@ async def submit_collection_protocol_audit(
return error_response(400, str(e))
@router.get("/collection-protocols/{protocol_id}/status-changes")
async def list_collection_protocol_status_changes(
protocol_id: str,
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
if not _protocol_accessible(db, protocol_id, tenant_no, user):
return error_response(403, "无权访问该协议或协议不存在")
items = cp_svc.list_protocol_status_changes(
db,
collection_protocol_id=protocol_id,
tenant_no=tenant_no,
)
return success_response({"list": items})
# ---------------------------------------------------------------------------
# 收款确认
# ---------------------------------------------------------------------------
+42 -2
View File
@@ -2,13 +2,15 @@
from __future__ import annotations
from datetime import datetime
from typing import Any, Dict, List, Optional
from fastapi import APIRouter, Depends, Query
from pydantic import BaseModel, ConfigDict, Field
from pydantic import BaseModel, ConfigDict, Field, field_validator
from sqlalchemy.orm import Session
from app.core.database import get_db
from app.core.data_scope import get_user_dept_id
from app.core.menu_guard import require_admin_or_super_admin, require_strict_menu_code
from app.core.response import error_response, success_response
from app.crud import presign_order as po_svc
@@ -56,6 +58,20 @@ class PresignOrderBody(BaseModel):
sample_type_ids: Optional[List[str]] = Field(None, alias="sampleTypeIds")
transfers: Optional[List[Dict[str, Any]]] = None
@field_validator("order_date", "expected_delivery_date")
@classmethod
def validate_ymd(cls, value: Optional[str]) -> Optional[str]:
if value in (None, ""):
return value
text = value.strip()
if len(text) != 8 or not text.isdigit():
raise ValueError("日期必须使用 YYYYMMDD 格式")
try:
datetime.strptime(text, "%Y%m%d")
except ValueError as exc:
raise ValueError("日期必须是有效的 YYYYMMDD") from exc
return text
class PresignTransferBody(BaseModel):
model_config = ConfigDict(extra="ignore", populate_by_name=True)
@@ -111,6 +127,7 @@ async def get_presign_order(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(db, order_id, tenant_no, user)
data = po_svc.get_presign_order(db, order_id=order_id, tenant_no=tenant_no)
if not data:
return error_response(404, "预签约订单不存在")
@@ -131,6 +148,7 @@ async def create_presign_order(
dumped = body.model_dump(by_alias=False)
obj = po_svc.create_presign_order(
db,
create_dept_id=get_user_dept_id(db, user_id) or "",
tenant_no=tenant_no,
user_id=user_id,
fields=dumped,
@@ -156,12 +174,14 @@ async def update_presign_order(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(db, order_id, tenant_no, user)
user_id = _get_current_user_id(user)
dumped = body.model_dump(by_alias=False, exclude_unset=True)
sample_type_ids = dumped.pop("sample_type_ids", None)
dumped.pop("transfers", None)
obj = po_svc.update_presign_order(
db,
create_dept_id=get_user_dept_id(db, user_id) or "",
order_id=order_id,
tenant_no=tenant_no,
user_id=user_id,
@@ -186,6 +206,7 @@ async def delete_presign_order(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(db, order_id, tenant_no, user)
user_id = _get_current_user_id(user)
po_svc.soft_delete_presign_order(
db, order_id=order_id, tenant_no=tenant_no, user_id=user_id
@@ -205,9 +226,11 @@ async def convert_presign_order(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(db, order_id, tenant_no, user)
user_id = _get_current_user_id(user)
data = po_svc.convert_to_protocol(
db, order_id=order_id, tenant_no=tenant_no, user_id=user_id
db, order_id=order_id, tenant_no=tenant_no, user_id=user_id,
create_dept_id=get_user_dept_id(db, user_id) or "",
)
return success_response(data, message="已转正式协议")
except PermissionError as e:
@@ -225,9 +248,11 @@ async def create_presign_transfer(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(db, order_id, tenant_no, user)
user_id = _get_current_user_id(user)
obj = po_svc.add_transfer(
db,
create_dept_id=get_user_dept_id(db, user_id) or "",
presign_order_id=order_id,
tenant_no=tenant_no,
user_id=user_id,
@@ -251,6 +276,9 @@ async def update_presign_transfer(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(
db, transfer_id, tenant_no, user, transfer=True
)
user_id = _get_current_user_id(user)
obj = po_svc.update_transfer_draft(
db,
@@ -276,6 +304,9 @@ async def submit_presign_transfer_finance(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(
db, transfer_id, tenant_no, user, transfer=True
)
user_id = _get_current_user_id(user)
obj = po_svc.submit_receipt_finance(
db, transfer_id=transfer_id, tenant_no=tenant_no, user_id=user_id
@@ -297,6 +328,9 @@ async def withdraw_presign_transfer(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(
db, transfer_id, tenant_no, user, transfer=True
)
user_id = _get_current_user_id(user)
obj = po_svc.withdraw_receipt(
db, transfer_id=transfer_id, tenant_no=tenant_no, user_id=user_id
@@ -371,6 +405,9 @@ async def confirm_presign_transfer(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(
db, transfer_id, tenant_no, user, transfer=True
)
user_id = _get_current_user_id(user)
obj = po_svc.confirm_receipt(
db,
@@ -397,6 +434,9 @@ async def reject_presign_transfer(
):
try:
tenant_no = _get_tenant_no(db, user)
po_svc.assert_presign_data_access(
db, transfer_id, tenant_no, user, transfer=True
)
user_id = _get_current_user_id(user)
obj = po_svc.reject_receipt(
db, transfer_id=transfer_id, tenant_no=tenant_no, user_id=user_id
+4 -6
View File
@@ -9,7 +9,7 @@ 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, require_strict_menu_code
from app.core.menu_guard import require_admin_or_super_admin
from app.core.response import error_response, success_response
from app.crud import protocol_refund_record as rr_svc
from app.models.models import (
@@ -20,8 +20,6 @@ from app.models.models import (
router = APIRouter(prefix="/web/admin", tags=["细胞存储-退费登记"])
REFUND_CONFIRM_MENU = "biz:cellStorageRefundConfirm:list"
def _get_tenant_no(db: Session, user: dict) -> str:
user_id = user.get("user_id")
@@ -96,7 +94,7 @@ async def list_protocol_refund_records(
async def create_protocol_refund_record(
protocol_id: str,
body: RefundRecordBody,
user: dict = Depends(require_strict_menu_code(REFUND_CONFIRM_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
try:
@@ -129,7 +127,7 @@ async def create_protocol_refund_record(
async def update_protocol_refund_record(
record_id: str,
body: RefundRecordUpdateBody,
user: dict = Depends(require_strict_menu_code(REFUND_CONFIRM_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
try:
@@ -176,7 +174,7 @@ async def update_protocol_refund_record(
@router.delete("/protocol-refund-records/{record_id}")
async def delete_protocol_refund_record(
record_id: str,
user: dict = Depends(require_strict_menu_code(REFUND_CONFIRM_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
try:
+32 -6
View File
@@ -325,7 +325,7 @@ async def update_research_donation(
@router.delete("/research-donations/{donation_id}")
async def delete_research_donation(
donation_id: str,
user: dict = Depends(require_strict_menu_code(PROTOCOL_LIST_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
@@ -350,7 +350,7 @@ async def delete_research_donation(
@router.post("/research-donations/batch-delete")
async def batch_delete_research_donations(
body: BatchDeleteBody,
user: dict = Depends(require_strict_menu_code(PROTOCOL_LIST_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
@@ -376,7 +376,7 @@ async def batch_delete_research_donations(
async def submit_donation_audit(
donation_id: str,
body: AuditSubmitBody,
user: dict = Depends(require_strict_menu_code(PROTOCOL_AUDIT_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
@@ -409,7 +409,7 @@ async def submit_donation_audit(
async def change_donation_status(
donation_id: str,
body: StatusChangeBody,
user: dict = Depends(require_strict_menu_code(PROTOCOL_AUDIT_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
@@ -433,6 +433,32 @@ async def change_donation_status(
return error_response(400, str(e))
@router.get("/research-donations/{donation_id}/status-changes")
async def list_research_donation_status_changes(
donation_id: str,
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
obj = (
db.query(BizResearchDonation)
.filter(
BizResearchDonation.id == donation_id,
BizResearchDonation.tenant_no == tenant_no,
BizResearchDonation.del_flag == 0,
)
.first()
)
if not obj:
return error_response(404, "捐赠单不存在")
items = rd_svc.list_donation_status_changes(
db,
research_donation_id=donation_id,
tenant_no=tenant_no,
)
return success_response({"list": items})
# ---------------------------------------------------------------------------
# 10. 细胞存储 → 科研捐赠
# ---------------------------------------------------------------------------
@@ -441,7 +467,7 @@ async def change_donation_status(
@router.post("/research-donations/convert-from-storage")
async def convert_from_storage(
body: ConvertFromStorageBody,
user: dict = Depends(require_strict_menu_code(PROTOCOL_AUDIT_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
@@ -469,7 +495,7 @@ async def convert_from_storage(
@router.post("/research-donations/{donation_id}/convert-to-storage")
async def convert_to_storage(
donation_id: str,
user: dict = Depends(require_strict_menu_code(PROTOCOL_AUDIT_MENU)),
user: dict = Depends(require_admin_or_super_admin),
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
+8 -1
View File
@@ -82,6 +82,7 @@ async def list_sample_freights(
items, total = freight_svc.list_freights(
db,
tenant_no=tenant_no,
user_info=user,
page=page,
page_size=pageSize,
keyword=keyword,
@@ -114,6 +115,7 @@ async def list_sample_freight_options(
items, total = freight_svc.list_sample_options(
db,
tenant_no=tenant_no,
user_info=user,
page=page,
page_size=pageSize,
keyword=keyword,
@@ -136,7 +138,7 @@ async def get_sample_freight(
):
try:
tenant_no = _get_tenant_no(db, user)
data = freight_svc.get_freight_detail(db, freight_id, tenant_no)
data = freight_svc.get_freight_detail(db, freight_id, tenant_no, user_info=user)
return success_response(data)
except PermissionError as e:
return error_response(403, str(e))
@@ -157,6 +159,7 @@ async def create_sample_freight(
data = freight_svc.create_freight(
db,
tenant_no=tenant_no,
user_info=user,
user_id=user_id,
transport_mode_raw=body.transport_mode,
freight_amount=body.freight_amount,
@@ -183,6 +186,7 @@ async def update_sample_freight(
db,
freight_id,
tenant_no=tenant_no,
user_info=user,
user_id=user_id,
transport_mode_raw=body.transport_mode,
freight_amount=body.freight_amount,
@@ -211,6 +215,7 @@ async def link_sample_freight(
db,
freight_id,
tenant_no=tenant_no,
user_info=user,
user_id=user_id,
items=items,
)
@@ -238,6 +243,7 @@ async def unlink_sample_freight(
db,
freight_id,
tenant_no=tenant_no,
user_info=user,
user_id=user_id,
items=items,
)
@@ -263,6 +269,7 @@ async def delete_sample_freight(
db,
freight_id,
tenant_no=tenant_no,
user_info=user,
user_id=user_id,
)
return success_response(data, message="删除成功")