"""操作日志路径推断(中间件落库与查询兜底)""" from __future__ import annotations import re from typing import List, Tuple _ACTION_TYPE_MAP = { "add": 1, "create": 1, "insert": 1, "update": 2, "edit": 2, "modify": 2, "delete": 3, "remove": 3, "export": 5, "import": 6, "transfer": 2, "intopool": 2, "deal": 2, "claim": 2, "release": 2, "invalid": 2, "assign": 2, "sign": 2, "renew": 1, } _MODULE_TITLE_RULES: List[Tuple[re.Pattern[str], str]] = [ (re.compile(r"/crm/customer", re.I), "CRM客户管理"), (re.compile(r"/crm/contact", re.I), "CRM联系人"), (re.compile(r"/crm/opportunity", re.I), "CRM商机管理"), (re.compile(r"/crm/contract", re.I), "CRM合同管理"), (re.compile(r"/crm/invoice-info", re.I), "CRM开票信息"), (re.compile(r"/crm/", re.I), "CRM管理"), (re.compile(r"/web/admin/", re.I), "系统管理"), (re.compile(r"/web/auth/", re.I), "认证授权"), (re.compile(r"/web/monitor/", re.I), "系统监控"), ] def title_from_path(path: str) -> str: for pattern, title in _MODULE_TITLE_RULES: if pattern.search(path or ""): return title parts = [p for p in (path or "").split("/") if p] return parts[-1] if parts else "操作日志" def business_type_from_path(path: str, http_method: str) -> int: parts = [p for p in (path or "").split("/") if p] if parts: last = parts[-1].lower() if last in _ACTION_TYPE_MAP: return _ACTION_TYPE_MAP[last] method = (http_method or "").upper() if method == "POST": return 1 if method in ("PUT", "PATCH"): return 2 if method == "DELETE": return 3 return 0