feat(data-process): 返回任务文档数量

This commit is contained in:
caoxiaozhu
2026-07-27 09:50:19 +08:00
parent 680fa905f8
commit 895983ac20
3 changed files with 109 additions and 10 deletions

View File

@@ -220,34 +220,39 @@ class DataProcessStore:
tenant_id: str | None = None,
project_id: str | None = None,
) -> dict[str, Any]:
clauses = ["deleted_at IS NULL"]
clauses = ["task.deleted_at IS NULL"]
params: list[Any] = []
if keyword:
clauses.append("(name ILIKE %s OR COALESCE(description, '') ILIKE %s)")
clauses.append("(task.name ILIKE %s OR COALESCE(task.description, '') ILIKE %s)")
pattern = f"%{keyword.strip()}%"
params.extend([pattern, pattern])
if status:
clauses.append("status = %s")
clauses.append("task.status = %s")
params.append(status)
if process_type:
clauses.append("process_type = %s")
clauses.append("task.process_type = %s")
params.append(process_type)
if tenant_id:
clauses.append("tenant_id = %s")
clauses.append("task.tenant_id = %s")
params.append(tenant_id)
if project_id:
clauses.append("project_id = %s")
clauses.append("task.project_id = %s")
params.append(project_id)
where = " AND ".join(clauses)
with self.connect() as conn:
total = conn.execute(
f"SELECT COUNT(*) AS count FROM data_process_tasks WHERE {where}", params
f"SELECT COUNT(*) AS count FROM data_process_tasks task WHERE {where}",
params,
).fetchone()["count"]
rows = conn.execute(
f"""
SELECT * FROM data_process_tasks
SELECT task.*,
(SELECT COUNT(*) FROM data_process_source_files source_file
WHERE source_file.task_id=task.id
AND source_file.deleted_at IS NULL) AS source_file_count
FROM data_process_tasks task
WHERE {where}
ORDER BY created_at DESC, id DESC
ORDER BY task.created_at DESC, task.id DESC
LIMIT %s OFFSET %s
""",
[*params, page_size, (page - 1) * page_size],