完善报价业务问答与连续追问,补齐订单列表和人工转接
This commit is contained in:
@@ -219,7 +219,46 @@ def answer_count_query(intent, tenants):
|
||||
return {'t':text + f",其中 {counts['with_inbound']} 票已登记入仓码。", '_customer_data':True}
|
||||
|
||||
|
||||
def answer_list_query(message, tenants):
|
||||
"""Reuse bounded status parsing; list reads require an explicit customer scope."""
|
||||
if is_lookup_help(message) or not re.search(r'订单|运单|\borders?\b|\bshipments?\b',message,re.I):
|
||||
return None
|
||||
if not re.search(r'列出|列表|全部|所有|\blist\b',message,re.I):
|
||||
return None
|
||||
if not tenants:
|
||||
return order_login_response()
|
||||
question=re.sub(r'列出|列表|全部|所有|\blist\b','多少',message,flags=re.I)
|
||||
intent=parse_count_query(question)
|
||||
if intent is None or intent['unsupported']:
|
||||
return {'t':'暂不支持按这个条件列出订单。可查看全部订单或按履约中、已完成等业务状态查询。'}
|
||||
scope=tenant_filter(tenant_ids=tenants)
|
||||
if scope is None:
|
||||
return order_login_response()
|
||||
from .db import connect
|
||||
connection=None
|
||||
try:
|
||||
connection=connect()
|
||||
sql='SELECT order_no,inbound_code,status,warehouse_code FROM order_test_data WHERE 1=1'+scope[0]
|
||||
values=scope[1]
|
||||
if intent['status']:
|
||||
sql+=' AND status=?';values=values+[intent['status']]
|
||||
rows=connection.execute(sql+' ORDER BY id DESC LIMIT 21',values).fetchall()
|
||||
if not rows:return {'t':'当前账号下没有符合条件的订单。','_customer_data':True}
|
||||
lines=['您当前的订单列表'+('(先列出20票)' if len(rows)>20 else '')+':']
|
||||
for number,inbound,status,warehouse in rows[:20]:
|
||||
lines.append(f'- 入仓码:{inbound or "未登记"};订单号:{number};业务状态:{STATUS_LABELS.get(status,status)};目的仓:{warehouse or "未登记"}')
|
||||
lines.append('发送入仓码可查询该票订单和物流轨迹。')
|
||||
return {'t':'\n'.join(lines),'_customer_data':True}
|
||||
except sqlite3.Error:
|
||||
return {'t':'订单信息暂时无法读取,请稍后重试。'}
|
||||
finally:
|
||||
if connection is not None:connection.close()
|
||||
|
||||
|
||||
def extract_reference(message):
|
||||
# Explicit postal/monetary fields are not order identifiers, even if invalid.
|
||||
message = re.sub(r'(?:邮编|zip(?:\s*code)?|post\s*code)\s*[::为是]?\s*[0-9-]+', ' ', message, flags=re.I)
|
||||
message = re.sub(r'(?<![A-Za-z0-9_-])\d+(?:\.\d+)?\s*(?:万)?(?:USD|RMB|CNY|美元|美金|人民币|元)(?![A-Za-z0-9_-])',' ',message,flags=re.I)
|
||||
message = re.sub(r'\[(?:图片|文件)\]/uploads/\S+|https?://\S+', '', message)
|
||||
message = re.sub(r'(?<![A-Za-z0-9_-])\d{4}-\d{1,2}-\d{1,2}'
|
||||
r'(?:[T ]\d{1,2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?'
|
||||
@@ -227,10 +266,14 @@ def extract_reference(message):
|
||||
message = re.sub(r'(?<![A-Za-z0-9_.-])\d+(?:\.\d+)?\s*[*xX×]\s*\d+(?:\.\d+)?\s*[*xX×]\s*\d+(?:\.\d+)?'
|
||||
r'(?:\s*(?:cm|mm|m|厘米|毫米|米))?(?![A-Za-z0-9_.-])', ' ', message, flags=re.I)
|
||||
message = re.sub(r'(?<![A-Za-z0-9_-])\d+(?:\.\d+)?\s*'
|
||||
r'(?:kg|lbs?|cbm|cm|mm|公斤|千克|克|吨|立方米|方|m[³3]|箱|件)'
|
||||
r'(?:kilograms?|kgs?|grams?|g|tons?|lbs?|磅|cbm|cm|mm|公斤|千克|克|吨|立方米|方|m[³3]|箱|件)'
|
||||
r'(?![A-Za-z0-9_])', ' ', message, flags=re.I)
|
||||
references = []
|
||||
for token in IDENTIFIER.findall(message):
|
||||
if (re.fullmatch(r'[A-Za-z]{2,4}[0-9][A-Za-z0-9]{0,2}',token)
|
||||
and re.search(r'美国|报价|海派|海卡|海运|\bquote\b',message,re.I)
|
||||
and not re.search(r'订单|运单|入仓|轨迹|查单|\btrack\b',message,re.I)):
|
||||
continue
|
||||
if sum(character.isdigit() for character in token) < 3:
|
||||
continue
|
||||
if re.fullmatch(r'\d{4}[-_]\d{2}[-_]\d{2}|\d+(?:KG|LBS?|CBM|CM|MM)', token, re.I):
|
||||
@@ -335,6 +378,10 @@ def answer_query(message, conv_id):
|
||||
count_intent = parse_count_query(message) if not references else None
|
||||
if count_intent is not None:
|
||||
return answer_count_query(count_intent,tenants)
|
||||
if not references:
|
||||
listed=answer_list_query(message,tenants)
|
||||
if listed is not None:return listed
|
||||
mutation=bool(re.search(r'改址|修改.*(?:收件|地址|订单)|收件地址.*改|(?:取消|删除).*(?:订单|运单)|(?:订单|运单).*取消',message))
|
||||
if references and not tenants:
|
||||
return order_login_response()
|
||||
if len(references) > 1:
|
||||
@@ -364,6 +411,8 @@ def answer_query(message, conv_id):
|
||||
except (ValueError, KeyError, TypeError):
|
||||
pass
|
||||
if not reference:
|
||||
if mutation:
|
||||
return order_login_response() if not tenants else {'t':'当前支持查询订单与物流轨迹;改址、取消等操作请联系人工客服办理,尚未修改订单。请提供入仓码。'}
|
||||
if is_tracking_request(message) or (not is_lookup_help(message) and re.search(r'(?:查|搜|看|找).*(?:订单|运单|物流轨迹|入仓码|入仓号)|(?:入仓码|入仓号).*(?:查|轨迹|状态)|订单状态|物流轨迹|shipment\s*id|'
|
||||
r'(?:列出|搜索|所有|全部|多少|我的).*(?:订单|运单|入仓)|(?:订单|运单).*(?:多少|列表|查询|在哪|到哪|进度)|'
|
||||
r'^\s*(?:查单|查询|查一下|帮我查一下)[。?!?!\s]*$|'
|
||||
@@ -381,6 +430,8 @@ def answer_query(message, conv_id):
|
||||
return {'t':f'未找到“{reference}”对应的订单。请核对入仓码,或联系人工客服。'}
|
||||
if len(matches) > 1:
|
||||
return {'t':'该标识匹配到多个订单,请提供完整入仓码或联系人工客服确认。'}
|
||||
if mutation:
|
||||
return {'t':f'已查到订单“{reference}”。当前支持查询订单与物流轨迹;改址、取消等操作请联系人工客服办理,尚未修改订单。','_customer_data':True}
|
||||
if re.search(r'运费|费用|多少钱|价格', message):
|
||||
return {'t':'该订单未记录实际运费,请联系人工客服核实。'}
|
||||
return {'t':'该订单未记录实际运费,请联系人工客服核实。','_customer_data':True}
|
||||
return {'card': build_card(matches[0])}
|
||||
|
||||
Reference in New Issue
Block a user