落地私聊空运询价与TMS报价回填,按后台模板出单。
查到价后把币种、单位、数量、单价、备注写入报价单,避免销售只看到光秃秃的金额。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -35,6 +35,8 @@ class TemplateEntry:
|
||||
mapping_json: str = ""
|
||||
biz_type: str = ""
|
||||
category: str = ""
|
||||
keywords: tuple[str, ...] = ()
|
||||
is_default: bool = False
|
||||
|
||||
|
||||
def local_cache_dir() -> Path:
|
||||
@@ -93,6 +95,8 @@ def entries_from_ledger_response(resp: LedgerResponse) -> list[TemplateEntry]:
|
||||
mapping_json=str(it.get("mappingJson") or ""),
|
||||
biz_type=str(it.get("bizType") or ""),
|
||||
category=str(it.get("category") or ""),
|
||||
keywords=tuple(str(x) for x in (it.get("keywords") or []) if str(x).strip()),
|
||||
is_default=bool(it.get("isDefault")),
|
||||
)
|
||||
)
|
||||
return out
|
||||
@@ -160,22 +164,35 @@ def registry_as_dicts() -> list[dict[str, Any]]:
|
||||
def pick_template_for_biz(
|
||||
*,
|
||||
biz_type: str,
|
||||
facts: Optional[dict[str, Any]] = None,
|
||||
quote: Optional[dict[str, Any]] = None,
|
||||
keywords: Optional[list[str]] = None,
|
||||
entries: Optional[list[TemplateEntry]] = None,
|
||||
) -> Optional[TemplateEntry]:
|
||||
"""
|
||||
按业务线 + 关键词挑选模板(优先 is_default 由主账排序保证)。
|
||||
按询价需求匹配模板关键词;都未命中则同业务默认模板。
|
||||
|
||||
关键词命中任一即优;否则同 biz 第一条。
|
||||
keywords 入参已废弃(兼容旧调用,忽略)。生产出单以主账 render 为准。
|
||||
"""
|
||||
_ = keywords
|
||||
from agent.quote_templates.match import pick_quote_template
|
||||
|
||||
items = entries if entries is not None else list_template_registry()
|
||||
same = [e for e in items if (e.biz_type == biz_type or not e.biz_type)]
|
||||
if not same:
|
||||
same = list(items)
|
||||
if keywords:
|
||||
kw_l = [k.lower() for k in keywords if k]
|
||||
for e in same:
|
||||
blob = f"{e.filename} {e.category} {e.code}".lower()
|
||||
if any(k in blob for k in kw_l):
|
||||
return e
|
||||
return same[0] if same else None
|
||||
rows = [
|
||||
{
|
||||
"templateId": e.template_id or e.code,
|
||||
"name": e.filename or e.code,
|
||||
"bizType": e.biz_type,
|
||||
"keywords": list(e.keywords),
|
||||
"isDefault": e.is_default,
|
||||
"_entry": e,
|
||||
}
|
||||
for e in items
|
||||
]
|
||||
hit = pick_quote_template(
|
||||
templates=rows, business_line=biz_type, facts=facts, quote=quote
|
||||
)
|
||||
if hit is None:
|
||||
return None
|
||||
entry = hit.raw.get("_entry")
|
||||
return entry if isinstance(entry, TemplateEntry) else None
|
||||
|
||||
Reference in New Issue
Block a user