feat(shipping-notice): 实现货代发货通知的库存全流程与对话交互
This commit is contained in:
1 parent
a5cc48b6aa
commit
2607f4a9f6
26 files changed
+5013
-256
No files matched your search
@@ -28,41 +28,10 @@ def _dify_openapi_spec() -> dict:
|
||||
return build_dify_openapi_spec(_tool_api_base_url())
|
||||
|
||||
|
||||
def _require_tool_key():
|
||||
configured = (
|
||||
str(current_app.config.get("SHIPPING_NOTICE_TOOL_API_KEY") or "").strip()
|
||||
or str(current_app.config.get("INTEGRATION_API_KEY") or "").strip()
|
||||
)
|
||||
if not configured:
|
||||
return jsonify({"error": "SHIPPING_NOTICE_TOOL_API_KEY is not configured"}), 503
|
||||
|
||||
incoming = (
|
||||
str(request.headers.get("X-Shipping-Tool-Key") or "").strip()
|
||||
or str(request.headers.get("X-Integration-Key") or "").strip()
|
||||
)
|
||||
if incoming and incoming == configured:
|
||||
return None
|
||||
return jsonify({"error": "Unauthorized"}), 401
|
||||
|
||||
|
||||
def _payload() -> dict:
|
||||
return request.get_json(silent=True) or {}
|
||||
|
||||
|
||||
@shipping_notice_bp.before_request
|
||||
def _auth_tools():
|
||||
if request.endpoint in {
|
||||
"shipping_notice.openapi_spec",
|
||||
"shipping_notice.openapi_dify_yaml",
|
||||
"shipping_notice.download_case_export",
|
||||
}:
|
||||
return None
|
||||
err = _require_tool_key()
|
||||
if err:
|
||||
return err
|
||||
return None
|
||||
|
||||
|
||||
@shipping_notice_bp.route("/tools/openapi.json", methods=["GET"])
|
||||
def openapi_spec():
|
||||
return jsonify(_dify_openapi_spec())
|
||||
@@ -86,6 +55,29 @@ def tool_parse_notice():
|
||||
return jsonify(shipping_tools.parse_notice(_payload()))
|
||||
|
||||
|
||||
@shipping_notice_bp.route("/tools/parse_inventory", methods=["POST"])
|
||||
def tool_parse_inventory():
|
||||
return jsonify(shipping_tools.parse_inventory(_payload()))
|
||||
|
||||
|
||||
@shipping_notice_bp.route("/tools/upload_inventory_file", methods=["POST"])
|
||||
def tool_upload_inventory_file():
|
||||
"""Multipart upload — parse server-side without sending Excel through LLM."""
|
||||
case_id = str(request.form.get("case_id") or request.args.get("case_id") or "").strip()
|
||||
upload = request.files.get("file")
|
||||
return jsonify(shipping_tools.upload_inventory_file(case_id, upload))
|
||||
|
||||
|
||||
@shipping_notice_bp.route("/tools/get_inventory_schema_preview", methods=["POST"])
|
||||
def tool_get_inventory_schema_preview():
|
||||
return jsonify(shipping_tools.get_inventory_schema_preview(_payload()))
|
||||
|
||||
|
||||
@shipping_notice_bp.route("/tools/apply_inventory_mapping", methods=["POST"])
|
||||
def tool_apply_inventory_mapping():
|
||||
return jsonify(shipping_tools.apply_inventory_mapping(_payload()))
|
||||
|
||||
|
||||
@shipping_notice_bp.route("/tools/ensure_inventory", methods=["POST"])
|
||||
def tool_ensure_inventory():
|
||||
return jsonify(shipping_tools.ensure_inventory(_payload()))
|
||||
|
||||
@@ -4,6 +4,7 @@ from flask import Blueprint, jsonify, request, send_file
|
||||
from pathlib import Path
|
||||
|
||||
from app.auth_jwt import get_current_user
|
||||
from app.services.shipping_notice.chat_actions import build_chat_actions_payload
|
||||
from app.services.shipping_notice.query_service import (
|
||||
get_case_for_user,
|
||||
list_cases_for_user,
|
||||
@@ -41,6 +42,57 @@ def workspace_shipping_case_detail(case_no: str):
|
||||
return jsonify(serialize_case_detail(case))
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route("/shipping-cases/<case_no>/chat-actions", methods=["GET"])
|
||||
def workspace_shipping_case_chat_actions(case_no: str):
|
||||
user, err = _require_user()
|
||||
if err:
|
||||
return err
|
||||
case = get_case_for_user(case_no, user.id)
|
||||
if not case:
|
||||
return jsonify({"error": "Not found"}), 404
|
||||
return jsonify(build_chat_actions_payload(case))
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route("/shipping-cases/<case_no>/upload-inventory", methods=["POST"])
|
||||
def workspace_upload_shipping_inventory(case_no: str):
|
||||
"""Hxops chat UI: upload inventory Excel with user auth (not Tool Key)."""
|
||||
user, err = _require_user()
|
||||
if err:
|
||||
return err
|
||||
case = get_case_for_user(case_no, user.id)
|
||||
if not case:
|
||||
return jsonify({"error": "Not found"}), 404
|
||||
|
||||
upload = request.files.get("file")
|
||||
from app.services.shipping_notice import tools as shipping_tools
|
||||
|
||||
return jsonify(shipping_tools.upload_inventory_file(case.case_no, upload))
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route("/shipping-cases/<case_no>/submit-decision", methods=["POST"])
|
||||
def workspace_submit_shipping_decision(case_no: str):
|
||||
"""Hxops chat UI: submit shipping decision with user auth (bypass Dify tool routing)."""
|
||||
user, err = _require_user()
|
||||
if err:
|
||||
return err
|
||||
case = get_case_for_user(case_no, user.id)
|
||||
if not case:
|
||||
return jsonify({"error": "Not found"}), 404
|
||||
|
||||
data = request.get_json(silent=True) or {}
|
||||
decision = str(data.get("decision") or "").strip()
|
||||
if not decision:
|
||||
return jsonify({"error": "decision is required"}), 400
|
||||
|
||||
from app.services.shipping_notice import tools as shipping_tools
|
||||
|
||||
payload = {"case_id": case.case_no, "decision": decision}
|
||||
comment = str(data.get("comment") or "").strip()
|
||||
if comment:
|
||||
payload["comment"] = comment
|
||||
return jsonify(shipping_tools.submit_decision(payload))
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route("/shipping-cases/<case_no>/export", methods=["GET"])
|
||||
def workspace_shipping_case_export(case_no: str):
|
||||
user, err = _require_user()
|
||||
|
||||
Reference in new issue
Block a user