feat: 任务列表显示店铺名和执行用时 (#136)

This commit is contained in:
chengma
2026-08-11 11:17:44 +08:00
parent 6d30115c7e
commit e354dddad6
10 changed files with 163 additions and 28 deletions
+36 -6
View File
@@ -129,11 +129,20 @@ class TaskRepository:
connection = open_database(self._db_path)
try:
rows = connection.execute(
"SELECT id, remote_task_id, task_type, goods_id, title,"
" target_color, target_size, price_cent, quantity, status, updated_at"
"SELECT pdd_tasks.id, remote_task_id, task_type, goods_id, title,"
" shop_name, target_color, target_size, price_cent, quantity,"
" status, pdd_tasks.updated_at, latest_run.run_status AS latest_run_status,"
" CASE WHEN latest_run.run_status = 'running' THEN NULL"
" WHEN latest_run.started_at IS NOT NULL AND latest_run.finished_at IS NOT NULL"
" THEN MAX(0, CAST(strftime('%s', latest_run.finished_at)"
" - strftime('%s', latest_run.started_at) AS INTEGER))"
" ELSE NULL END AS duration_seconds"
" FROM pdd_tasks"
" LEFT JOIN task_runs AS latest_run ON latest_run.id = ("
" SELECT id FROM task_runs WHERE task_id = pdd_tasks.id"
" ORDER BY attempt_no DESC LIMIT 1)"
f"{where_sql}"
" ORDER BY updated_at DESC, id DESC"
" ORDER BY pdd_tasks.updated_at DESC, pdd_tasks.id DESC"
" LIMIT ? OFFSET ?",
parameters,
).fetchall()
@@ -1098,13 +1107,14 @@ class TaskRepository:
task_cursor = connection.execute(
"UPDATE pdd_tasks SET status = 'result_pending',"
" current_step = 'purchase_order_matched_pending_report',"
" pdd_data = ?,"
" pdd_data = ?, shop_name = ?,"
" price_cent = ?, last_error_code = NULL,"
" last_error_message = NULL, finished_at = ?, updated_at = ?"
" WHERE id = ? AND status = 'manual_review'"
" AND current_step = 'reconcile_purchase'",
(
result_json,
self._summary_shop_name(pdd_data),
self._purchase_result_price(pdd_data),
now,
now,
@@ -1188,11 +1198,12 @@ class TaskRepository:
)
connection.execute(
"UPDATE pdd_tasks SET status = 'result_pending',"
" current_step = 'submit_result', pdd_data = ?,"
" current_step = 'submit_result', pdd_data = ?, shop_name = ?,"
" price_cent = ?, finished_at = ?, updated_at = ?"
" WHERE id = ?",
(
result_json,
self._summary_shop_name(pdd_data),
self._purchase_result_price(pdd_data),
now,
now,
@@ -1373,11 +1384,13 @@ class TaskRepository:
connection.execute(
"UPDATE pdd_tasks SET status = 'result_pending',"
" current_step = 'submit_result', pdd_data = ?, goods_id = ?,"
" title = ?, price_cent = ?, finished_at = ?, updated_at = ?"
" title = ?, shop_name = ?, price_cent = ?,"
" finished_at = ?, updated_at = ?"
" WHERE id = ?",
(
result_json,
pdd_data.get("goods_id"), pdd_data.get("title"),
self._summary_shop_name(pdd_data),
self._summary_price(pdd_data), now, now, task["id"],
),
)
@@ -1834,14 +1847,31 @@ class TaskRepository:
task_type=TaskType(row["task_type"]),
goods_id=row["goods_id"],
title=row["title"],
shop_name=row["shop_name"],
target_color=row["target_color"],
target_size=row["target_size"],
price_cent=row["price_cent"],
quantity=row["quantity"],
status=TaskStatus(row["status"]),
latest_run_status=(
RunStatus(row["latest_run_status"])
if row["latest_run_status"] is not None
else None
),
duration_seconds=row["duration_seconds"],
updated_at=row["updated_at"],
)
@staticmethod
def _summary_shop_name(pdd_data: Dict[str, object]) -> Optional[str]:
"""提取列表需要的店铺名,空值不写入摘要列。"""
value = pdd_data.get("shop_name")
if not isinstance(value, str):
return None
value = value.strip()
return value or None
@staticmethod
def _to_detail(row: sqlite3.Row) -> TaskDetail:
admin_payload = TaskRepository._load_json_object(row["admin_payload"])