feat(shipping-notice): 支持发货通知解析延后至 Dify 画布,优化任务创建流程
This commit is contained in:
1 parent
d46d61bfa1
commit
70e8f700ff
38 files changed
+3215
-714
No files matched your search
@@ -121,8 +121,22 @@ def workspace_create_shipping_batch_from_notices():
|
||||
"conversation_id": conversation_id or None,
|
||||
"file_count": len(notice_items),
|
||||
"notice_items": notice_items,
|
||||
# 用户态上传通知后仅完成抽文、建批/建任务与 raw_text 落库;
|
||||
# 首轮订单需求解析由 Dify 画布读取 raw_text 后调用 parse_notice(structured=...)。
|
||||
"defer_parse": True,
|
||||
}
|
||||
return jsonify(shipping_tools.create_batch_tasks(payload))
|
||||
created = shipping_tools.create_batch_tasks(payload)
|
||||
data = created.get("data") if isinstance(created, dict) else None
|
||||
batch_data = data.get("batch") if isinstance(data, dict) else None
|
||||
tasks_data = data.get("tasks") if isinstance(data, dict) else None
|
||||
batch_no = str(created.get("batch_no") or (batch_data or {}).get("batch_no") or "").strip()
|
||||
if isinstance(data, dict) and batch_no:
|
||||
focus_task = get_focus_task_for_batch(batch_no, user.id)
|
||||
if focus_task:
|
||||
data["focus_task"] = serialize_task_summary(focus_task)
|
||||
if isinstance(tasks_data, list):
|
||||
data["tasks"] = tasks_data
|
||||
return jsonify(created)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route("/shipping-batches/<batch_no>", methods=["GET"])
|
||||
@@ -222,7 +236,7 @@ def workspace_create_shipping_task():
|
||||
|
||||
@workspace_shipping_notice_bp.route("/shipping-tasks/create-from-notice", methods=["POST"])
|
||||
def workspace_create_shipping_task_from_notice():
|
||||
"""接收单个发货通知附件,建单后抽取文本并立即触发解析。"""
|
||||
"""接收单个发货通知附件,建单后抽取文本并保存 raw_text,解析延后到 Dify。"""
|
||||
user, err = _require_user()
|
||||
if err:
|
||||
return err
|
||||
@@ -277,13 +291,24 @@ def workspace_create_shipping_task_from_notice():
|
||||
task.raw_content = text
|
||||
db.session.commit()
|
||||
|
||||
payload = {"task_id": task_id}
|
||||
parsed = shipping_tools.parse_notice(payload)
|
||||
data = parsed.get("data") if isinstance(parsed, dict) else None
|
||||
if isinstance(data, dict):
|
||||
data["notice_upload"] = {"filename": upload.filename or "", **meta}
|
||||
parsed["message"] = f"已上传发货通知文件并创建任务 {task_id}。{parsed.get('message') or ''}".strip()
|
||||
return jsonify(parsed)
|
||||
task = ShippingTask.query.filter_by(task_no=task_id).first()
|
||||
if task:
|
||||
task.source_file_name = str(upload.filename or "").strip() or task.source_file_name
|
||||
task.source_file_type = str(getattr(upload, "mimetype", "") or "").strip() or task.source_file_type
|
||||
db.session.commit()
|
||||
|
||||
return jsonify(
|
||||
{
|
||||
"status": "ok",
|
||||
"task_id": task_id,
|
||||
"message": f"已上传发货通知文件并创建任务 {task_id}。通知原文已保存,等待 Dify 继续解析。",
|
||||
"data": {
|
||||
"task": serialize_task_summary(task) if task else {"task_no": task_id},
|
||||
"notice_upload": {"filename": upload.filename or "", **meta},
|
||||
"parse_status": "deferred",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@workspace_shipping_notice_bp.route("/shipping-tasks/<task_no>", methods=["GET"])
|
||||
|
||||
Reference in new issue
Block a user