feat(shipping-notice): 增强发货通知候选管理功能,支持候选选择、重复检测与业务摘要修订
This commit is contained in:
1 parent
70f684b94a
commit
b595e157e9
83 files changed
+5857
-200
No files matched your search
+21
-2
@@ -47,7 +47,12 @@ SHIPPING_NOTICE_AGENT_CODE = 'shipping_notice'
|
||||
PLM_PREVIEW_SHARE_ROOT = (os.getenv('PLM_PREVIEW_SHARE_ROOT') or '\\\\192.168.0.11\\dss\\dssroot\\').strip()
|
||||
|
||||
|
||||
def _build_chat_adapter_hints(*, shipping_task_id: str | None = None, shipping_batch_no: str | None = None) -> dict | None:
|
||||
def _build_chat_adapter_hints(
|
||||
*,
|
||||
shipping_task_id: str | None = None,
|
||||
shipping_batch_no: str | None = None,
|
||||
shipping_intake_nos: list[str] | None = None,
|
||||
) -> dict | None:
|
||||
"""
|
||||
构建聊天入口分发给领域 adapter 的提示字典。
|
||||
|
||||
@@ -56,12 +61,16 @@ def _build_chat_adapter_hints(*, shipping_task_id: str | None = None, shipping_b
|
||||
"""
|
||||
task_id = str(shipping_task_id or '').strip()
|
||||
batch_no = str(shipping_batch_no or '').strip()
|
||||
if not task_id and not batch_no:
|
||||
intake_nos = sorted({str(item or '').strip().upper() for item in (shipping_intake_nos or []) if str(item or '').strip()})
|
||||
if not task_id and not batch_no and not intake_nos:
|
||||
return None
|
||||
return {
|
||||
'shipping_notice': {
|
||||
'task_id': task_id or None,
|
||||
'batch_no': batch_no or None,
|
||||
'intake_nos': intake_nos,
|
||||
'capability': 'order_extraction' if intake_nos else None,
|
||||
'contract_version': 'shipping-order-extraction-v1' if intake_nos else None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1275,6 +1284,14 @@ def chat_completions():
|
||||
conversation_id = data.get('conversation_id')
|
||||
shipping_task_id = str(data.get('task_id') or '').strip()
|
||||
shipping_batch_no = str(data.get('batch_no') or '').strip()
|
||||
raw_shipping_intakes = data.get('shipping_intake_nos')
|
||||
if raw_shipping_intakes is not None and not isinstance(raw_shipping_intakes, list):
|
||||
raise ValidationError('shipping_intake_nos must be a list')
|
||||
shipping_intake_nos = sorted({
|
||||
str(item or '').strip().upper()
|
||||
for item in (raw_shipping_intakes or [])
|
||||
if str(item or '').strip()
|
||||
})
|
||||
kb_type = data.get('kb_type', '企业知识库')
|
||||
files = data.get('files')
|
||||
request_id = uuid.uuid4().hex[:12]
|
||||
@@ -1404,6 +1421,7 @@ def chat_completions():
|
||||
adapter_hints=_build_chat_adapter_hints(
|
||||
shipping_task_id=shipping_task_id,
|
||||
shipping_batch_no=shipping_batch_no,
|
||||
shipping_intake_nos=shipping_intake_nos,
|
||||
),
|
||||
shipping_task_id=shipping_task_id,
|
||||
shipping_batch_no=shipping_batch_no,
|
||||
@@ -1446,6 +1464,7 @@ def chat_completions():
|
||||
adapter_hints=_build_chat_adapter_hints(
|
||||
shipping_task_id=shipping_task_id,
|
||||
shipping_batch_no=shipping_batch_no,
|
||||
shipping_intake_nos=shipping_intake_nos,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -138,6 +138,25 @@ def tool_create_task():
|
||||
"""
|
||||
return jsonify(shipping_tools.create_task(_payload()))
|
||||
|
||||
|
||||
@shipping_notice_bp.route('/tools/get_order_extraction_context', methods=['POST'])
|
||||
def tool_get_order_extraction_context():
|
||||
"""
|
||||
返回当前会话待解析邮件及附件文本。
|
||||
【AI 触发时机】:仅当 agent_runtime_context.refs.capability=order_extraction 时,
|
||||
在完整订单抽取 LLM 节点之前调用一次。
|
||||
"""
|
||||
return jsonify(shipping_tools.get_order_extraction_context(_payload()))
|
||||
|
||||
|
||||
@shipping_notice_bp.route('/tools/submit_order_extraction', methods=['POST'])
|
||||
def tool_submit_order_extraction():
|
||||
"""
|
||||
提交 LLM 完整订单抽取结果并由 HXOPS 校验、判重和自动建单。
|
||||
【AI 触发时机】:订单抽取 LLM 与 JSON 标准化节点成功后调用;禁止绕过此 Tool 直接建单。
|
||||
"""
|
||||
return jsonify(shipping_tools.submit_order_extraction(_payload()))
|
||||
|
||||
@shipping_notice_bp.route('/tools/create_batch', methods=['POST'])
|
||||
def tool_create_batch():
|
||||
"""
|
||||
|
||||
@@ -701,15 +701,79 @@ def workspace_refresh_shipping_notice_duplicate(intake_no: str):
|
||||
return _ok(refresh_intake_duplicate_detection(user_id=user.id, intake_no=intake_no))
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-notice/candidates/<candidate_no>', methods=['PATCH'])
|
||||
def workspace_update_shipping_notice_candidate(candidate_no: str):
|
||||
"""更新订单候选的选择状态或人工修订业务摘要。"""
|
||||
user = _require_user()
|
||||
body = request.get_json(silent=True) or {}
|
||||
if not isinstance(body, dict):
|
||||
raise ValidationError('请求体必须为对象')
|
||||
if 'selected' in body and not isinstance(body.get('selected'), bool):
|
||||
raise ValidationError('selected 必须为布尔值')
|
||||
if 'business_summary' in body and not isinstance(body.get('business_summary'), dict):
|
||||
raise ValidationError('business_summary 必须为对象')
|
||||
if 'selected' not in body and 'business_summary' not in body:
|
||||
raise ValidationError('selected 或 business_summary 至少提供一项')
|
||||
from app.services.shipping_notice.candidate_service import update_candidate
|
||||
|
||||
return _ok(
|
||||
update_candidate(
|
||||
user_id=user.id,
|
||||
candidate_no=candidate_no,
|
||||
selected=body.get('selected') if 'selected' in body else None,
|
||||
business_summary=body.get('business_summary') if 'business_summary' in body else None,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route(
|
||||
'/shipping-notice/candidates/<candidate_no>/duplicate-refresh',
|
||||
methods=['POST'],
|
||||
)
|
||||
def workspace_refresh_shipping_notice_candidate(candidate_no: str):
|
||||
"""刷新单个订单候选的重复检测。"""
|
||||
user = _require_user()
|
||||
from app.services.shipping_notice.candidate_service import refresh_candidate_duplicate
|
||||
|
||||
return _ok(refresh_candidate_duplicate(user_id=user.id, candidate_no=candidate_no))
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route(
|
||||
'/shipping-notice/candidates/<candidate_no>/duplicate-resolution',
|
||||
methods=['POST'],
|
||||
)
|
||||
def workspace_resolve_shipping_notice_candidate(candidate_no: str):
|
||||
"""保存单个订单候选的重复处理决策。"""
|
||||
user = _require_user()
|
||||
body = request.get_json(silent=True) or {}
|
||||
from app.services.shipping_notice.candidate_service import resolve_candidate_duplicate
|
||||
|
||||
return _ok(
|
||||
resolve_candidate_duplicate(
|
||||
user_id=user.id,
|
||||
candidate_no=candidate_no,
|
||||
action=str(body.get('action') or ''),
|
||||
target_task_no=str(body.get('target_task_no') or '').strip() or None,
|
||||
reason=str(body.get('reason') or '').strip() or None,
|
||||
actor=user,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route('/shipping-batches/create-from-intakes', methods=['POST'])
|
||||
def workspace_create_shipping_batch_from_intakes():
|
||||
"""从已解析接入记录确认建批。"""
|
||||
user = _require_user()
|
||||
body = request.get_json(silent=True) or {}
|
||||
if not isinstance(body, dict):
|
||||
raise ValidationError('请求体必须为对象')
|
||||
intake_nos = body.get('intake_nos')
|
||||
if not isinstance(intake_nos, list) or not intake_nos:
|
||||
raise ValidationError('intake_nos is required')
|
||||
conversation_id = str(body.get('conversation_id') or '').strip() or None
|
||||
candidate_nos = body.get('candidate_nos')
|
||||
if candidate_nos is not None and not isinstance(candidate_nos, list):
|
||||
raise ValidationError('candidate_nos must be a list')
|
||||
from app.services.shipping_notice.batch_create_idempotency import (
|
||||
normalize_create_idempotency_key,
|
||||
warn_missing_create_idempotency_key,
|
||||
@@ -725,6 +789,7 @@ def workspace_create_shipping_batch_from_intakes():
|
||||
user_id=user.id,
|
||||
conversation_id=conversation_id,
|
||||
intake_nos=[str(item) for item in intake_nos],
|
||||
candidate_nos=[str(item) for item in candidate_nos] if isinstance(candidate_nos, list) else None,
|
||||
create_idempotency_key=idempotency_key,
|
||||
)
|
||||
return _ok(result)
|
||||
|
||||
Reference in new issue
Block a user