提交
This commit is contained in:
1 parent
15ed25e33b
commit
dc31968204
143 files changed
+15823
-9989
No files matched your search
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user