checkpoint: 提交当前工作区代码(同义词配置初版 + 既有流程改动)
- 新增 inq_synonym 表、62组同义词种子与智能体只读接口 - Python 同义词加载/归一化与 1板/2箱 机读 - 同步当前分支既有协作、报价识别、陆运等改动
This commit is contained in:
@@ -15,6 +15,7 @@ from agent.schema.quote_adjust import (
|
||||
adjustable_rows,
|
||||
apply_adjust,
|
||||
extract_adjust,
|
||||
inspect_adjust_recognition,
|
||||
private_session_can_adjust,
|
||||
quote_fee_rows,
|
||||
)
|
||||
@@ -158,9 +159,92 @@ def try_private_adjust(
|
||||
if not session_quoted(sess):
|
||||
return None
|
||||
names = [str(r.get("name") or "") for r in adjustable_rows(getattr(sess, "quote", None))]
|
||||
# 产品 2026-11-24:调价先回识别回执;这里接「确认/确定」并真正改价。
|
||||
from agent.policy.quote_confirm import is_confirm_text, quote_confirm_enabled
|
||||
from agent.redis_coord.pending_quote_confirm import (
|
||||
clear_pending_confirm,
|
||||
load_pending_confirm,
|
||||
)
|
||||
|
||||
if quote_confirm_enabled():
|
||||
no = str(getattr(sess, "work_order_no", "") or "")
|
||||
pending = load_pending_confirm(no)
|
||||
if pending.get("kind") == "adjust" and is_confirm_text(text):
|
||||
if str(getattr(sess, "sender_id", "") or "") != str(
|
||||
pending.get("sender_id") or ""
|
||||
):
|
||||
reply(copy.adjust_confirm_not_allowed())
|
||||
return "adjust_confirm_not_allowed"
|
||||
clear_pending_confirm(no)
|
||||
confirmed = extract_adjust(
|
||||
text, injected=pending.get("adjust") or {}, allow_model=False
|
||||
)
|
||||
return _apply_private_adjust(flow, sess, confirmed, reply, names)
|
||||
extract = extract_adjust(text, fee_names=names, injected=injected_adjust)
|
||||
# 调价也走分级提示:只说了费用名没说幅度、只说了幅度没点名费用,
|
||||
# 或「改成」后面没写值,都先回「我识别内容为…」;完全不像调价才让原流程继续。
|
||||
attempt = inspect_adjust_recognition(text, extract, fee_names=names)
|
||||
if attempt is not None and attempt["status"] in {"partial", "none"}:
|
||||
reason = private_session_can_adjust(
|
||||
str(getattr(sess, "status", "") or ""),
|
||||
bool(quote_fee_rows(getattr(sess, "quote", None))),
|
||||
str(getattr(sess, "collab_chat_id", "") or ""),
|
||||
)
|
||||
if reason:
|
||||
reply(copy.adjust_ineligible(reason))
|
||||
return "adjust_blocked"
|
||||
if attempt["status"] == "partial":
|
||||
reply(copy.adjust_partial_recognized(attempt["recognized"], attempt["missing"]))
|
||||
return "adjust_partial_recognized"
|
||||
reply(copy.adjust_not_recognized())
|
||||
return "adjust_not_recognized"
|
||||
if not extract.is_adjust:
|
||||
return None
|
||||
# 产品 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():
|
||||
payload = _adjust_payload(extract)
|
||||
save_pending_confirm(
|
||||
str(getattr(sess, "work_order_no", "") or ""),
|
||||
{
|
||||
"kind": "adjust",
|
||||
"adjust": payload,
|
||||
"text": text,
|
||||
"line": str(getattr(sess, "business_line", "") or ""),
|
||||
"sender_id": str(getattr(sess, "sender_id", "") or ""),
|
||||
},
|
||||
)
|
||||
reply(
|
||||
copy.adjust_confirm_receipt(
|
||||
payload.get("items") or [],
|
||||
work_order_no=str(getattr(sess, "work_order_no", "") or ""),
|
||||
)
|
||||
)
|
||||
return "adjust_confirm_pending"
|
||||
return _apply_private_adjust(flow, sess, extract, reply, names)
|
||||
|
||||
|
||||
def _adjust_payload(extract: Any) -> dict[str, Any]:
|
||||
"""把 AdjustExtract 收成可落 Redis 的 JSON。"""
|
||||
return {
|
||||
"is_adjust": bool(getattr(extract, "is_adjust", False)),
|
||||
"wants_total": bool(getattr(extract, "wants_total", False)),
|
||||
"items": [
|
||||
{
|
||||
"fee_name": str(getattr(it, "fee_name", "") or ""),
|
||||
"kind": str(getattr(it, "kind", "") or "percent"),
|
||||
"direction": str(getattr(it, "direction", "") or "up"),
|
||||
"value": float(getattr(it, "value", 0) or 0),
|
||||
}
|
||||
for it in (getattr(extract, "items", None) or [])
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def _apply_private_adjust(flow: Any, sess: Any, extract: Any, reply, names: list[str]) -> Optional[str]:
|
||||
"""私聊调价真正改价:资格、算价、写主账、出新卡。确认前后共用。"""
|
||||
reason = private_session_can_adjust(
|
||||
str(getattr(sess, "status", "") or ""),
|
||||
bool(quote_fee_rows(getattr(sess, "quote", None))),
|
||||
@@ -228,6 +312,149 @@ def try_private_adjust(
|
||||
return "wait_collab"
|
||||
|
||||
|
||||
def _apply_group_adjust_math(
|
||||
*,
|
||||
flow: Any,
|
||||
ticket: object,
|
||||
no: str,
|
||||
view: dict[str, Any],
|
||||
current: dict[str, Any],
|
||||
names: list[str],
|
||||
extract: Any,
|
||||
sess: Any,
|
||||
sender_id: str,
|
||||
room: str,
|
||||
client: Any,
|
||||
) -> str:
|
||||
"""群内调价真正改价:算价、写主账、发全量文本 + 成交跟进。确认前后共用。"""
|
||||
from agent.policy.sea_group_ops import (
|
||||
_save_product_quote,
|
||||
emit_group_deal,
|
||||
send_group_text,
|
||||
ticket_view,
|
||||
)
|
||||
|
||||
result = apply_adjust(
|
||||
current,
|
||||
extract,
|
||||
business_line=str(view.get("business_line") or getattr(sess, "business_line", "") or ""),
|
||||
tms_cost=_baselines(current)[0],
|
||||
tms_sale=_baselines(current)[1],
|
||||
)
|
||||
if result.code == "need_fee":
|
||||
send_group_text(client, room, copy.adjust_need_fee())
|
||||
return "adjust_need_fee"
|
||||
if result.code == "need_lines":
|
||||
send_group_text(client, room, copy.adjust_need_lines())
|
||||
return "adjust_need_lines"
|
||||
if result.code == "none_matched":
|
||||
send_group_text(client, room, copy.adjust_unmatched(result.unmatched, names))
|
||||
return "adjust_none"
|
||||
if not result.ok:
|
||||
send_group_text(client, room, copy.adjust_unmatched(result.unmatched or ["该项"], names))
|
||||
return "adjust_none"
|
||||
copy.remember_tms_quote(sess, current)
|
||||
_save_product_quote(
|
||||
flow,
|
||||
no,
|
||||
result.quote,
|
||||
sess,
|
||||
remark=copy.adjust_ledger_remark(result.applied),
|
||||
kind="adjust",
|
||||
sender_id=sender_id,
|
||||
)
|
||||
ticket2 = ticket_view(ticket)
|
||||
ticket2["quote"] = result.quote
|
||||
ticket2["status"] = "已报价"
|
||||
ticket2["work_order_no"] = no
|
||||
parts = [copy.adjust_confirm(result.applied)]
|
||||
if result.unmatched:
|
||||
parts.append(copy.adjust_unmatched(result.unmatched, [str(r.get("name") or "") for r in quote_fee_rows(result.quote)]))
|
||||
if result.lines_hint:
|
||||
parts.append(copy.adjust_need_lines())
|
||||
if result.currency_hint:
|
||||
parts.append(copy.adjust_currency_hint())
|
||||
line = str(view.get("business_line") or getattr(sess, "business_line", "") or "SEA")
|
||||
parts.append(copy.adjust_group_body(result.quote, business_line=line))
|
||||
send_group_text(client, room, "\n".join(parts))
|
||||
# 调价只更新文字与成交跟进;Excel/PDF 等「生成报价单」指令。
|
||||
emit_group_deal(flow=flow, ticket=ticket2, sess=sess, quote=result.quote)
|
||||
logger.info("group_adjust wo=%s applied=%s", no, [x.get("name") for x in result.applied])
|
||||
return "group_adjusted"
|
||||
|
||||
|
||||
def confirm_pending_group_adjust(
|
||||
flow: Any,
|
||||
ticket: object,
|
||||
message: Any,
|
||||
sess: Any = None,
|
||||
) -> str:
|
||||
"""
|
||||
群里成员 @机器人 回「确认/确定」:把待确认的调价真正改价。
|
||||
|
||||
发起调价的销售本人,或产品/航线岗可以确认。
|
||||
"""
|
||||
from agent.policy.quote_confirm import (
|
||||
can_confirm_adjust,
|
||||
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 ""
|
||||
from agent.policy.sea_group_ops import (
|
||||
_current_quote,
|
||||
group_client_of,
|
||||
hydrate_ticket,
|
||||
send_group_text,
|
||||
ticket_no,
|
||||
ticket_status,
|
||||
ticket_view,
|
||||
)
|
||||
|
||||
ticket = hydrate_ticket(flow, ticket)
|
||||
no = ticket_no(ticket)
|
||||
pending = load_pending_confirm(no)
|
||||
if not pending or pending.get("kind") != "adjust":
|
||||
return ""
|
||||
text = getattr(message, "content", "") or ""
|
||||
if not is_confirm_text(text):
|
||||
return ""
|
||||
sender_id = getattr(message, "sender_id", "") or ""
|
||||
room = getattr(message, "chat_id", "") or ""
|
||||
client = group_client_of(flow)
|
||||
if not can_confirm_adjust(
|
||||
flow, ticket, sender_id, pending_sender=str(pending.get("sender_id") or "")
|
||||
):
|
||||
send_group_text(client, room, copy.adjust_confirm_not_allowed())
|
||||
return "adjust_confirm_not_allowed"
|
||||
if ticket_status(ticket) not in {"已报价", "协商中"}:
|
||||
send_group_text(client, room, copy.adjust_ineligible("no_quote"))
|
||||
return "adjust_blocked"
|
||||
clear_pending_confirm(no)
|
||||
view = ticket_view(ticket)
|
||||
current = _current_quote(view, sess)
|
||||
names = [str(r.get("name") or "") for r in adjustable_rows(current)]
|
||||
extract = extract_adjust(text, injected=pending.get("adjust") or {}, allow_model=False)
|
||||
return _apply_group_adjust_math(
|
||||
flow=flow,
|
||||
ticket=ticket,
|
||||
no=no,
|
||||
view=view,
|
||||
current=current,
|
||||
names=names,
|
||||
extract=extract,
|
||||
sess=sess,
|
||||
sender_id=sender_id,
|
||||
room=room,
|
||||
client=client,
|
||||
)
|
||||
|
||||
|
||||
def apply_group_adjust(
|
||||
*,
|
||||
flow: Any,
|
||||
@@ -283,51 +510,55 @@ def apply_group_adjust(
|
||||
current = _current_quote(view, sess)
|
||||
names = [str(r.get("name") or "") for r in adjustable_rows(current)]
|
||||
extract = extract_adjust(text, fee_names=names, injected=injected_adjust)
|
||||
# 调价分级提示:部分识别先回「我识别内容为…」,完全不像调价才静默。
|
||||
attempt = inspect_adjust_recognition(text, extract, fee_names=names)
|
||||
if attempt is not None and attempt["status"] in {"partial", "none"}:
|
||||
if attempt["status"] == "partial":
|
||||
send_group_text(
|
||||
client,
|
||||
room,
|
||||
copy.adjust_partial_recognized(
|
||||
attempt["recognized"], attempt["missing"]
|
||||
),
|
||||
)
|
||||
return "adjust_partial_recognized"
|
||||
send_group_text(client, room, copy.adjust_not_recognized())
|
||||
return "adjust_not_recognized"
|
||||
if not extract.is_adjust:
|
||||
return "not_adjust"
|
||||
result = apply_adjust(
|
||||
current,
|
||||
extract,
|
||||
business_line=str(view.get("business_line") or getattr(sess, "business_line", "") or ""),
|
||||
tms_cost=_baselines(current)[0],
|
||||
tms_sale=_baselines(current)[1],
|
||||
# 产品 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():
|
||||
payload = _adjust_payload(extract)
|
||||
save_pending_confirm(
|
||||
no,
|
||||
{
|
||||
"kind": "adjust",
|
||||
"adjust": payload,
|
||||
"text": text,
|
||||
"line": str(view.get("business_line") or ""),
|
||||
"sender_id": sender_id,
|
||||
"chat_id": room,
|
||||
},
|
||||
)
|
||||
send_group_text(
|
||||
client,
|
||||
room,
|
||||
copy.adjust_confirm_receipt(payload.get("items") or [], work_order_no=no),
|
||||
)
|
||||
return "adjust_confirm_pending"
|
||||
return _apply_group_adjust_math(
|
||||
flow=flow,
|
||||
ticket=ticket,
|
||||
no=no,
|
||||
view=view,
|
||||
current=current,
|
||||
names=names,
|
||||
extract=extract,
|
||||
sess=sess,
|
||||
sender_id=sender_id,
|
||||
room=room,
|
||||
client=client,
|
||||
)
|
||||
if result.code == "need_fee":
|
||||
send_group_text(client, room, copy.adjust_need_fee())
|
||||
return "adjust_need_fee"
|
||||
if result.code == "need_lines":
|
||||
send_group_text(client, room, copy.adjust_need_lines())
|
||||
return "adjust_need_lines"
|
||||
if result.code == "none_matched":
|
||||
send_group_text(client, room, copy.adjust_unmatched(result.unmatched, names))
|
||||
return "adjust_none"
|
||||
if not result.ok:
|
||||
send_group_text(client, room, copy.adjust_unmatched(result.unmatched or ["该项"], names))
|
||||
return "adjust_none"
|
||||
copy.remember_tms_quote(sess, current)
|
||||
_save_product_quote(
|
||||
flow,
|
||||
no,
|
||||
result.quote,
|
||||
sess,
|
||||
remark=copy.adjust_ledger_remark(result.applied),
|
||||
kind="adjust",
|
||||
)
|
||||
ticket2 = ticket_view(ticket)
|
||||
ticket2["quote"] = result.quote
|
||||
ticket2["status"] = "已报价"
|
||||
ticket2["work_order_no"] = no
|
||||
parts = [copy.adjust_confirm(result.applied)]
|
||||
if result.unmatched:
|
||||
parts.append(copy.adjust_unmatched(result.unmatched, [str(r.get("name") or "") for r in quote_fee_rows(result.quote)]))
|
||||
if result.lines_hint:
|
||||
parts.append(copy.adjust_need_lines())
|
||||
if result.currency_hint:
|
||||
parts.append(copy.adjust_currency_hint())
|
||||
line = str(view.get("business_line") or getattr(sess, "business_line", "") or "SEA")
|
||||
parts.append(copy.adjust_group_body(result.quote, business_line=line))
|
||||
send_group_text(client, room, "\n".join(parts))
|
||||
# 调价只更新文字与成交跟进;Excel/PDF 等「生成报价单」指令。
|
||||
emit_group_deal(flow=flow, ticket=ticket2, sess=sess, quote=result.quote)
|
||||
logger.info("group_adjust wo=%s applied=%s", no, [x.get("name") for x in result.applied])
|
||||
return "group_adjusted"
|
||||
|
||||
Reference in New Issue
Block a user