feat(shipping-notice): 支持发货通知解析延后至 Dify 画布,优化任务创建流程

This commit is contained in:
hugo committed 2026-06-22 16:59:38 +08:00
1 parent d46d61bfa1
commit 70e8f700ff
38 files changed
+3215 -714

No files matched your search

+80 -4
View File
@@ -4,20 +4,42 @@
1. 单/多通知可通过 create_batch 一次建批并生成多 task。
2. get_batch_status 返回 focus task 与任务列表。
3. switch_focus_task 可在同批次内切换当前任务。
4. 工作台批量上传通知时仅保存 raw_text,首轮解析延后到 Dify。
"""
from app.models import ShippingBatch, ShippingTask
from app import db
from app.models import ShippingBatch, ShippingTask, User
from app.auth_jwt import issue_local_access_token
def _tool_headers():
def _tool_headers(app):
app.config["INTEGRATION_API_KEY"] = "test-integration-key"
return {
"Content-Type": "application/json",
"X-Integration-Key": "test-integration-key",
}
def _workspace_headers(app):
with app.app_context():
user = User(
username="shipping_workspace_user",
email="shipping_workspace_user@example.com",
role="user",
status="active",
)
user.set_password("password")
db.session.add(user)
db.session.commit()
token = issue_local_access_token(user)
return {
"Authorization": f"Bearer {token}",
}
def test_create_batch_tasks_and_switch_focus(app, client):
"""验证 batch 建单、状态查询、focus task 切换主流程。"""
headers = _tool_headers()
headers = _tool_headers(app)
create_res = client.post(
"/api/shipping-notice/tools/create_batch",
@@ -93,9 +115,63 @@ def test_create_batch_tasks_and_switch_focus(app, client):
assert task_rows[1].batch_total == 2
def test_create_batch_defers_parse_without_structured(app, client):
"""默认将 parse_notice 延后到 Dify,仅保存 raw_text。"""
headers = _tool_headers(app)
res = client.post(
"/api/shipping-notice/tools/create_batch",
headers=headers,
json={
"notice_items": [
{
"source_file_name": "notice-a.txt",
"raw_text": "客户:ACME 料号A001 x 10",
},
],
},
)
assert res.status_code == 200
data = res.get_json()
assert data["data"]["tasks"][0]["parse_status"] == "deferred"
with app.app_context():
task = ShippingTask.query.filter_by(task_no=data["data"]["tasks"][0]["task_id"]).first()
assert task is not None
assert task.raw_content
assert not (task.lines_json or [])
def test_workspace_create_batch_from_notices_defers_parse_to_dify(app, client):
"""聊天/工作台批量上传通知时应仅落 raw_text,首轮解析延后到 Dify。"""
headers = _workspace_headers(app)
res = client.post(
"/api/workspace/shipping-batches/create-from-notices",
headers=headers,
data={
"files": (__import__("io").BytesIO("客户:ACME\nA001 x 10".encode("utf-8")), "notice-a.txt"),
"conversation_id": "conv-workspace-batch-001",
},
content_type="multipart/form-data",
)
assert res.status_code == 200
data = res.get_json()
assert data["status"] == "ok"
assert data["batch_no"].startswith("SB-")
assert data["data"]["batch"]["batch_no"] == data["batch_no"]
assert data["data"]["tasks"][0]["parse_status"] == "deferred"
assert data["data"]["focus_task"]["task_no"] == data["data"]["tasks"][0]["task_id"]
with app.app_context():
task = ShippingTask.query.filter_by(task_no=data["data"]["tasks"][0]["task_id"]).first()
assert task is not None
assert task.raw_content
assert task.process_status == "created"
assert len(task.lines_json or []) == 0
def test_create_empty_batch_returns_batch_shell(app, client):
"""验证无 notice_items 时仍可创建批次壳,供后续续办。"""
headers = _tool_headers()
headers = _tool_headers(app)
res = client.post(
"/api/shipping-notice/tools/create_batch",