feat(chat): 更新发货任务处理逻辑和界面文本

- 移除不必要的状态引用
- 更新上传处理提示文本,使用国际化支持
- 扩展发货任务摘要接口,增加错误信息和短缺信息
- 更新多语言支持的文本,改善用户体验
- 增加批次工作区的汇总信息和操作提示
This commit is contained in:
hugo committed 2026-06-29 14:43:27 +08:00
1 parent 0b083cfdbd
commit 1fc9976ca3
60 files changed
+3876 -639

No files matched your search

@@ -205,6 +205,169 @@ def test_workspace_create_batch_from_notices_starts_orchestrator_when_enabled(ap
assert started == [data["batch_no"]]
def test_workspace_conversation_batch_workspace_aggregates_multiple_batches(app, client):
"""同一 Agent 会话下多个批次应聚合为一个会话级工作台快照。"""
headers = _workspace_headers(app)
with app.app_context():
user = User.query.filter_by(username="shipping_workspace_user").order_by(User.id.desc()).first()
assert user is not None
batch_a = ShippingBatch(
batch_no="SB-CONV-WS-A",
user_id=user.id,
conversation_id="conv-workspace-multi",
current_focus_task_no="SN-20260626-CONVA001",
file_count=2,
)
batch_b = ShippingBatch(
batch_no="SB-CONV-WS-B",
user_id=user.id,
conversation_id="conv-workspace-multi",
current_focus_task_no="SN-20260626-CONVB001",
file_count=2,
)
other_batch = ShippingBatch(
batch_no="SB-CONV-WS-OTHER",
user_id=user.id,
conversation_id="conv-workspace-other",
file_count=1,
)
db.session.add_all([batch_a, batch_b, other_batch])
db.session.flush()
db.session.add_all([
ShippingTask(
task_no="SN-20260626-CONVA001",
batch_id=batch_a.id,
user_id=user.id,
conversation_id="conv-workspace-multi",
source_type="manual",
process_status="uploaded",
batch_index=1,
batch_total=2,
),
ShippingTask(
task_no="SN-20260626-CONVA002",
batch_id=batch_a.id,
user_id=user.id,
conversation_id="conv-workspace-multi",
source_type="manual",
process_status="matched",
batch_index=2,
batch_total=2,
),
ShippingTask(
task_no="SN-20260626-CONVB001",
batch_id=batch_b.id,
user_id=user.id,
conversation_id="conv-workspace-multi",
source_type="manual",
process_status="waiting_inventory",
review_status="align_review",
batch_index=1,
batch_total=2,
),
ShippingTask(
task_no="SN-20260626-CONVB002",
batch_id=batch_b.id,
user_id=user.id,
conversation_id="conv-workspace-multi",
source_type="manual",
process_status="matched",
upload_status="failed",
batch_index=2,
batch_total=2,
),
ShippingTask(
task_no="SN-20260626-OTHER001",
batch_id=other_batch.id,
user_id=user.id,
conversation_id="conv-workspace-other",
source_type="manual",
process_status="uploaded",
batch_index=1,
batch_total=1,
),
])
db.session.commit()
res = client.get(
"/api/workspace/shipping-conversations/conv-workspace-multi/batch-workspace",
headers=headers,
)
assert res.status_code == 200
data = res.get_json()
assert data["conversation_id"] == "conv-workspace-multi"
assert data["summary"] == {
"batch_count": 2,
"total": 4,
"completed": 1,
"running": 1,
"failed": 1,
"needs_human": 1,
"pending": 0,
}
assert [item["batch_no"] for item in data["batches"]] == ["SB-CONV-WS-A", "SB-CONV-WS-B"]
assert data["batches"][0]["focus_task"]["task_no"] == "SN-20260626-CONVA001"
assert len(data["batches"][1]["tasks"]) == 2
def test_workspace_conversation_batch_workspace_filters_by_user(app, client):
"""会话级工作台只能返回当前用户可访问的批次。"""
headers = _workspace_headers(app)
with app.app_context():
current = User.query.filter_by(username="shipping_workspace_user").order_by(User.id.desc()).first()
other = User(
username="shipping_workspace_other",
email="shipping_workspace_other@example.com",
role="user",
status="active",
)
other.set_password("password")
db.session.add(other)
db.session.flush()
own_batch = ShippingBatch(
batch_no="SB-CONV-OWN",
user_id=current.id,
conversation_id="conv-workspace-secure",
file_count=1,
)
foreign_batch = ShippingBatch(
batch_no="SB-CONV-FOREIGN",
user_id=other.id,
conversation_id="conv-workspace-secure",
file_count=1,
)
db.session.add_all([own_batch, foreign_batch])
db.session.flush()
db.session.add_all([
ShippingTask(
task_no="SN-20260626-OWN00001",
batch_id=own_batch.id,
user_id=current.id,
conversation_id="conv-workspace-secure",
source_type="manual",
process_status="created",
),
ShippingTask(
task_no="SN-20260626-FGN00001",
batch_id=foreign_batch.id,
user_id=other.id,
conversation_id="conv-workspace-secure",
source_type="manual",
process_status="uploaded",
),
])
db.session.commit()
res = client.get(
"/api/workspace/shipping-conversations/conv-workspace-secure/batch-workspace",
headers=headers,
)
assert res.status_code == 200
data = res.get_json()
assert data["summary"]["batch_count"] == 1
assert [item["batch_no"] for item in data["batches"]] == ["SB-CONV-OWN"]
def test_shipping_orchestrator_enqueues_generic_job_not_kb_job(app):
"""发货通知后台编排应写入通用 jobs,不能污染 kb_jobs。"""
app.config["SHIPPING_NOTICE_BATCH_ORCHESTRATOR_ENABLED"] = True
@@ -306,6 +469,53 @@ def test_run_single_task_routes_created_task_to_dify_executor(app, monkeypatch):
assert called.get("dify") == task_no
def test_run_single_task_refreshes_after_dify_parse_before_auto_progress(app, monkeypatch):
"""Dify Tool 提交解析结果后,编排器应刷新 session 并继续触发自动推进。"""
app.config["SHIPPING_NOTICE_AUTO_PROGRESS_ENABLED"] = True
with app.app_context():
batch = ShippingBatch(batch_no="SB-ORCH-PARSE-FOLLOW", file_count=1)
task = ShippingTask(
task_no="SN-20260629-FOLLOW01",
batch=batch,
source_type="manual",
raw_content="客户:ACME\nA001 x 10",
process_status="created",
)
db.session.add_all([batch, task])
db.session.commit()
task_no = task.task_no
called: dict[str, object] = {}
def fake_dify(task_ref: str):
stmt = (
ShippingTask.__table__.update()
.where(ShippingTask.__table__.c.task_no == task_ref)
.values(
process_status="parsed",
review_status=None,
pending_human_reason=None,
lines_json=[{"sku": "A001", "reservation_id": "R-1", "qty": 10}],
)
)
with db.engine.begin() as conn:
conn.execute(stmt)
return {"status": "ok", "message": "parsed-by-dify"}
def fake_auto_progress(payload):
called["auto_progress"] = payload
return {"status": "running", "message": "rpa triggered"}
monkeypatch.setattr(batch_orchestrator, "run_shipping_parse_via_dify", fake_dify)
monkeypatch.setattr(batch_orchestrator, "auto_progress", fake_auto_progress)
result = batch_orchestrator._run_single_task(task_no)
assert result["status"] == "running"
assert isinstance(called.get("auto_progress"), dict)
assert called["auto_progress"]["task_id"] == task_no
def test_run_single_task_routes_non_created_task_to_auto_progress(app, monkeypatch):
"""编排器遇到非 created 且无人工阻塞的任务时应调用 auto_progress。"""
with app.app_context():