This commit is contained in:
zlwu committed 2026-05-25 15:14:06 +08:00
1 parent 575e63e7e8
commit 771f010a39
165 files changed
+67359 -21698

No files matched your search

+165 -2
View File
@@ -630,6 +630,8 @@ def list_storage_certs(
tenant_no: str,
keyword: Optional[str] = None,
make_status: Optional[str] = None,
storage_in_date_start: Optional[str] = None,
storage_in_date_end: Optional[str] = None,
page: int = 1,
page_size: int = 10,
user_info=None,
@@ -704,6 +706,8 @@ def list_storage_certs(
items: List[Dict[str, Any]] = []
ms_filter = (make_status or "").strip()
start_in = _yyyymmdd_from_date_param(storage_in_date_start) if storage_in_date_start else ""
end_in = _yyyymmdd_from_date_param(storage_in_date_end) if storage_in_date_end else ""
for r in rows_all:
sc = sc_map.get(r.id)
cert_ms = (sc.make_status or "0") if sc else "0"
@@ -711,6 +715,15 @@ def list_storage_certs(
continue
pc = pc_map.get(r.id)
samples = sample_map.get(r.id, [])
storage_in = _pick_storage_in_date(samples) or storage_in_date_map.get(r.id, "")
if start_in or end_in:
sid = _storage_in_date_to_yyyymmdd(storage_in)
if not sid:
continue
if start_in and sid < start_in:
continue
if end_in and sid > end_in:
continue
cert_dict = _storage_cert_to_dict(sc) if sc else {"makeStatus": "0", "certImageUrls": "", "makeDate": "", "remark": ""}
items.append(
{
@@ -728,8 +741,7 @@ def list_storage_certs(
"newbornWeightGram": pc.newborn_weight_gram if pc else None,
"newbornInfo": _format_newborn_info(pc),
"sampleInfo": _format_storage_cert_sample_info(samples, type_map),
"storageInDate": _pick_storage_in_date(samples)
or storage_in_date_map.get(r.id, ""),
"storageInDate": storage_in,
"samples": samples,
"makeStatus": cert_dict.get("makeStatus", "0"),
"certImageUrls": cert_dict.get("certImageUrls", ""),
@@ -745,6 +757,26 @@ def list_storage_certs(
return items[start : start + page_size_safe], total
def _normalize_date_bound(value: str, *, end_of_day: bool = False) -> str:
val = (value or "").strip()
if len(val) == 10:
return f"{val} 23:59:59" if end_of_day else f"{val} 00:00:00"
return val
def _yyyymmdd_from_date_param(value: str) -> str:
val = (value or "").strip()
if len(val) == 10 and val[4] == "-" and val[7] == "-":
return val.replace("-", "")
digits = "".join(c for c in val if c.isdigit())
return digits[:8] if len(digits) >= 8 else digits
def _storage_in_date_to_yyyymmdd(value: str) -> str:
digits = "".join(c for c in (value or "").strip() if c.isdigit())
return digits[:8] if len(digits) >= 8 else ""
def list_collection_protocols(
db: Session,
*,
@@ -752,6 +784,10 @@ def list_collection_protocols(
page_size: int = 10,
keyword: Optional[str] = None,
protocol_status: Optional[str] = None,
create_time_start: Optional[str] = None,
create_time_end: Optional[str] = None,
sample_collect_time_start: Optional[str] = None,
sample_collect_time_end: Optional[str] = None,
tenant_no: Optional[str] = None,
scope_collector_user_id: Optional[str] = None,
user_info=None,
@@ -766,6 +802,32 @@ def list_collection_protocols(
)
if protocol_status:
q0 = q0.filter(BizCollectionProtocol.protocol_status == protocol_status.strip())
if create_time_start:
q0 = q0.filter(
BizCollectionProtocol.create_time >= _normalize_date_bound(create_time_start)
)
if create_time_end:
q0 = q0.filter(
BizCollectionProtocol.create_time
<= _normalize_date_bound(create_time_end, end_of_day=True)
)
if sample_collect_time_start or sample_collect_time_end:
ci_q = db.query(BizProtocolCollectionInfo.collection_protocol_id).filter(
BizProtocolCollectionInfo.del_flag == 0,
)
if tenant_no:
ci_q = ci_q.filter(BizProtocolCollectionInfo.tenant_no == tenant_no)
if sample_collect_time_start:
ci_q = ci_q.filter(
BizProtocolCollectionInfo.sample_collect_time
>= _normalize_date_bound(sample_collect_time_start)
)
if sample_collect_time_end:
ci_q = ci_q.filter(
BizProtocolCollectionInfo.sample_collect_time
<= _normalize_date_bound(sample_collect_time_end, end_of_day=True)
)
q0 = q0.filter(BizCollectionProtocol.id.in_(ci_q))
kw = (keyword or "").strip()
if kw:
like = f"%{kw}%"
@@ -1168,6 +1230,46 @@ def _detail_query_with_protocol(
)
def _apply_payment_detail_list_filters(
q,
db: Session,
*,
tenant_no: str,
keyword: Optional[str] = None,
installment_due_date_start: Optional[str] = None,
installment_due_date_end: Optional[str] = None,
):
kw = (keyword or "").strip()
if kw:
like = f"%{kw}%"
party_q = db.query(BizProtocolPartyCustomer.collection_protocol_id).filter(
BizProtocolPartyCustomer.del_flag == 0,
or_(
BizProtocolPartyCustomer.mother_name.like(like),
BizProtocolPartyCustomer.mother_id_card.like(like),
BizProtocolPartyCustomer.newborn_name.like(like),
BizProtocolPartyCustomer.newborn_id_card.like(like),
),
)
if tenant_no:
party_q = party_q.filter(BizProtocolPartyCustomer.tenant_no == tenant_no)
q = q.filter(
or_(
BizCollectionProtocol.protocol_no.like(like),
BizCollectionProtocol.id.in_(party_q),
)
)
if installment_due_date_start:
start_due = _yyyymmdd_from_date_param(installment_due_date_start)
if start_due:
q = q.filter(BizProtocolPaymentDetail.installment_due_date >= start_due)
if installment_due_date_end:
end_due = _yyyymmdd_from_date_param(installment_due_date_end)
if end_due:
q = q.filter(BizProtocolPaymentDetail.installment_due_date <= end_due)
return q
def _rows_to_payment_detail_dicts(
db: Session,
rows: List[Any],
@@ -1207,12 +1309,23 @@ def list_receipt_confirm_details(
*,
page: int = 1,
page_size: int = 10,
keyword: Optional[str] = None,
installment_due_date_start: Optional[str] = None,
installment_due_date_end: Optional[str] = None,
tenant_no: Optional[str] = None,
user_info=None,
) -> Tuple[List[Dict[str, Any]], int]:
if not tenant_no:
return [], 0
q_base = _detail_query_with_protocol(db, tenant_no, "jfqrz")
q_base = _apply_payment_detail_list_filters(
q_base,
db,
tenant_no=tenant_no,
keyword=keyword,
installment_due_date_start=installment_due_date_start,
installment_due_date_end=installment_due_date_end,
)
if user_info:
from app.core.data_scope import apply_data_scope
q_base = apply_data_scope(q_base, BizProtocolPaymentDetail, user_info, db, tenant_no)
@@ -1233,12 +1346,23 @@ def list_receipt_confirmed_details(
*,
page: int = 1,
page_size: int = 10,
keyword: Optional[str] = None,
installment_due_date_start: Optional[str] = None,
installment_due_date_end: Optional[str] = None,
tenant_no: Optional[str] = None,
user_info=None,
) -> Tuple[List[Dict[str, Any]], int]:
if not tenant_no:
return [], 0
q_base = _detail_query_with_protocol(db, tenant_no, "yjf")
q_base = _apply_payment_detail_list_filters(
q_base,
db,
tenant_no=tenant_no,
keyword=keyword,
installment_due_date_start=installment_due_date_start,
installment_due_date_end=installment_due_date_end,
)
if user_info:
from app.core.data_scope import apply_data_scope
q_base = apply_data_scope(q_base, BizProtocolPaymentDetail, user_info, db, tenant_no)
@@ -1307,12 +1431,23 @@ def list_refund_confirm_details(
*,
page: int = 1,
page_size: int = 10,
keyword: Optional[str] = None,
installment_due_date_start: Optional[str] = None,
installment_due_date_end: Optional[str] = None,
tenant_no: Optional[str] = None,
user_info=None,
) -> Tuple[List[Dict[str, Any]], int]:
if not tenant_no:
return [], 0
q_base = _detail_query_with_protocol(db, tenant_no, "tfqrz")
q_base = _apply_payment_detail_list_filters(
q_base,
db,
tenant_no=tenant_no,
keyword=keyword,
installment_due_date_start=installment_due_date_start,
installment_due_date_end=installment_due_date_end,
)
if user_info:
from app.core.data_scope import apply_data_scope
q_base = apply_data_scope(q_base, BizProtocolPaymentDetail, user_info, db, tenant_no)
@@ -1341,12 +1476,23 @@ def list_refund_confirmed_details(
*,
page: int = 1,
page_size: int = 10,
keyword: Optional[str] = None,
installment_due_date_start: Optional[str] = None,
installment_due_date_end: Optional[str] = None,
tenant_no: Optional[str] = None,
user_info=None,
) -> Tuple[List[Dict[str, Any]], int]:
if not tenant_no:
return [], 0
q_base = _detail_query_with_protocol(db, tenant_no, "ytf")
q_base = _apply_payment_detail_list_filters(
q_base,
db,
tenant_no=tenant_no,
keyword=keyword,
installment_due_date_start=installment_due_date_start,
installment_due_date_end=installment_due_date_end,
)
if user_info:
from app.core.data_scope import apply_data_scope
q_base = apply_data_scope(q_base, BizProtocolPaymentDetail, user_info, db, tenant_no)
@@ -1567,6 +1713,13 @@ def _party_customer_map_by_protocol_ids(
return {r.collection_protocol_id: r for r in rows}
def _yyyymmdd_from_date_param(value: str) -> str:
val = (value or "").strip()
if len(val) == 10 and val[4] == "-" and val[7] == "-":
return val.replace("-", "")
return val
def list_payment_details_page(
db: Session,
*,
@@ -1575,6 +1728,8 @@ def list_payment_details_page(
pay_status: Optional[str] = None,
keyword: Optional[str] = None,
transfer_type: Optional[str] = None,
installment_due_date_start: Optional[str] = None,
installment_due_date_end: Optional[str] = None,
tenant_no: Optional[str] = None,
user_info=None,
) -> Tuple[List[Dict[str, Any]], int]:
@@ -1598,6 +1753,14 @@ def list_payment_details_page(
q = q.filter(BizCollectionProtocol.protocol_no.like(like))
if transfer_type and transfer_type.strip():
q = q.filter(BizProtocolPaymentDetail.transfer_type == transfer_type.strip())
if installment_due_date_start:
start_due = _yyyymmdd_from_date_param(installment_due_date_start)
if start_due:
q = q.filter(BizProtocolPaymentDetail.installment_due_date >= start_due)
if installment_due_date_end:
end_due = _yyyymmdd_from_date_param(installment_due_date_end)
if end_due:
q = q.filter(BizProtocolPaymentDetail.installment_due_date <= end_due)
if user_info:
from app.core.data_scope import apply_data_scope
q = apply_data_scope(q, BizProtocolPaymentDetail, user_info, db, tenant_no)