Files
shanxia2.0/backend/app/services/pl/plan_column_facet_context.py
T
wuzilongandCursor 6a8cd90b98 feat: cascade column facet options by current list context
Make dynamic column-facet values respect other active filters (Excel-style), with backend facet context helpers, list-page wiring, slip print/sidebar fixes, and refreshed graphify graphs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 22:04:20 +08:00

112 lines
2.9 KiB
Python

"""运输计划列头 facet:从上下文参数中剥离当前列自身条件(Excel 语义)。"""
from __future__ import annotations
from typing import Dict, MutableMapping, Set
_FIELD_ALIASES = {
"loadCustomers": "loadCustomer",
"deliveryCustomers": "deliveryCustomer",
"contractNo": "productContract",
"productPackageSpec": "packageSpec",
}
_FIELD_KEYS: Dict[str, Set[str]] = {
"planNo": {"planNo", "planNoIn", "plan_no", "plan_no_in"},
"licensePlate": {
"licensePlate",
"licensePlateIn",
"license_plate",
"license_plate_in",
},
"carrierName": {
"carrierName",
"carrierNameIn",
"carrier_name",
"carrier_name_in",
},
"loadCustomer": {
"loadCustomer",
"loadCustomerIn",
"loadCustomers",
"loadCustomersIn",
"load_customers",
"load_customers_in",
"stopCustomers",
"stop_customers",
"customerKeyword",
"customer_keyword",
},
"deliveryCustomer": {
"deliveryCustomer",
"deliveryCustomerIn",
"deliveryCustomers",
"deliveryCustomersIn",
"delivery_customers",
"delivery_customers_in",
"stopCustomers",
"stop_customers",
"customerKeyword",
"customer_keyword",
},
"productContract": {
"productContract",
"productContractIn",
"contractNo",
"contractNoIn",
"contract_no",
"contract_no_in",
"stopKind",
"stopKindIn",
"stop_kind",
"stop_kind_in",
},
"productName": {
"productName",
"productNameIn",
"product_name",
"product_name_in",
},
"productSpec": {
"productSpec",
"productSpecIn",
"product_spec",
"product_spec_in",
},
"packageSpec": {
"packageSpec",
"packageSpecIn",
"package_spec",
"package_spec_in",
"productPackageSpec",
"productPackageSpecIn",
},
"productUnit": {
"productUnit",
"productUnitIn",
"product_unit",
"product_unit_in",
},
"gapType": {"gapType", "gapTypeIn", "gap_type"},
}
def _keys_for_field(field: str) -> Set[str]:
f = _FIELD_ALIASES.get((field or "").strip(), (field or "").strip())
keys = _FIELD_KEYS.get(f)
if keys:
return set(keys)
snake = "".join(["_" + c.lower() if c.isupper() else c for c in f]).lstrip("_")
return {f, f"{f}In", snake, f"{snake}_in"}
def strip_plan_facet_self_params(
params: MutableMapping[str, object], field: str
) -> Dict[str, object]:
"""返回去掉当前 facet 列对应过滤键后的新 dict(不修改入参)。"""
out = {k: v for k, v in params.items() if v not in (None, "")}
for key in _keys_for_field(field):
out.pop(key, None)
for meta in ("field", "keyword", "limit"):
out.pop(meta, None)
return out