修复:手动建单优先于工单处理结果图片上传

This commit is contained in:
2026-03-31 18:22:27 +08:00
parent 4e03938334
commit 70a2f5b504
2 changed files with 37 additions and 2 deletions

View File

@@ -56,9 +56,12 @@ class AgentDispatcher:
self._pending_images[user_id] = []
session = get_session_manager().get(user_id)
normalized_content = content.strip()
try:
reply = await self._handle_manual_order_message(user_id, session, content.strip())
reply = self._maybe_start_manual_order_from_text(session, normalized_content)
if reply is None:
reply = await self._handle_manual_order_message(user_id, session, normalized_content)
if reply is None:
reply = await self._langgraph_chat(user_id, content)
except Exception as e:
@@ -99,6 +102,10 @@ class AgentDispatcher:
permanent_url = oss.get_permanent_url(object_key)
presign_url = oss.get_presigned_url(object_key)
if session.state == "waiting_manual_order_image":
del presign_url
return await self._start_manual_order_flow(session, permanent_url)
# 3. 检查用户是否有待处理工单
handling_alarm_id = self._find_handling_alarm(user_id)
if handling_alarm_id:
@@ -196,8 +203,36 @@ class AgentDispatcher:
"请回复区域编号。"
)
@staticmethod
def _maybe_start_manual_order_from_text(session, content: str) -> Optional[str]:
"""用户明确提出创建工单时,优先进入手动建单流程。"""
if session.state != "idle":
return None
trigger_phrases = (
"创建工单",
"新建工单",
"手动工单",
"手动上报",
"我要创建工单",
"我要上报",
"上报工单",
)
if not any(phrase in content for phrase in trigger_phrases):
return None
session.reset()
session.state = "waiting_manual_order_image"
return "请先上传现场图片,我会在收到图片后引导您选择区域并补充备注。"
async def _handle_manual_order_message(self, user_id: str, session, content: str) -> Optional[str]:
"""处理手动工单创建状态机。"""
if session.state == "waiting_manual_order_image":
if content in {"取消", "算了", "不用了"}:
session.reset()
return "已取消本次手动工单创建。"
return "请先上传现场图片。若不需要创建工单,回复“取消”即可。"
if session.state == "waiting_manual_order_area":
area = self._match_area_option(content, session.pending_manual_order_area_options)
if not area:

View File

@@ -18,7 +18,7 @@ class UserSession:
def __init__(self, user_id: str):
self.user_id = user_id
self.state = "idle" # idle / waiting_close_photo / waiting_manual_order_area / waiting_manual_order_remark / waiting_manual_order_confirm
self.state = "idle" # idle / waiting_close_photo / waiting_manual_order_image / waiting_manual_order_area / waiting_manual_order_remark / waiting_manual_order_confirm
self.pending_image_url = "" # 暂存的图片 COS key
self.pending_analysis = "" # VLM 分析结果描述
self.pending_alarm_type = "" # VLM 识别的告警类型