feat: add batch progress overview

This commit is contained in:
chengma
2026-07-02 10:21:39 +08:00
parent d8c3c5d548
commit b622925d74
5 changed files with 165 additions and 9 deletions
+73 -1
View File
@@ -194,6 +194,65 @@ if QT_IMPORT_ERROR is None:
button.setVisible(active and show_button)
BATCH_PROGRESS_FIELDS = [
("total", "总数"),
("imported", "导入"),
("collected", "已采集"),
("generated", "已生成"),
("applied", "已更新"),
("failed", "失败"),
("skipped", "略过"),
]
def _summarize_batch_progress(tasks):
summary = {key: 0 for key, _label in BATCH_PROGRESS_FIELDS}
task_rows = list(tasks or [])
summary["total"] = len(task_rows)
for task in task_rows:
status = getattr(task, "status", None)
stage = getattr(task, "stage", None)
if status == "failed":
summary["failed"] += 1
elif status == "skipped":
summary["skipped"] += 1
elif stage == "applied":
summary["applied"] += 1
elif stage == "generated":
summary["generated"] += 1
elif stage == "collected":
summary["collected"] += 1
else:
summary["imported"] += 1
return summary
def _format_batch_progress(summary):
parts = [f"{label}{summary.get(key, 0)}" for key, label in BATCH_PROGRESS_FIELDS]
return "批次进度:" + " · ".join(parts)
def _build_batch_progress_overview(object_name):
label = QLabel("")
label.setObjectName(object_name)
label.setWordWrap(True)
label.setStyleSheet(
f"QLabel#{object_name} {{ "
"background: #f6f8fa; border: 1px solid #d0d7de; "
"border-radius: 6px; padding: 8px 10px; color: #24292f; "
"}"
)
label.setVisible(False)
return label
def _set_batch_progress_overview(label, tasks):
summary = _summarize_batch_progress(tasks)
active = summary["total"] > 0
label.setVisible(active)
label.setText(_format_batch_progress(summary) if active else "")
def _database_path(db_path=None, config=None) -> str:
return db_path or appconfig.db_path(config)
@@ -810,6 +869,7 @@ if QT_IMPORT_ERROR is None:
filter_layout.addWidget(self.refresh_button)
self.summary_label = QLabel("任务 0 条")
self.batch_progress_label = _build_batch_progress_overview("generateBatchProgressOverview")
(
self.empty_state_card,
self.empty_state_label,
@@ -837,6 +897,7 @@ if QT_IMPORT_ERROR is None:
right_layout.setContentsMargins(12, 0, 0, 0)
right_layout.addLayout(filter_layout)
right_layout.addWidget(self.summary_label)
right_layout.addWidget(self.batch_progress_label)
right_layout.addWidget(self.empty_state_card)
right_layout.addWidget(self.task_table, 1)
right_layout.addWidget(QLabel("AI生成运行日志"))
@@ -1310,6 +1371,7 @@ if QT_IMPORT_ERROR is None:
except Exception as exc:
self.model.set_tasks([], [])
self.summary_label.setText("任务读取失败")
_set_batch_progress_overview(self.batch_progress_label, [])
_set_empty_state(self.empty_state_card, self.empty_state_label, self.empty_state_button)
self._set_status(f"AI 生成任务读取失败:{exc}")
return
@@ -1317,6 +1379,7 @@ if QT_IMPORT_ERROR is None:
self.summary_label.setText(
f"任务 {len(filtered_tasks)}/{len(batch_tasks)} 条"
)
_set_batch_progress_overview(self.batch_progress_label, batch_tasks)
self._update_empty_state(batch_tasks, filtered_tasks, accounts_rows)
def _update_empty_state(self, batch_tasks, filtered_tasks, account_rows):
@@ -1471,6 +1534,7 @@ if QT_IMPORT_ERROR is None:
filter_layout.addWidget(self.refresh_button)
self.summary_label = QLabel("任务 0 条")
self.batch_progress_label = _build_batch_progress_overview("applyBatchProgressOverview")
self.risk_label = QLabel("可先点击「检查本轮更新」确认当前筛选范围;点击「开始更新」后会再次确认并按批提交线上。")
(
self.empty_state_card,
@@ -1525,6 +1589,7 @@ if QT_IMPORT_ERROR is None:
layout.addLayout(filter_layout)
layout.addWidget(self.risk_label)
layout.addWidget(self.summary_label)
layout.addWidget(self.batch_progress_label)
layout.addWidget(self.empty_state_card)
layout.addWidget(self.task_table, 1)
layout.addWidget(QLabel("运行日志"))
@@ -1561,8 +1626,9 @@ if QT_IMPORT_ERROR is None:
item_query = self.item_filter.text().strip()
self._populate_batch_filter(batches, selected_batch)
selected_batch = self.batch_filter.currentData()
all_batch_tasks = db.list_tasks(batch_id=selected_batch, path=self.db_path)
batch_tasks = [
task for task in db.list_tasks(batch_id=selected_batch, path=self.db_path)
task for task in all_batch_tasks
if self._is_update_task(task)
]
self._populate_shop_filter(batch_tasks, account_rows, selected_shop)
@@ -1576,6 +1642,7 @@ if QT_IMPORT_ERROR is None:
except Exception as exc:
self.model.set_tasks([], [])
self.summary_label.setText("任务读取失败")
_set_batch_progress_overview(self.batch_progress_label, [])
_set_empty_state(self.empty_state_card, self.empty_state_label, self.empty_state_button)
self._set_status(f"更新任务读取失败:{exc}")
return
@@ -1583,6 +1650,7 @@ if QT_IMPORT_ERROR is None:
self.summary_label.setText(
f"任务 {len(filtered_tasks)}/{len(batch_tasks)} 条"
)
_set_batch_progress_overview(self.batch_progress_label, all_batch_tasks)
self._update_empty_state(batch_tasks, filtered_tasks, account_rows)
self._update_write_back_button()
@@ -2264,6 +2332,7 @@ if QT_IMPORT_ERROR is None:
self.summary_label = QLabel("未导入任务")
self.summary_label.setTextFormat(Qt.RichText)
self.batch_progress_label = _build_batch_progress_overview("collectBatchProgressOverview")
self.match_detail_label = QLabel("")
self.show_all_button = QPushButton("全部")
self.show_unmatched_button = QPushButton("未匹配(0)")
@@ -2304,6 +2373,7 @@ if QT_IMPORT_ERROR is None:
layout.addLayout(toolbar)
layout.addLayout(summary_layout)
layout.addWidget(self.match_detail_label)
layout.addWidget(self.batch_progress_label)
layout.addWidget(self.empty_state_card)
layout.addWidget(self.table, 1)
layout.addWidget(QLabel("采集运行日志"))
@@ -2516,11 +2586,13 @@ if QT_IMPORT_ERROR is None:
except Exception as exc:
self.model.set_tasks([], [])
self.empty_label.setText("任务读取失败")
_set_batch_progress_overview(self.batch_progress_label, [])
_set_empty_state(self.empty_state_card, self.empty_state_label, self.empty_state_button)
self._set_status(f"任务读取失败:{exc}")
return
self.model.set_tasks(task_rows, account_rows)
self._update_summary(task_rows, account_rows)
_set_batch_progress_overview(self.batch_progress_label, task_rows)
self._update_empty_state(task_rows, account_rows)
self._update_delete_batch_button()