fix: align sample registration, freight scope, and OA datetime display

Let customer-service quick register write storage, certificate, and insurance separately without extra menu or data-scope checks. List freight by document data scope like the web admin, allow protocol staff outside the collection region, and pad OA datetimes to seconds so PC date pickers can show historical minute values.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zlwuandCursor committed 2026-10-20 17:30:30 +08:00
1 parent 03fcc01d6d
commit ac8e471aca
41 files changed
+16929 -14162

No files matched your search

+118 -26
View File
@@ -6,7 +6,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 assert_strict_menu_code, require_any_menu_code
from app.core.menu_guard import require_any_menu_code
from app.core.response import error_response, success_response
from app.core.utils import parse_date, parse_datetime
from app.crud import protocol_sample_collection as svc
@@ -26,8 +26,6 @@ _QUICK_REGISTER_MENU = require_any_menu_code(
"research-donation:sample-info:list",
)
_STORAGE_CERT_MENU = "cell-storage:storage-cert:list"
def _get_tenant_no(db: Session, user: dict) -> str:
user_id = user.get("user_id")
@@ -114,6 +112,18 @@ class QuickRegisterBody(BaseModel):
remark: Optional[str] = None
mail_cert_time: Optional[str] = Field(None, alias="mailCertTime")
policy_send_time: Optional[str] = Field(None, alias="policySendTime")
storage_handle_time: Optional[str] = Field(None, alias="storageHandleTime")
storage_handler_user_id: Optional[str] = Field(None, alias="storageHandlerUserId")
storage_attachments: Optional[str] = Field(None, alias="storageAttachments")
storage_remark: Optional[str] = Field(None, alias="storageRemark")
cert_handle_time: Optional[str] = Field(None, alias="certHandleTime")
cert_handler_user_id: Optional[str] = Field(None, alias="certHandlerUserId")
cert_attachments: Optional[str] = Field(None, alias="certAttachments")
cert_remark: Optional[str] = Field(None, alias="certRemark")
insurance_handle_time: Optional[str] = Field(None, alias="insuranceHandleTime")
insurance_handler_user_id: Optional[str] = Field(None, alias="insuranceHandlerUserId")
insurance_attachments: Optional[str] = Field(None, alias="insuranceAttachments")
insurance_remark: Optional[str] = Field(None, alias="insuranceRemark")
sms_send_date: Optional[str] = Field(None, alias="smsSendDate")
sms_send_status: Optional[str] = Field(None, alias="smsSendStatus")
microbe_followup_date: Optional[str] = Field(None, alias="microbeFollowupDate")
@@ -161,8 +171,6 @@ async def quick_register_sample_info(
user: dict = Depends(_QUICK_REGISTER_MENU),
):
kind = (body.kind or "").strip()
if kind in {"storage_cert", "insurance", "all"}:
assert_strict_menu_code(db, user, _STORAGE_CERT_MENU)
try:
tenant_no = _get_tenant_no(db, user)
user_id = _get_current_user_id(user)
@@ -185,7 +193,6 @@ async def quick_register_sample_info(
items=items,
reception_source=source,
tenant_no=tenant_no,
user=user,
user_id=user_id,
handle_time=ht,
handler_user_id=body.handler_user_id,
@@ -201,7 +208,6 @@ async def quick_register_sample_info(
db,
items=items,
tenant_no=tenant_no,
user=user,
user_id=user_id,
handle_time=ht,
handler_user_id=body.handler_user_id,
@@ -219,7 +225,6 @@ async def quick_register_sample_info(
db,
items=items,
tenant_no=tenant_no,
user=user,
user_id=user_id,
handle_time=ht,
handler_user_id=body.handler_user_id,
@@ -235,57 +240,144 @@ async def quick_register_sample_info(
db,
items=items,
tenant_no=tenant_no,
user=user,
user_id=user_id,
incoming=cs_incoming,
)
elif kind == "all":
if source != "cell_storage":
return error_response(400, "登记全部仅支持细胞存储样本")
split = any(
value is not None
for value in (
body.storage_handle_time,
body.storage_handler_user_id,
body.storage_attachments,
body.storage_remark,
body.cert_handle_time,
body.insurance_handle_time,
body.cert_attachments,
body.insurance_attachments,
body.cert_remark,
body.insurance_remark,
body.cert_handler_user_id,
body.insurance_handler_user_id,
)
)
if split:
storage_ht = (
parse_datetime(body.storage_handle_time)
if (body.storage_handle_time or "").strip()
else None
)
storage_handler = body.storage_handler_user_id
storage_atts = body.storage_attachments or ""
storage_remark = body.storage_remark or ""
cert_ht = (
parse_datetime(body.cert_handle_time)
if (body.cert_handle_time or "").strip()
else None
)
ins_ht = (
parse_datetime(body.insurance_handle_time)
if (body.insurance_handle_time or "").strip()
else None
)
cert_handler = body.cert_handler_user_id
ins_handler = body.insurance_handler_user_id
cert_atts = body.cert_attachments or ""
ins_atts = body.insurance_attachments or ""
cert_remark = body.cert_remark or ""
ins_remark = body.insurance_remark or ""
else:
storage_ht = None
storage_handler = None
storage_atts = ""
storage_remark = ""
cert_ht = ins_ht = ht
cert_handler = ins_handler = body.handler_user_id
cert_atts = ins_atts = attachments
cert_remark = ins_remark = remark
storage_side = bool(
storage_ht is not None
or (storage_atts or "").strip()
or (storage_remark or "").strip()
)
cert_side = bool(
cert_ht is not None
or update_mail
or (cert_atts or "").strip()
or (cert_remark or "").strip()
)
ins_side = bool(
ins_ht is not None
or update_policy
or (ins_atts or "").strip()
or (ins_remark or "").strip()
)
if storage_side and storage_ht is None:
return error_response(400, "请填写入库办理时间")
if cert_side and cert_ht is None:
return error_response(400, "请填写储存证办理时间")
if ins_side and ins_ht is None:
return error_response(400, "请填写保险办理时间")
wrote_any = False
success = 0
fail = 0
if ht is not None:
if storage_ht is not None:
storage_r = quick_svc.batch_quick_register_storage(
db,
items=items,
reception_source=source,
tenant_no=tenant_no,
user_id=user_id,
handle_time=storage_ht,
handler_user_id=storage_handler,
attachments=storage_atts,
remark=storage_remark,
do_commit=False,
)
success = max(success, storage_r.get("success", 0))
fail = max(fail, storage_r.get("fail", 0))
wrote_any = True
if cert_ht is not None:
cert_r = quick_svc.batch_handle_storage_certs(
db,
items=items,
tenant_no=tenant_no,
user=user,
user_id=user_id,
handle_time=ht,
handler_user_id=body.handler_user_id,
attachments=attachments,
remark=remark,
handle_time=cert_ht,
handler_user_id=cert_handler,
attachments=cert_atts,
remark=cert_remark,
mail_cert_time=mail_t,
update_mail_cert_time=update_mail,
do_commit=False,
)
success = max(success, cert_r.get("success", 0))
fail = max(fail, cert_r.get("fail", 0))
wrote_any = True
if ins_ht is not None:
ins_r = quick_svc.batch_handle_insurance(
db,
items=items,
tenant_no=tenant_no,
user=user,
user_id=user_id,
handle_time=ht,
handler_user_id=body.handler_user_id,
attachments=attachments,
remark=remark,
handle_time=ins_ht,
handler_user_id=ins_handler,
attachments=ins_atts,
remark=ins_remark,
policy_send_time=policy_t,
update_policy_send_time=update_policy,
do_commit=False,
)
success = max(cert_r.get("success", 0), ins_r.get("success", 0))
fail = max(cert_r.get("fail", 0), ins_r.get("fail", 0))
success = max(success, ins_r.get("success", 0))
fail = max(fail, ins_r.get("fail", 0))
wrote_any = True
elif update_mail or update_policy:
# 仅补时间线字段时仍要求办理时间走证险主路径;此处拒绝避免半写
return error_response(400, "登记储存证/保险请填写办理时间")
if has_any_customer_service_payload(cs_incoming):
cs_r = quick_svc.batch_register_customer_service(
db,
items=items,
tenant_no=tenant_no,
user=user,
user_id=user_id,
incoming=cs_incoming,
do_commit=False,