checkpoint: 提交当前工作区代码(同义词配置初版 + 既有流程改动)
- 新增 inq_synonym 表、62组同义词种子与智能体只读接口 - Python 同义词加载/归一化与 1板/2箱 机读 - 同步当前分支既有协作、报价识别、陆运等改动
This commit is contained in:
@@ -205,11 +205,20 @@ def apply_multi_file(
|
||||
client = group_client_of(flow)
|
||||
name = (filename or "").strip()
|
||||
if not filename_is_excel_pdf(name):
|
||||
# 与海运/空运同口径(2026-11-19 真机):文件名不带工单号的非 Excel/PDF 一律静默,
|
||||
# 避免群里随手丢个 Word/zip 就被机器搭话;带号才提示一句。
|
||||
# 2026-11-21:本次指令明确 @ 过机器人时也一定提示(附件的本体仍不入库)。
|
||||
# 产品 2026-11-24:图片/其它文件不能读,按「无法识别」提示用文字重报。
|
||||
if explicit or copy.extract_work_order_no(name or ""):
|
||||
send_group_text(client, room, copy.group_only_excel_pdf())
|
||||
from agent.policy.quote_confirm import sender_display_name
|
||||
|
||||
line = str(sender_mode(flow, sender_id) or "").upper()
|
||||
send_group_text(
|
||||
client,
|
||||
room,
|
||||
copy.quote_not_recognized(
|
||||
business_line=line,
|
||||
at_name=sender_display_name(flow, ticket, sender_id),
|
||||
text_format=True,
|
||||
),
|
||||
)
|
||||
else:
|
||||
logger.info("multi_file_type_silent wo=%s file=%s", no or "-", (name or "")[:80])
|
||||
return "file_type_rejected"
|
||||
@@ -240,6 +249,100 @@ def apply_multi_file(
|
||||
quote=quote,
|
||||
sheet_fn=None,
|
||||
skip_sheet=True,
|
||||
sender_id=sender_id,
|
||||
)
|
||||
|
||||
|
||||
def _segment_note(segment: Segment, text: str) -> str:
|
||||
"""多段群回执前缀:让产品知道这句提示说的是哪一段。"""
|
||||
return f"段{segment.index}:{segment.word()}\n{text}"
|
||||
|
||||
|
||||
def _save_raw_segment_quote(
|
||||
*, flow: Any, ticket: object, segment: Segment, text: str, sender_id: str = ""
|
||||
) -> None:
|
||||
"""
|
||||
非话术/全无:原话按段落档,进「原始报价参考」,六态保持询价中。
|
||||
|
||||
不写 total/fee_rows,_has_money 为假,不会把这一段当已报价;
|
||||
后续产品重报标准价时同一段会被覆盖。副作用:写主账。线程:Worker。
|
||||
"""
|
||||
no = ticket_no(ticket)
|
||||
stored = segment_quotes(ticket)
|
||||
raw = (text or "").strip()
|
||||
stored[segment.mode] = {"raw_text": raw, "source_label": "产品群原话"}
|
||||
payload = {
|
||||
"segment_quotes": stored,
|
||||
"source_label": "分段报价",
|
||||
"raw_text": raw,
|
||||
"raw_source": "nonstandard",
|
||||
"deal_version": int(
|
||||
dict(ticket_view(ticket).get("quote") or {}).get("deal_version") or 0
|
||||
),
|
||||
}
|
||||
writer = getattr(flow.ledger, "upsert_product_quote", None)
|
||||
if not callable(writer):
|
||||
return
|
||||
try:
|
||||
writer(
|
||||
work_order_no=no,
|
||||
quote=payload,
|
||||
to_status="询价中",
|
||||
remark="分段原话",
|
||||
kind="product",
|
||||
raw_text=text,
|
||||
raw_source="nonstandard",
|
||||
sender_id=sender_id,
|
||||
)
|
||||
except TypeError:
|
||||
writer(work_order_no=no, quote=payload, to_status="询价中")
|
||||
|
||||
|
||||
def confirm_pending_multi(
|
||||
*, flow: Any, ticket: object, chat_id: str, sender_id: str, text: str
|
||||
) -> str:
|
||||
"""
|
||||
多段群成员 @机器人 回「确认/确定」:把待确认那一段报价正式落账。
|
||||
|
||||
返回空串表示不是确认/没有待确认,调用方继续原流程。
|
||||
"""
|
||||
from agent.policy.quote_confirm import (
|
||||
can_confirm_quote,
|
||||
is_confirm_text,
|
||||
quote_confirm_enabled,
|
||||
)
|
||||
from agent.redis_coord.pending_quote_confirm import (
|
||||
clear_pending_confirm,
|
||||
load_pending_confirm,
|
||||
)
|
||||
|
||||
if not quote_confirm_enabled():
|
||||
return ""
|
||||
no = ticket_no(ticket)
|
||||
pending = load_pending_confirm(no)
|
||||
if not pending or pending.get("kind") != "quote":
|
||||
return ""
|
||||
if not is_confirm_text(text or ""):
|
||||
return ""
|
||||
seg_mode = str(pending.get("segment_mode") or pending.get("line") or "").upper()
|
||||
segments = load_segments(ticket)
|
||||
target = next((s for s in segments if str(s.mode).upper() == seg_mode), None)
|
||||
if target is None:
|
||||
return ""
|
||||
if not can_confirm_quote(flow, ticket, sender_id, business_line=seg_mode):
|
||||
send_group_text(group_client_of(flow), chat_id, "只有本单销售或产品/航线可以确认报价。")
|
||||
return "confirm_not_allowed"
|
||||
clear_pending_confirm(no)
|
||||
return _save_segment_quote(
|
||||
flow=flow,
|
||||
ticket=ticket,
|
||||
chat_id=chat_id,
|
||||
segment=target,
|
||||
segments=segments,
|
||||
quote=dict(pending.get("quote") or {}),
|
||||
sheet_fn=None,
|
||||
skip_sheet=True,
|
||||
sender_id=sender_id,
|
||||
)
|
||||
|
||||
|
||||
@@ -266,6 +369,11 @@ def handle_multi_inbound(
|
||||
if not segments:
|
||||
send_group_text(group_client_of(flow), room, f"工单{no}没有可报价的运输段。")
|
||||
return "multi_no_segments"
|
||||
confirmed = confirm_pending_multi(
|
||||
flow=flow, ticket=ticket, chat_id=room, sender_id=sender_id, text=text or ""
|
||||
)
|
||||
if confirmed:
|
||||
return confirmed
|
||||
only_no = copy.extract_work_order_no(text or "") == no and _only_work_order(text or "")
|
||||
if only_no or not (ticket_view(ticket).get("collab_chat_id") or ""):
|
||||
_bind_room(flow, ticket, room, sender_id)
|
||||
@@ -295,26 +403,147 @@ def handle_multi_inbound(
|
||||
baseline = _quote_currency_hint((segment_quotes(ticket) or {}).get(target.mode) or {})
|
||||
if not baseline:
|
||||
baseline = _quote_currency_hint(dict(ticket_view(ticket).get("quote") or {}))
|
||||
seg_mode = str(mode or "").upper()
|
||||
seg_transport = (
|
||||
"陆运" if seg_mode == "LAND" else ("空运" if seg_mode == "AIR" else "海运")
|
||||
)
|
||||
# 待确认期间改车型/税率/线路等字段,不能把数字当新报价。
|
||||
from agent.policy.quote_confirm import quote_confirm_enabled, sender_display_name
|
||||
from agent.policy.sea_group_ops import _is_group_field_correction
|
||||
from agent.redis_coord.pending_quote_confirm import load_pending_confirm
|
||||
|
||||
if quote_confirm_enabled():
|
||||
pending = load_pending_confirm(no)
|
||||
if (
|
||||
pending
|
||||
and pending.get("kind") == "quote"
|
||||
and _is_group_field_correction(text or "", seg_mode)
|
||||
):
|
||||
at_name = sender_display_name(flow, ticket, sender_id)
|
||||
prefix = f"@{at_name}\n" if at_name else ""
|
||||
send_group_text(
|
||||
group_client_of(flow),
|
||||
room,
|
||||
prefix + "请先确认上一条报价,或按标准格式重新报价。",
|
||||
)
|
||||
return "quote_pending_hint"
|
||||
quote = extract_product_quote(
|
||||
text or "",
|
||||
injected=injected_quote,
|
||||
business_line=str(mode or "").upper(),
|
||||
transport_mode=(
|
||||
"陆运" if str(mode or "").upper() == "LAND"
|
||||
else ("空运" if str(mode or "").upper() == "AIR" else "海运")
|
||||
),
|
||||
business_line=seg_mode,
|
||||
transport_mode=seg_transport,
|
||||
baseline_currency=baseline,
|
||||
)
|
||||
from agent.schema.quote_recognition import inspect_quote_recognition
|
||||
|
||||
recognition = inspect_quote_recognition(
|
||||
text or "",
|
||||
quote,
|
||||
business_line=seg_mode,
|
||||
transport_mode=seg_transport,
|
||||
facts=dict(getattr(target, "facts", {}) or {}) if target is not None else {},
|
||||
extra_facts=dict(fields),
|
||||
)
|
||||
from agent.policy.quote_confirm import sender_display_name
|
||||
|
||||
at_name = sender_display_name(flow, ticket, sender_id)
|
||||
client = group_client_of(flow)
|
||||
if not quote:
|
||||
if fields:
|
||||
return "multi_collab_saved"
|
||||
if is_sales(ticket, sender_id):
|
||||
return _maybe_deal(flow, ticket, sender_id, text)
|
||||
send_group_text(group_client_of(flow), room, copy.group_quote_not_recognized())
|
||||
return "quote_not_recognized"
|
||||
if target is None:
|
||||
# 对不上段时无法归段,只能整体提示重报,不写段价。
|
||||
send_group_text(
|
||||
client,
|
||||
room,
|
||||
copy.quote_not_recognized(business_line=seg_mode, at_name=at_name),
|
||||
)
|
||||
return "quote_raw_saved"
|
||||
# 非话术/全无:原话按段落档,六态保持询价中;再按段回识别回执。
|
||||
_save_raw_segment_quote(
|
||||
flow=flow, ticket=ticket, segment=target, text=text or "", sender_id=sender_id
|
||||
)
|
||||
if recognition["status"] == "partial":
|
||||
send_group_text(
|
||||
client,
|
||||
room,
|
||||
_segment_note(
|
||||
target,
|
||||
copy.quote_partial_recognized(
|
||||
recognition["recognized"],
|
||||
recognition["missing"],
|
||||
business_line=seg_mode,
|
||||
work_order_no=no,
|
||||
at_name=at_name,
|
||||
),
|
||||
),
|
||||
)
|
||||
return "quote_partial_saved"
|
||||
send_group_text(
|
||||
client,
|
||||
room,
|
||||
_segment_note(
|
||||
target,
|
||||
copy.quote_not_recognized(business_line=seg_mode, at_name=at_name),
|
||||
),
|
||||
)
|
||||
return "quote_raw_saved"
|
||||
if target is None:
|
||||
send_group_text(group_client_of(flow), room, "没有对上你负责的运输段,请让对应岗位报价。")
|
||||
send_group_text(client, room, "没有对上你负责的运输段,请让对应岗位报价。")
|
||||
return "quote_wrong_role"
|
||||
# 产品 2026-11-24:报价先回识别回执,成员@机器人回「确认/确定」后才落段价。
|
||||
from agent.policy.quote_confirm import quote_confirm_enabled
|
||||
from agent.redis_coord.pending_quote_confirm import save_pending_confirm
|
||||
|
||||
if quote_confirm_enabled():
|
||||
save_pending_confirm(
|
||||
no,
|
||||
{
|
||||
"kind": "quote",
|
||||
"quote": dict(quote),
|
||||
"raw_text": text or "",
|
||||
"raw_source": "text",
|
||||
"line": seg_mode,
|
||||
"segment_mode": seg_mode,
|
||||
"recognized": list(recognition["recognized"]),
|
||||
"chat_id": room,
|
||||
"sender_id": sender_id,
|
||||
},
|
||||
)
|
||||
send_group_text(
|
||||
client,
|
||||
room,
|
||||
_segment_note(
|
||||
target,
|
||||
copy.quote_partial_recognized(
|
||||
recognition["recognized"],
|
||||
[],
|
||||
business_line=seg_mode,
|
||||
work_order_no=no,
|
||||
at_name=at_name,
|
||||
),
|
||||
),
|
||||
)
|
||||
return "quote_confirm_pending"
|
||||
# 部分识别回执:先告诉产品识别到了什么,再落段价/发成交跟进,
|
||||
# 成交卡保持最新一条,不会被回执顶到上面。
|
||||
if recognition["status"] == "partial":
|
||||
send_group_text(
|
||||
client,
|
||||
room,
|
||||
_segment_note(
|
||||
target,
|
||||
copy.quote_partial_recognized(
|
||||
recognition["recognized"],
|
||||
recognition["missing"],
|
||||
business_line=seg_mode,
|
||||
work_order_no=no,
|
||||
at_name=at_name,
|
||||
),
|
||||
),
|
||||
)
|
||||
# 文字段报价:只落价,不自动发报价单;销售/商务/航线再说「生成报价单」。
|
||||
return _save_segment_quote(
|
||||
flow=flow,
|
||||
@@ -325,6 +554,7 @@ def handle_multi_inbound(
|
||||
quote=quote,
|
||||
sheet_fn=sheet_fn,
|
||||
skip_sheet=True,
|
||||
sender_id=sender_id,
|
||||
)
|
||||
|
||||
|
||||
@@ -390,6 +620,7 @@ def _save_segment_quote(
|
||||
quote: dict[str, Any],
|
||||
sheet_fn: Optional[SheetFn],
|
||||
skip_sheet: bool = False,
|
||||
sender_id: str = "",
|
||||
) -> str:
|
||||
"""写入这一段报价并发该段报价单。其他段未齐时不发成交跟进。"""
|
||||
no = ticket_no(ticket)
|
||||
@@ -415,6 +646,7 @@ def _save_segment_quote(
|
||||
to_status="已报价" if all_ready else "询价中",
|
||||
remark="分段报价",
|
||||
kind="product",
|
||||
sender_id=sender_id,
|
||||
)
|
||||
else:
|
||||
writer = getattr(flow.ledger, "upsert_quote", None)
|
||||
|
||||
Reference in New Issue
Block a user