后台成本价、销售价、利润点按费用逐行展示,费用合计用报价官方总价。选完线路只关页面。报价单文件名带上模板名,空运起运地和转人工跟对应工单走。
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -337,13 +337,134 @@ class AirTextInquiryFlow:
|
||||
self.drop_current_bookmark(sender_id)
|
||||
return None
|
||||
|
||||
def _handoff_flows(self) -> list[Any]:
|
||||
"""陆运、海运、空运各查自己的工单索引。当前流程放前面,避免单测实例对不上全局。"""
|
||||
from agent.policy.land_text_flow import get_land_text_flow
|
||||
from agent.policy.sea_text_flow import get_sea_text_flow
|
||||
|
||||
flows: list[Any] = [self]
|
||||
for flow in (get_land_text_flow(), get_sea_text_flow(), get_air_text_flow()):
|
||||
if all(flow is not item for item in flows):
|
||||
flows.append(flow)
|
||||
return flows
|
||||
|
||||
def _handoff_owner_for_line(self, line: str):
|
||||
"""
|
||||
转人工入口跟工单运输方式走,不跟当前私聊里的另一张单走。
|
||||
|
||||
空运、海运、陆运各用自己的流程收书签。对不上就返回空,不能默认成空运。
|
||||
"""
|
||||
from agent.policy.land_text_flow import LandTextInquiryFlow, get_land_text_flow
|
||||
from agent.policy.sea_text_flow import SeaTextInquiryFlow, get_sea_text_flow
|
||||
|
||||
code = (line or "").strip().upper()
|
||||
if code == "LAND":
|
||||
return self if isinstance(self, LandTextInquiryFlow) else get_land_text_flow()
|
||||
if code == "SEA":
|
||||
return (
|
||||
self
|
||||
if isinstance(self, SeaTextInquiryFlow)
|
||||
and not isinstance(self, LandTextInquiryFlow)
|
||||
else get_sea_text_flow()
|
||||
)
|
||||
if code == "AIR":
|
||||
return self if type(self) is AirTextInquiryFlow else get_air_text_flow()
|
||||
return None
|
||||
|
||||
def _offer_handoff_for_named_ticket(
|
||||
self,
|
||||
*,
|
||||
sender_id: str,
|
||||
work_order_no: str,
|
||||
text: str,
|
||||
reply: ReplyFn,
|
||||
) -> str:
|
||||
"""
|
||||
按原话里的工单号转人工。
|
||||
|
||||
有没有协同群只决定拦不拦。话术只看这张单是空运、海运还是陆运。
|
||||
销售私聊里另一张已建群的单,不能拿来拒绝,也不能拿来决定话术。
|
||||
副作用:命中后把这张单收到对应运输方式的转人工入口;读主账。不建群。
|
||||
"""
|
||||
from agent.policy.handoff_human import is_closed_for_handoff
|
||||
|
||||
no = (work_order_no or "").strip().upper()
|
||||
hit = None
|
||||
hit_flow = None
|
||||
for flow in self._handoff_flows():
|
||||
found = flow.session_by_ticket(sender_id, no)
|
||||
if found is None:
|
||||
continue
|
||||
hit = found
|
||||
hit_flow = flow
|
||||
break
|
||||
getter = getattr((hit_flow or self)._ledger, "get_for_agent", None)
|
||||
view: dict[str, Any] = {}
|
||||
if callable(getter):
|
||||
try:
|
||||
view = getter(work_order_no=no, sender_id=sender_id) or {}
|
||||
except Exception:
|
||||
logger.exception("转人工读主账失败 wo=%s", no)
|
||||
view = {}
|
||||
if view.get("found") and view.get("owned") is False:
|
||||
reply("这张工单不属于当前账号,不能转人工。")
|
||||
return "ticket_forbidden"
|
||||
if hit is not None and view.get("found"):
|
||||
# 主账上的运输方式和群号盖过进程里的旧书签。
|
||||
hit.collab_chat_id = str(view.get("collab_chat_id") or "").strip()
|
||||
if str(view.get("status") or "").strip():
|
||||
hit.status = str(view.get("status") or "").strip()
|
||||
if str(view.get("business_line") or "").strip():
|
||||
hit.business_line = str(view.get("business_line") or "").strip().upper()
|
||||
if hit is None:
|
||||
if not callable(getter):
|
||||
reply(f"找不到工单 {no},请核对工单号后再试。")
|
||||
return "ticket_missing"
|
||||
if not view.get("found"):
|
||||
reply(f"找不到工单 {no},请核对工单号后再试。")
|
||||
return "ticket_missing"
|
||||
line = str(view.get("business_line") or "").strip().upper()
|
||||
owner = self._handoff_owner_for_line(line)
|
||||
if owner is None:
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
return "need_mode"
|
||||
hit = owner._session_from_ledger(sender_id=sender_id, view=view)
|
||||
line = (hit.business_line or "").strip().upper()
|
||||
owner = self._handoff_owner_for_line(line)
|
||||
if owner is None:
|
||||
reply(copy.ASK_TRANSPORT)
|
||||
return "need_mode"
|
||||
logger.info(
|
||||
"handoff.named wo=%s line=%s phase=%s chat=%s",
|
||||
no,
|
||||
line or "-",
|
||||
hit.phase or "-",
|
||||
"yes" if (hit.collab_chat_id or "").strip() else "no",
|
||||
)
|
||||
if is_closed_for_handoff(hit.status):
|
||||
reply("该工单已结束,不能再转人工。")
|
||||
return "handoff_closed"
|
||||
if owner._block_if_handoff_committed(hit, reply):
|
||||
return "handoff_done"
|
||||
return owner._offer_handoff_now(
|
||||
sender_id=sender_id, reason="intent", reply=reply, text=text, sess=hit
|
||||
)
|
||||
|
||||
def offer_handoff(self, *, sender_id: str, text: str, reply: ReplyFn) -> str:
|
||||
"""
|
||||
路由判定销售明确要求人来接管。运输方式不明则继续补问运输方式。
|
||||
|
||||
原话里写了工单号时,只处理那一张。
|
||||
有没有协同群只决定拦不拦;空运、海运、陆运各走各的转人工。
|
||||
"""
|
||||
from agent.llm.extract_text import detect_transport_mode
|
||||
from agent.policy.handoff_human import is_closed_for_handoff
|
||||
|
||||
named = copy.extract_work_order_no(text)
|
||||
if named:
|
||||
return self._offer_handoff_for_named_ticket(
|
||||
sender_id=sender_id, work_order_no=named, text=text, reply=reply
|
||||
)
|
||||
sess = self.session_of(sender_id)
|
||||
if sess and is_closed_for_handoff(sess.status):
|
||||
reply("该工单已结束,不能再转人工。")
|
||||
@@ -1572,7 +1693,15 @@ class AirTextInquiryFlow:
|
||||
if not result.get("ok"):
|
||||
reply(str(result.get("message") or copy.quote_template_missing()))
|
||||
return "wait_adopt"
|
||||
filename = str(result.get("fileName") or f"{sess.work_order_no}_quote.{fmt}")
|
||||
from agent.quote_templates.filename import filename_from_render
|
||||
|
||||
# 私聊直接生成与群里同一套名字:工单号 + 模板名 + 后缀。PDF 用 .pdf,表格用 .xlsx。
|
||||
xlsx_name = filename_from_render(sess.work_order_no, result, suffix=".xlsx")
|
||||
filename = (
|
||||
filename_from_render(sess.work_order_no, result, suffix=".pdf")
|
||||
if kind == "PDF"
|
||||
else xlsx_name
|
||||
)
|
||||
from agent.policy.event_exception import clear_wait
|
||||
|
||||
clear_wait(self._ledger, work_order_no=sess.work_order_no)
|
||||
@@ -1582,20 +1711,18 @@ class AirTextInquiryFlow:
|
||||
result,
|
||||
work_order_no=sess.work_order_no,
|
||||
sender_id=sess.sender_id,
|
||||
filename=filename if filename.lower().endswith(".pdf") else f"{sess.work_order_no}_quote.pdf",
|
||||
filename=filename,
|
||||
quote=dict(sess.quote or {}),
|
||||
facts=dict(sess.facts or {}),
|
||||
)
|
||||
if not queued:
|
||||
fallback = str(result.get("fileName") or f"{sess.work_order_no}_quote.xlsx")
|
||||
if not fallback.lower().endswith(".xlsx"):
|
||||
fallback = f"{sess.work_order_no}_quote.xlsx"
|
||||
reply("PDF 转换排队失败,已按后台模板发送 Excel 报价单。")
|
||||
file_extra = self._quote_file_payload(result, filename=xlsx_name)
|
||||
return self._emit_file_then_deal(
|
||||
sess,
|
||||
reply,
|
||||
kind="Excel",
|
||||
filename=fallback,
|
||||
filename=xlsx_name,
|
||||
file_extra=file_extra,
|
||||
)
|
||||
# 已入队:等 Worker 出文件后再出成交卡,这里不提前发卡
|
||||
|
||||
@@ -454,9 +454,7 @@ def _air_field_line(key: str, value: str, *, required: bool, example: str = "")
|
||||
|
||||
|
||||
def AIR_DISPLAY_LABEL(key: str) -> str:
|
||||
"""核对/补问对外名。起运港按产品口径写起运港。"""
|
||||
if key == "起运港":
|
||||
return "起运港"
|
||||
"""核对/补问对外名。空运起运港对外写起运地,内部键不变。"""
|
||||
return display_name(key, "AIR")
|
||||
|
||||
|
||||
@@ -464,10 +462,11 @@ def air_confirm_card(facts: dict[str, str] | None) -> str:
|
||||
"""
|
||||
确定查价前的核对卡。没有工单号。
|
||||
|
||||
必填 7 项 + 6 个非必填都列出;空着的非必填留空行。
|
||||
起运地(非必填)紧挨在目的地(必填)上面。其余非必填仍在报价日期后面。
|
||||
"""
|
||||
src = dict(facts or {})
|
||||
lines = ["运输方式(必填):空运"]
|
||||
lines.append(_air_field_line("起运港", _air_known_value(src, "起运港"), required=False))
|
||||
for key, _label in AIR_REQUIRED_FIELDS:
|
||||
if key == "报价日期":
|
||||
val = _air_known_value(src, key) or (src.get("报价日期") or "").strip()
|
||||
@@ -475,6 +474,8 @@ def air_confirm_card(facts: dict[str, str] | None) -> str:
|
||||
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))
|
||||
lines.append("")
|
||||
lines.append(AIR_CONFIRM_TAIL)
|
||||
@@ -523,14 +524,15 @@ def ask_clarify(
|
||||
lines = ["请确认并补充以下信息:"]
|
||||
if transport_mode:
|
||||
lines.append(f"运输方式:{transport_mode}")
|
||||
if not sea:
|
||||
origin = known(src, "起运港")
|
||||
if origin:
|
||||
lines.append(f"起运地:{origin}")
|
||||
for key, label, _example in rows:
|
||||
val = known(src, key)
|
||||
if val:
|
||||
lines.append(f"{label}:{val}")
|
||||
if not sea:
|
||||
origin = known(src, "起运港")
|
||||
if origin:
|
||||
lines.append(f"起运地:{origin}")
|
||||
for key, label, _example in _AIR_OPTIONAL_CLARIFY:
|
||||
if key == "起运港":
|
||||
continue
|
||||
@@ -545,6 +547,10 @@ def ask_clarify(
|
||||
any_missing = True
|
||||
seq += 1
|
||||
lines.append(_pending_field_block(seq, "运输方式", "空运"))
|
||||
if not sea and not known(src, "起运港"):
|
||||
any_missing = True
|
||||
seq += 1
|
||||
lines.append(_pending_field_block(seq, "起运地", _AIR_EXAMPLES["起运港"], optional=True))
|
||||
for key, label, example in rows:
|
||||
if key in missing_set:
|
||||
any_missing = True
|
||||
@@ -564,13 +570,12 @@ def ask_clarify(
|
||||
optional_pending = [
|
||||
(key, label, example)
|
||||
for key, label, example in _AIR_OPTIONAL_CLARIFY
|
||||
if not known(src, key)
|
||||
if key != "起运港" and not known(src, key)
|
||||
]
|
||||
for key, label, example in optional_pending:
|
||||
any_missing = True
|
||||
seq += 1
|
||||
shown = "起运港" if key == "起运港" else label
|
||||
lines.append(_pending_field_block(seq, shown, example, optional=True))
|
||||
lines.append(_pending_field_block(seq, label, example, optional=True))
|
||||
if not any_missing:
|
||||
return ""
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -778,7 +778,10 @@ def _render_and_send_sheet(
|
||||
if not result.get("ok"):
|
||||
logger.warning("群填表失败 wo=%s line=%s err=%s", work_order_no, line, result.get("error"))
|
||||
return result
|
||||
filename = str(result.get("fileName") or f"{work_order_no}_quote.xlsx")
|
||||
from agent.quote_templates.filename import filename_from_render
|
||||
|
||||
# 群里文件名:工单号 + 后台模板名 + .xlsx。调价后再发也是这个名字。
|
||||
filename = filename_from_render(work_order_no, result)
|
||||
sender = getattr(client, "send_group_file", None)
|
||||
if not callable(sender):
|
||||
logger.warning("群发文件无客户端 wo=%s chat=%s", work_order_no, chat_id)
|
||||
@@ -1039,6 +1042,8 @@ def _persist_quote_sheet(
|
||||
if sess is not None and getattr(sess, "collab_facts", None):
|
||||
collab.update(dict(sess.collab_facts or {}))
|
||||
renderer = getattr(flow.ledger, "render_quote", None)
|
||||
from agent.quote_templates.filename import filename_from_render
|
||||
|
||||
filename = f"{no}_quote.xlsx"
|
||||
object_key = filename
|
||||
line = str(
|
||||
@@ -1062,8 +1067,8 @@ def _persist_quote_sheet(
|
||||
),
|
||||
) or {}
|
||||
if result.get("ok"):
|
||||
filename = str(result.get("fileName") or filename)
|
||||
object_key = str(result.get("objectKey") or result.get("fileName") or filename)
|
||||
filename = filename_from_render(no, result)
|
||||
object_key = str(result.get("objectKey") or filename)
|
||||
_archive_file(flow, no, filename, {"media_id": object_key}, sender_id)
|
||||
|
||||
|
||||
|
||||
@@ -598,7 +598,14 @@ class SeaTextInquiryFlow(AirTextInquiryFlow):
|
||||
)
|
||||
|
||||
def _replay_wait(self, sess: FlowSession, reply: ReplyFn, *, source: str) -> str:
|
||||
if sess.business_line == "SEA" and sess.phase == "wait_collab":
|
||||
"""
|
||||
海运、陆运停在拉群问句时,继续工单必须把同一张卡拉回来。
|
||||
|
||||
空运父类的无价卡没有「拉产品进群」按钮。陆运以前被当成空运重放,
|
||||
销售继续工单就看不到这张卡。
|
||||
"""
|
||||
line = (sess.business_line or "").upper()
|
||||
if line in {"SEA", "LAND"} and sess.phase == "wait_collab":
|
||||
self._emit_sea_hit(
|
||||
reply,
|
||||
work_order_no=sess.work_order_no,
|
||||
@@ -606,10 +613,10 @@ class SeaTextInquiryFlow(AirTextInquiryFlow):
|
||||
first_or_same=sess.first_or_same,
|
||||
history_work_order_no=sess.history_work_order_no,
|
||||
status=sess.status or "已报价",
|
||||
business_line=sess.business_line or "SEA",
|
||||
business_line=line,
|
||||
)
|
||||
return "wait_collab"
|
||||
if sess.business_line == "SEA" and sess.phase == "tms_miss":
|
||||
if line in {"SEA", "LAND"} and sess.phase == "tms_miss":
|
||||
self._emit_tms_miss(reply, sess.work_order_no)
|
||||
return "tms_miss"
|
||||
return super()._replay_wait(sess, reply, source=source)
|
||||
|
||||
Reference in New Issue
Block a user