按陆运线路叶子收窄工单和看板,避免中港权限看到全部陆运;产品/航线排名只留智能体团队。空运核对卡不再列出空的非必填,报价合计标明约数。中港口语里的车型吨位和按运费比例不再算进金额。报价单上传人显示机器人名,进后台拉标题不再误报没有权限。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
linmianxun
2026-11-08 11:44:31 +08:00
co-authored by Cursor
parent 246ae4607c
commit b878a094b5
24 changed files with 1125 additions and 78 deletions
+51 -1
View File
@@ -1086,6 +1086,29 @@ _RE_FEE_LINE = re.compile(
rf"\s*(?P<ccy2>{_CCY_TOKEN}|元)?",
re.I,
)
# 中港陆运口语:「深圳--香港元朗运费10T:1700HKD/车」——车型吨位不是金额。
# 必须先于普通费用行,否则会抽成运费=10(WO202610300015)。
_RE_FEE_VEHICLE_PRICE = re.compile(
r"(?P<name>[\u4e00-\u9fffA-Za-z][\u4e00-\u9fffA-Za-z0-9/()()++\--]{0,24}费)"
r"\s*(?:改为|改成|调整为|调整成)?"
r"\s*[::=]?"
r"\s*(?P<label>\d+(?:\.\d+)?\s*(?:T|吨|HQ|GP|尺))"
r"\s*[::=]?\s*"
rf"(?:(?P<ccy1>{_CCY_TOKEN})\s*)?"
r"(?P<amount>\d+(?:\.\d+)?)"
rf"\s*(?P<ccy2>{_CCY_TOKEN}|元)?"
r"(?:\s*/\s*车)?",
re.I,
)
# 金额后紧跟车型单位:该数字是吨位/柜型,不是费用金额。
_RE_AMOUNT_IS_VEHICLE_UNIT = re.compile(r"^\s*(?:T|吨|HQ|GP|尺)\b", re.I)
# 「压夜按运费80%」「压日按运费100%」是比例,禁止落成 HKD 80/100 再加进合计。
_RE_FEE_OF_FREIGHT_PCT = re.compile(
r"(?P<name>[\u4e00-\u9fff]{1,8}按运费|[\u4e00-\u9fffA-Za-z][\u4e00-\u9fffA-Za-z0-9/()()++\--]{0,16}费)"
r"\s*[::=]?\s*"
r"(?P<amount>\d+(?:\.\d+)?)\s*%",
re.I,
)
# 多段报价「段1:」「第一段」只是段号,数字不能当费用金额。
_RE_SEGMENT_INDEX_LABEL = re.compile(
r"(?:段\s*\d+\s*[::]?|第\s*[一二三四五六七八九\d]+\s*段\s*[::]?)",
@@ -1366,6 +1389,8 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
只认带「费」的中文名或短英文费用码,避免把工单号当金额。
句里无币种时继承 baseline_currency(通常是当前 TMS/主账币种),禁止默认 USD。
认「费名, KG, 单价…」与「费名_板,单价…」里的计量单位,写入 unit,禁止出单再默认「票」。
「运费10T:1700HKD」先认车型价,禁止把吨位 10 当成运费金额。
「压夜按运费80%」金额带 %,禁止当绝对金额加进合计。
"""
project, body = _split_fee_project_prefix(text or "")
raw = _ascii_amount(body)
@@ -1395,6 +1420,23 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
row[key] = val
rows.append(row)
# 先认「运费10T:1700」——车型价;再认「按运费80%」比例;最后才普通金额行。
for hit in _RE_FEE_VEHICLE_PRICE.finditer(raw):
label = (hit.group("label") or "").strip().replace(" ", "")
_add(
(hit.group("name") or "").strip(),
_ascii_amount(hit.group("amount") or ""),
hit.group("ccy1") or hit.group("ccy2") or "",
unit="车",
vehicle=label,
unit_price=_ascii_amount(hit.group("amount") or ""),
)
for hit in _RE_FEE_OF_FREIGHT_PCT.finditer(raw):
name = (hit.group("name") or "").strip()
amt = _ascii_amount(hit.group("amount") or "")
if not name or not amt:
continue
_add(name, f"{amt}%", "")
priced_hits = 0
for hit in _RE_FEE_PRICED.finditer(raw):
priced_hits += 1
@@ -1427,9 +1469,17 @@ def _parse_fee_rows(text: str, baseline_currency: str = "") -> list[dict[str, st
quantity=quantity,
)
for hit in _RE_FEE_LINE.finditer(raw):
amount = _ascii_amount(hit.group("amount") or "")
after_amount = raw[hit.end("amount") :]
# 吨位/柜型数字不能当金额(运费10T:… 已被车型价规则吃掉;这里再挡漏网)。
if _RE_AMOUNT_IS_VEHICLE_UNIT.match(after_amount):
continue
# 「80%」保留百分号,合计时只加绝对金额。
if re.match(r"\s*%", after_amount or ""):
amount = f"{amount}%"
_add(
(hit.group("name") or "").strip(),
_ascii_amount(hit.group("amount") or ""),
amount,
hit.group("ccy1") or hit.group("ccy2") or "",
)
for hit in _RE_FEE_CHANGE.finditer(raw):
+3 -2
View File
@@ -102,10 +102,11 @@ def air_price_lines(
facts: dict[str, str] | None = None,
) -> list[str]:
"""
TMS 价格段:费用行、备注、费用合计、报价有效期。
TMS 价格段:费用行、备注、费用合计约、报价有效期。
有单价且有计价单位:单价CNY11/KG。按票:CNY300/票。只有金额:CNY 100.0。
备注每次都有,TMS 没带回就「-」。不写时效。
合计是预估,不等于最终费用,所以文字里写「费用合计约」。卡片引用条仍叫费用合计。
"""
from agent.policy.inquiry_copy import money_text, tms_valid_until_display
@@ -115,7 +116,7 @@ def air_price_lines(
lines = [line for line in lines if line]
lines.append(f"备注:{_remark_display(src, facts)}")
total = money_text(str(src.get("total") or "-").strip() or "-", header_ccy)
lines.append(f"费用合计:{total}")
lines.append(f"费用合计约:{total}")
lines.append(f"报价有效期:{tms_valid_until_display(src)}")
return lines
+13 -6
View File
@@ -578,23 +578,30 @@ def air_confirm_card(facts: dict[str, str] | None) -> str:
"""
确定查价前的核对卡。没有工单号。
起运地(非必填)紧挨在目的地(必填)上面。
报价日期说了写成「报价日期:日期」;没说写成「报价日期(非必填):」,不填当天。
必填项一律列出(方便核对)。非必填与报价日期:有识别结果才展示,空着不占行。
起运地有值时紧挨在目的地上面。报价日期没说不填当天、也不出空行。
"""
src = dict(facts or {})
lines = ["运输方式(必填):空运"]
lines.append(_air_field_line("起运港", _air_known_value(src, "起运港"), required=False))
origin_val = _air_known_value(src, "起运港")
if origin_val:
lines.append(_air_field_line("起运港", origin_val, required=False))
for key, _label in AIR_REQUIRED_FIELDS:
if key == "报价日期":
val = _air_known_value(src, key)
# 说了日期就只写日期;没说标明非必填并留空,禁止写成当天。
lines.append(f"报价日期:{val}" if val else "报价日期(非必填):")
# 说了才展示;没说不占行、不填当天(产品:空非必填不显示)。
if val:
lines.append(f"报价日期:{val}")
continue
lines.append(_air_field_line(key, _air_known_value(src, key), required=True))
for key, _label in AIR_OPTIONAL_FIELDS:
if key == "起运港":
continue
lines.append(_air_field_line(key, _air_known_value(src, key), required=False))
opt_val = _air_known_value(src, key)
if not opt_val:
continue
opt_line = _air_field_line(key, opt_val, required=False)
lines.append(opt_line)
lines.append("")
lines.append(AIR_CONFIRM_TAIL)
return "\n".join(lines)