feat(shipping-notice): 实现货代发货通知的库存全流程与对话交互

This commit is contained in:
hugo committed 2026-06-03 11:09:46 +08:00
1 parent a5cc48b6aa
commit 2607f4a9f6
26 files changed
+5013 -256

No files matched your search

+23 -31
View File
@@ -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()))