|
|
@@ -0,0 +1,53 @@
|
|
|
+from __future__ import annotations
|
|
|
+
|
|
|
+from typing import Optional
|
|
|
+
|
|
|
+from app.models.bx_models import (
|
|
|
+ BxAdvanceApply,
|
|
|
+ BxInvoice,
|
|
|
+ BxInvoiceLedger,
|
|
|
+ BxReimburseApply,
|
|
|
+)
|
|
|
+from app.services.crm.list_sort import resolve_datetime_order_by
|
|
|
+
|
|
|
+ADVANCE_WHITELIST = {
|
|
|
+ "applyTime": BxAdvanceApply.create_time,
|
|
|
+ "issueTime": BxAdvanceApply.issue_time,
|
|
|
+}
|
|
|
+REIMBURSE_WHITELIST = {
|
|
|
+ "applyTime": BxReimburseApply.create_time,
|
|
|
+ "payTime": BxReimburseApply.pay_time,
|
|
|
+}
|
|
|
+INVOICE_WHITELIST = {"createTime": BxInvoice.create_time}
|
|
|
+LEDGER_WHITELIST = {"createTime": BxInvoiceLedger.create_time}
|
|
|
+
|
|
|
+
|
|
|
+def order_advance(sort_field: Optional[str], sort_order: Optional[str], default=None):
|
|
|
+ if default is None:
|
|
|
+ default = BxAdvanceApply.create_time.desc()
|
|
|
+ return resolve_datetime_order_by(sort_field, sort_order, ADVANCE_WHITELIST, default)
|
|
|
+
|
|
|
+
|
|
|
+def order_reimburse(sort_field: Optional[str], sort_order: Optional[str], default=None):
|
|
|
+ if default is None:
|
|
|
+ default = BxReimburseApply.create_time.desc()
|
|
|
+ return resolve_datetime_order_by(sort_field, sort_order, REIMBURSE_WHITELIST, default)
|
|
|
+
|
|
|
+
|
|
|
+def order_invoice(sort_field: Optional[str], sort_order: Optional[str], default=None):
|
|
|
+ if default is None:
|
|
|
+ default = BxInvoice.create_time.desc()
|
|
|
+ return resolve_datetime_order_by(sort_field, sort_order, INVOICE_WHITELIST, default)
|
|
|
+
|
|
|
+
|
|
|
+def order_ledger(sort_field: Optional[str], sort_order: Optional[str], default=None):
|
|
|
+ if default is None:
|
|
|
+ default = BxInvoiceLedger.create_time.desc()
|
|
|
+ return resolve_datetime_order_by(sort_field, sort_order, LEDGER_WHITELIST, default)
|
|
|
+
|
|
|
+
|
|
|
+def parse_sort_params(params: dict) -> tuple:
|
|
|
+ """从 request/body dict 取 sortField/sortOrder(兼容 snake)。"""
|
|
|
+ sf = params.get("sortField") or params.get("sort_field")
|
|
|
+ so = params.get("sortOrder") or params.get("sort_order")
|
|
|
+ return (str(sf).strip() if sf else None), (str(so).strip() if so else None)
|