This commit is contained in:
zlwu committed 2026-05-20 14:32:07 +08:00
1 parent 15ed25e33b
commit dc31968204
143 files changed
+15823 -9989

No files matched your search

+50 -121
View File
@@ -681,101 +681,16 @@ async def list_storage_certs(
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
q = (
db.query(BizCollectionProtocol)
.filter(
BizCollectionProtocol.del_flag == 0,
BizCollectionProtocol.tenant_no == tenant_no,
BizCollectionProtocol.protocol_status == "sxz",
)
page_items, total = cp_svc.list_storage_certs(
db,
tenant_no=tenant_no,
keyword=keyword,
make_status=makeStatus,
page=page,
page_size=pageSize,
)
kw = (keyword or "").strip()
if kw:
like = f"%{kw}%"
q = q.filter(BizCollectionProtocol.protocol_no.like(like))
protocol_ids_sub = q.with_entities(BizCollectionProtocol.id).subquery()
sample_exists = (
db.query(BizProtocolSample)
.filter(
BizProtocolSample.collection_protocol_id == protocol_ids_sub.c.id,
BizProtocolSample.del_flag == 0,
BizProtocolSample.sample_status == "yrk",
)
.limit(1)
.exists()
)
q = q.filter(sample_exists)
rows_all = q.order_by(BizCollectionProtocol.create_time.desc()).all()
protocol_ids = [r.id for r in rows_all]
pc_map: Dict[str, Any] = {}
sc_map: Dict[str, Any] = {}
sample_map: Dict[str, List[Dict[str, Any]]] = {}
if protocol_ids:
pc_rows = (
db.query(BizProtocolPartyCustomer)
.filter(
BizProtocolPartyCustomer.collection_protocol_id.in_(protocol_ids),
BizProtocolPartyCustomer.del_flag == 0,
)
.all()
)
for pc in pc_rows:
pc_map[pc.collection_protocol_id] = pc
sc_rows = (
db.query(BizProtocolStorageCert)
.filter(
BizProtocolStorageCert.collection_protocol_id.in_(protocol_ids),
BizProtocolStorageCert.del_flag == 0,
)
.all()
)
for sc in sc_rows:
sc_map[sc.collection_protocol_id] = sc
s_rows = (
db.query(BizProtocolSample)
.filter(
BizProtocolSample.collection_protocol_id.in_(protocol_ids),
BizProtocolSample.del_flag == 0,
BizProtocolSample.sample_status == "yrk",
)
.all()
)
for s in s_rows:
sample_map.setdefault(s.collection_protocol_id, []).append(
cp_svc._sample_to_dict(s)
)
items: List[Dict[str, Any]] = []
for r in rows_all:
sc = sc_map.get(r.id)
ms = (sc.make_status or "0") if sc else "0"
if makeStatus and makeStatus.strip() and ms != makeStatus.strip():
continue
pc = pc_map.get(r.id)
d: Dict[str, Any] = {
"id": r.id,
"protocolNo": r.protocol_no or "",
"protocolStatus": r.protocol_status or "",
"motherName": (pc.mother_name or "") if pc else "",
"newbornDeliveryTime": cp_svc._fmt_dt(pc.newborn_delivery_time) if pc else "",
"samples": sample_map.get(r.id, []),
"makeStatus": ms,
"certImageUrls": (sc.cert_image_urls or "") if sc else "",
"makeDate": ((sc.make_date or "").strip() if sc.make_date else "") if sc else "",
}
items.append(d)
total = len(items)
page_safe = max(1, page)
page_size_safe = min(max(1, pageSize), 100)
start = (page_safe - 1) * page_size_safe
page_items = items[start : start + page_size_safe]
tp = cp_svc.total_pages(total, page_size_safe)
return success_response(
{"list": page_items, "total": total, "page": page_safe, "pageSize": page_size_safe, "totalPages": tp}
@@ -792,20 +707,18 @@ async def list_fullmoon_todos(
db: Session = Depends(get_db),
):
tenant_no = _get_tenant_no(db, user)
party_join = sa_and(
BizProtocolPartyCustomer.collection_protocol_id == BizCollectionProtocol.id,
BizProtocolPartyCustomer.del_flag == 0,
BizProtocolPartyCustomer.tenant_no == tenant_no,
)
q = (
db.query(BizCollectionProtocol, BizProtocolPartyCustomer)
.join(
BizProtocolPartyCustomer,
sa_and(
BizProtocolPartyCustomer.collection_protocol_id == BizCollectionProtocol.id,
BizProtocolPartyCustomer.del_flag == 0,
),
)
.outerjoin(BizProtocolPartyCustomer, party_join)
.filter(
BizCollectionProtocol.del_flag == 0,
BizCollectionProtocol.tenant_no == tenant_no,
BizCollectionProtocol.protocol_status == "sxz",
BizProtocolPartyCustomer.tenant_no == tenant_no,
)
)
kw = (keyword or "").strip()
@@ -837,33 +750,49 @@ async def list_fullmoon_todos(
ft_map[ft.collection_protocol_id] = ft
now = datetime.now()
_empty_ft: Dict[str, Any] = {
"todoStatus": "0",
"handleDate": "",
"handleRemark": "",
"insuranceAttachments": "",
"insuranceCompanyId": "",
"insuranceCompanyName": "",
"insuranceType": "",
"insurancePolicyNo": "",
"insuranceEffectiveDate": "",
"insuranceExpiryDate": "",
"insuranceSubscribed": "0",
"insuranceFee": None,
}
items: List[Dict[str, Any]] = []
for proto, pc in rows:
dt = pc.newborn_delivery_time
if not dt:
continue
fullmoon_date = dt + timedelta(days=30)
if fullmoon_date > now:
continue
dt = pc.newborn_delivery_time if pc else None
fullmoon_date_str = ""
is_fullmoon_passed = False
if dt:
fullmoon_date = dt + timedelta(days=30)
fullmoon_date_str = fullmoon_date.strftime("%Y-%m-%d")
is_fullmoon_passed = fullmoon_date <= now
ft = ft_map.get(proto.id)
ts = (ft.todo_status or "0") if ft else "0"
if todoStatus and todoStatus.strip() and ts != todoStatus.strip():
continue
d: Dict[str, Any] = {
"id": proto.id,
"protocolNo": proto.protocol_no or "",
"protocolStatus": proto.protocol_status or "",
"motherName": pc.mother_name or "",
"motherPhone": pc.mother_phone or "",
"newbornName": pc.newborn_name or "",
"newbornDeliveryTime": cp_svc._fmt_dt(dt),
"fullmoonDate": fullmoon_date.strftime("%Y-%m-%d"),
}
if ft:
d["fullmoonTodo"] = cp_svc._fullmoon_todo_to_dict(ft)
else:
d["fullmoonTodo"] = None
items.append(d)
ft_dict = cp_svc._fullmoon_todo_to_dict(ft) if ft else dict(_empty_ft)
items.append(
{
"protocolId": proto.id,
"id": proto.id,
"protocolNo": proto.protocol_no or "",
"protocolStatus": proto.protocol_status or "",
"motherName": (pc.mother_name if pc else "") or "",
"motherPhone": (pc.mother_phone if pc else "") or "",
"newbornName": (pc.newborn_name if pc else "") or "",
"newbornDeliveryTime": cp_svc._fmt_dt(dt) if dt else "",
"fullmoonDate": fullmoon_date_str,
"isFullmoonPassed": is_fullmoon_passed,
**ft_dict,
}
)
total = len(items)
page_safe = max(1, page)
+5 -5
View File
@@ -1,4 +1,4 @@
"""保险公司管理 API(保险公司 + 开票信息 + 项目价格)"""
"""保险公司及险种价格管理 API(保险公司 + 开票信息 + 险种价格)"""
import math
import uuid
from datetime import datetime
@@ -18,7 +18,7 @@ from app.models.models import (
SysUser,
)
router = APIRouter(prefix="/web/admin", tags=["保险公司管理"])
router = APIRouter(prefix="/web/admin", tags=["保险公司及险种价格管理"])
# ---------------------------------------------------------------------------
@@ -238,7 +238,7 @@ def _soft_delete_insurance_company(db: Session, row_id: str, *, tenant_no: str):
# ---------------------------------------------------------------------------
# Inline CRUD — 保险公司开票信息
# Inline CRUD — 险种开票信息
# ---------------------------------------------------------------------------
@@ -376,7 +376,7 @@ def _soft_delete_insurance_company_invoice(db: Session, row_id: str, *, tenant_n
# ---------------------------------------------------------------------------
# Inline CRUD — 保险项目价格
# Inline CRUD — 险种价格
# ---------------------------------------------------------------------------
@@ -729,7 +729,7 @@ async def delete_insurance_company_invoice(
# ---------------------------------------------------------------------------
# 3. 保险项目价格(子表)
# 3. 险种价格(子表)
# ---------------------------------------------------------------------------
+1 -1
View File
@@ -66,7 +66,7 @@ async def create_leave(
):
tenant_no = _user.get("tenant_no", "")
user_id = _user.get("user_id") or _user.get("id", "")
dept_id = _user.get("deptId", "")
dept_id = _user.get("region_id", "")
row = leave_crud.create_leave(
db,
leave_type=body.leaveType,
+1 -1
View File
@@ -88,7 +88,7 @@ STATIC_MENU_TREE = [
"name": "Unit",
"path": "unit",
"component": "/system/unit/index",
"meta": {"title": "物品单位", "keepAlive": True, "menuCode": "system:unit:list"},
"meta": {"title": "物品单位管理", "keepAlive": True, "menuCode": "system:unit:list"},
},
{
"id": "110",
+100 -1
View File
@@ -264,10 +264,25 @@ class ReceptionCheckSubmit(BaseModel):
checked: bool = False
class SampleReceptionUpdateBody(BaseModel):
model_config = ConfigDict(populate_by_name=True)
reception_time: str = Field(..., alias="receptionTime")
handler_user_id: Optional[str] = Field(None, alias="handlerUserId")
handler_name: Optional[str] = Field(None, alias="handlerName")
receive_temperature: Optional[str] = Field(None, alias="receiveTemperature")
volume_ml: Optional[float] = Field(None, alias="volumeMl")
net_weight_g: Optional[float] = Field(None, alias="netWeightG")
checks: List[ReceptionCheckSubmit] = Field(default_factory=list)
accept_conclusion: str = Field(..., alias="acceptConclusion")
receive_attachments: Optional[str] = Field(None, alias="receiveAttachments")
remark: Optional[str] = None
class SampleReceptionCreateBody(BaseModel):
model_config = ConfigDict(populate_by_name=True)
protocol_sample_id: str = Field(..., alias="protocolSampleId")
protocol_sample_id: Optional[str] = Field(None, alias="protocolSampleId")
reception_time: str = Field(..., alias="receptionTime")
handler_user_id: Optional[str] = Field(None, alias="handlerUserId")
handler_name: Optional[str] = Field(None, alias="handlerName")
@@ -326,3 +341,87 @@ async def post_sample_reception(
return error_response(str(e))
except Exception as e:
return error_response(str(e))
@router.put("/sample-receptions/{reception_id}")
async def put_sample_reception(
reception_id: str,
body: SampleReceptionUpdateBody,
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)
rt = parse_datetime(body.reception_time)
if not rt:
return error_response("样本接收时间格式无效")
checks_payload = [
{"checkItemId": c.check_item_id, "checked": c.checked} for c in body.checks
]
obj = sr_svc.update_sample_reception(
db,
reception_id=reception_id,
tenant_no=tenant_no,
user_id=user_id,
reception_time=rt,
handler_user_id=body.handler_user_id or user_id,
handler_name=body.handler_name,
receive_temperature=body.receive_temperature,
volume_ml=body.volume_ml,
net_weight_g=body.net_weight_g,
checks=checks_payload,
accept_conclusion=body.accept_conclusion,
receive_attachments=body.receive_attachments,
remark=body.remark,
)
detail = sr_svc.get_reception_by_id(db, obj.id, tenant_no)
return success_response(detail or {"id": obj.id})
except PermissionError as e:
return error_response(str(e), code=403)
except ValueError as e:
return error_response(str(e))
except Exception as e:
return error_response(str(e))
@router.put("/sample-receptions/{reception_id}")
async def put_sample_reception(
reception_id: str,
body: SampleReceptionUpdateBody,
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)
rt = parse_datetime(body.reception_time)
if not rt:
return error_response("样本接收时间格式无效")
checks_payload = [
{"checkItemId": c.check_item_id, "checked": c.checked} for c in body.checks
]
obj = sr_svc.update_sample_reception(
db,
reception_id=reception_id,
tenant_no=tenant_no,
user_id=user_id,
reception_time=rt,
handler_user_id=body.handler_user_id or user_id,
handler_name=body.handler_name,
receive_temperature=body.receive_temperature,
volume_ml=body.volume_ml,
net_weight_g=body.net_weight_g,
checks=checks_payload,
accept_conclusion=body.accept_conclusion,
receive_attachments=body.receive_attachments,
remark=body.remark,
)
detail = sr_svc.get_reception_by_id(db, obj.id, tenant_no)
return success_response(detail or {"id": obj.id})
except PermissionError as e:
return error_response(str(e), code=403)
except ValueError as e:
return error_response(str(e))
except Exception as e:
return error_response(str(e))