feat(shipping-notice): 货代会话主区域切换为批次中心常驻并按附件派生会话标题
- 会话命名:新增业务命名纯函数,新建抽取会话按附件内容派生标题,仅新建不回填不改名 - 批次中心常驻主区域并展示会话标题:移除关闭入口、隐藏对话列、去除面板外壳与折叠/钉住徽标 - 清理对话流打开批次中心的冗余链路 - 新增设计文档与实施计划,同步功能清单说明
This commit is contained in:
1 parent
d396371020
commit
e472abc4e3
21 files changed
+1198
-206
No files matched your search
@@ -0,0 +1,59 @@
|
||||
"""
|
||||
backend/app/services/shipping_notice/conversation_title.py
|
||||
|
||||
用途:为订单抽取**新建**会话推导业务化标题,替代写死的「订单抽取」。
|
||||
依赖:仅标准库(datetime/pathlib/re);禁止引入 Flask/DB 依赖,保持可单测。
|
||||
逻辑:取首个非空附件文件名去扩展名 → 循环剥离邮件前缀 → 截断 24 字符 →
|
||||
多文件追加「等 N 个文件」→ 追加 MM-DD 日期消歧 → 全空回退「订单抽取」。
|
||||
仅新建会话时调用;存量会话标题一律不改(设计决策见 2026-09-17 spec)。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
from pathlib import PureWindowsPath
|
||||
|
||||
_FALLBACK_TITLE = '订单抽取'
|
||||
_NAME_MAX_CHARS = 24
|
||||
_TITLE_MAX_CHARS = 60
|
||||
# re:/fw:/fwd: 为半角冒号且大小写不敏感;回复/转发为全角冒号。循环剥离以支持多层嵌套。
|
||||
_MAIL_PREFIX_PATTERN = re.compile(r'^\s*(?:re|fw|fwd)\s*:|^\s*(?:回复|转发):', re.IGNORECASE)
|
||||
|
||||
|
||||
def _strip_mail_prefixes(name: str) -> str:
|
||||
"""循环剥离单个文件名开头的邮件前缀(Re:/Fw:/Fwd:/回复:/转发:)。"""
|
||||
current = name.strip()
|
||||
while True:
|
||||
stripped = _MAIL_PREFIX_PATTERN.sub('', current, count=1).lstrip()
|
||||
if stripped == current:
|
||||
return current
|
||||
current = stripped
|
||||
|
||||
|
||||
def derive_order_extraction_title(filenames: list[str], created_at: datetime) -> str:
|
||||
"""
|
||||
按首个附件文件名推导订单抽取会话标题。
|
||||
|
||||
Args:
|
||||
filenames: 本次冻结 Intake 对应的资产原始文件名,按 Intake 顺序;
|
||||
允许包含空串占位(保持计数口径)。
|
||||
created_at: 会话创建时间(服务器 UTC,不做时区换算),提供 MM-DD 消歧后缀。
|
||||
Returns:
|
||||
形如「PO#6075309 等 11 个文件 09-15」的标题;文件名全空时回退「订单抽取」;
|
||||
末尾做 60 字符防御性钳制(24 字主名约束下正常不可达)。
|
||||
"""
|
||||
ordered = [str(name or '').strip() for name in filenames]
|
||||
usable = [name for name in ordered if name]
|
||||
if not usable:
|
||||
return _FALLBACK_TITLE
|
||||
# PureWindowsPath 同时把 '/' 与 '\' 视为目录分隔符,兼容两类上传来源的路径写法。
|
||||
stem = PureWindowsPath(usable[0]).stem
|
||||
base = _strip_mail_prefixes(stem)[:_NAME_MAX_CHARS].strip()
|
||||
if not base:
|
||||
return _FALLBACK_TITLE
|
||||
parts = [base]
|
||||
if len(ordered) > 1:
|
||||
parts.append(f'等 {len(ordered)} 个文件')
|
||||
parts.append(f'{created_at.month:02d}-{created_at.day:02d}')
|
||||
return ' '.join(parts)[:_TITLE_MAX_CHARS]
|
||||
@@ -56,6 +56,7 @@ from app.models import (
|
||||
ShippingOrderSchemaVersion,
|
||||
User,
|
||||
)
|
||||
from app.services.shipping_notice.conversation_title import derive_order_extraction_title
|
||||
from app.services.shipping_notice.order_extraction_route_contract import (
|
||||
PARSER_ENGINE_VERSION,
|
||||
PARSER_POLICY_VERSION,
|
||||
@@ -697,6 +698,16 @@ def _load_intakes(
|
||||
return rows
|
||||
|
||||
|
||||
def _intake_filenames(intakes: list[ShippingOrderIntake]) -> list[str]:
|
||||
"""按 Intake 顺序取资产原始文件名;无资产或资产缺失以空串占位,保持计数口径。"""
|
||||
asset_ids = [int(intake.asset_id) for intake in intakes if intake.asset_id]
|
||||
if not asset_ids:
|
||||
return []
|
||||
rows = db.session.query(FileAsset.id, FileAsset.original_filename).filter(FileAsset.id.in_(asset_ids)).all()
|
||||
filename_by_id = {row[0]: str(row[1] or '') for row in rows}
|
||||
return [filename_by_id.get(int(intake.asset_id), '') for intake in intakes if intake.asset_id]
|
||||
|
||||
|
||||
def _resolve_conversation(
|
||||
*,
|
||||
user_id: int,
|
||||
@@ -713,6 +724,7 @@ def _resolve_conversation(
|
||||
intakes: 已按用户锁定且通过业务资格校验的 Intake。
|
||||
Returns:
|
||||
已存在或本事务新建的 ChatSession;调用方负责最终提交。
|
||||
新建会话的 title 由 conversation_title 按首个 Intake 文件名派生;已存在会话不改动标题。
|
||||
Raises:
|
||||
ConflictError: 所选 Intake 已分属不同会话,或与显式会话不一致。
|
||||
"""
|
||||
@@ -737,7 +749,7 @@ def _resolve_conversation(
|
||||
session_id=uuid.uuid4().hex,
|
||||
user_id=user_id,
|
||||
agent_id=agent_id,
|
||||
title='订单抽取',
|
||||
title=derive_order_extraction_title(_intake_filenames(intakes), datetime.utcnow()),
|
||||
status='running',
|
||||
created_at=datetime.utcnow(),
|
||||
updated_at=datetime.utcnow(),
|
||||
|
||||
Reference in new issue
Block a user