feat(product-suite): confirm prior successful generations
This commit is contained in:
@@ -1395,7 +1395,14 @@ class ProductSuiteGlobalHistoryDialog(QDialog):
|
||||
|
||||
PAGE_SIZE = 30
|
||||
|
||||
def __init__(self, *, current_project_id=None, db_path=None, parent=None):
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
current_project_id=None,
|
||||
current_project_only=False,
|
||||
db_path=None,
|
||||
parent=None,
|
||||
):
|
||||
super().__init__(parent)
|
||||
self.db_path = db_path
|
||||
self.current_project_id = None
|
||||
@@ -1490,6 +1497,7 @@ class ProductSuiteGlobalHistoryDialog(QDialog):
|
||||
layout.addWidget(self.load_more_button, 0, Qt.AlignHCenter)
|
||||
|
||||
self.set_current_project(current_project_id, refresh=False)
|
||||
self.set_current_project_filter(current_project_only, refresh=False)
|
||||
self.refresh_history()
|
||||
|
||||
def set_current_project(self, project_id, *, refresh=True):
|
||||
@@ -1512,6 +1520,15 @@ class ProductSuiteGlobalHistoryDialog(QDialog):
|
||||
if refresh and (changed or self.current_project_checkbox.isChecked()):
|
||||
self.refresh_history()
|
||||
|
||||
def set_current_project_filter(self, enabled, *, refresh=True):
|
||||
should_filter = bool(enabled) and self.current_project_id is not None
|
||||
changed = self.current_project_checkbox.isChecked() != should_filter
|
||||
previous = self.current_project_checkbox.blockSignals(True)
|
||||
self.current_project_checkbox.setChecked(should_filter)
|
||||
self.current_project_checkbox.blockSignals(previous)
|
||||
if refresh and changed:
|
||||
self.refresh_history()
|
||||
|
||||
def refresh_history(self, checked=False):
|
||||
scroll_value = self.scroll.verticalScrollBar().value()
|
||||
self._clear_history_content()
|
||||
@@ -2309,6 +2326,40 @@ class ProductSuiteTab(QWidget):
|
||||
box.exec()
|
||||
return box.clickedButton() is confirm_button
|
||||
|
||||
def _confirm_new_generation_history(self, state, summary):
|
||||
item_id = str(state.item_id or "临时草稿")
|
||||
account_text = self._account_context_label(state)
|
||||
latest = str(summary.latest_succeeded_at or "").replace("T", " ")
|
||||
lines = [
|
||||
"%s" % account_text,
|
||||
"商品ID:%s" % item_id,
|
||||
"该商品已有成功套图:%d轮,%d张。"
|
||||
% (
|
||||
int(summary.successful_round_count),
|
||||
int(summary.successful_image_count),
|
||||
),
|
||||
]
|
||||
if latest:
|
||||
lines.append("最近成功时间:%s" % latest)
|
||||
lines.append("继续会创建新一轮生成,已有历史结果会保留。")
|
||||
|
||||
box = QMessageBox(self)
|
||||
box.setIcon(QMessageBox.Warning)
|
||||
box.setWindowTitle("已有套图生成记录")
|
||||
box.setText("\n".join(lines))
|
||||
history_button = box.addButton("查看历史", QMessageBox.ActionRole)
|
||||
continue_button = box.addButton("继续生成新一轮", QMessageBox.AcceptRole)
|
||||
cancel_button = box.addButton("取消", QMessageBox.RejectRole)
|
||||
box.setDefaultButton(cancel_button)
|
||||
box.setEscapeButton(cancel_button)
|
||||
box.exec()
|
||||
clicked = box.clickedButton()
|
||||
if clicked is history_button:
|
||||
return "history"
|
||||
if clicked is continue_button:
|
||||
return "continue"
|
||||
return "cancel"
|
||||
|
||||
def refresh_accounts(self):
|
||||
selected = self.account_combo.currentData()
|
||||
try:
|
||||
@@ -4192,6 +4243,31 @@ class ProductSuiteTab(QWidget):
|
||||
spec["generation_slot_index"] = original_job.generation_slot_index
|
||||
generation_round_key = str(original_job.generation_round_key or "")
|
||||
else:
|
||||
if confirm_batch:
|
||||
try:
|
||||
history_summary = image_studio.get_successful_generation_history_summary(
|
||||
state.project_id,
|
||||
path=self.db_path,
|
||||
)
|
||||
except Exception:
|
||||
self._message(
|
||||
"读取套图历史失败",
|
||||
"暂时无法确认该商品是否已有成功套图,请稍后重试。",
|
||||
)
|
||||
return False
|
||||
if history_summary.successful_round_count:
|
||||
decision = self._confirm_new_generation_history(
|
||||
state,
|
||||
history_summary,
|
||||
)
|
||||
if decision == "history":
|
||||
self.open_history_dialog(
|
||||
current_project_only=True,
|
||||
current_project_id=state.project_id,
|
||||
)
|
||||
return False
|
||||
if decision != "continue":
|
||||
return False
|
||||
generation_round_key = uuid.uuid4().hex
|
||||
for slot_index, spec in enumerate(specs):
|
||||
spec["generation_round_key"] = generation_round_key
|
||||
@@ -4910,14 +4986,25 @@ class ProductSuiteTab(QWidget):
|
||||
self.result_summary_label.setText("共 %d 张 · 成功 %d 张" % (len(jobs), success))
|
||||
self.undo_button.setVisible(bool(state.undo_records))
|
||||
|
||||
def open_history_dialog(self, checked=False):
|
||||
def open_history_dialog(
|
||||
self,
|
||||
checked=False,
|
||||
*,
|
||||
current_project_only=False,
|
||||
current_project_id=None,
|
||||
):
|
||||
state = self._displayed_state
|
||||
current_project_id = state.project_id if state is not None else None
|
||||
if current_project_id is None:
|
||||
current_project_id = state.project_id if state is not None else None
|
||||
|
||||
dialog = self._history_dialog
|
||||
if dialog is not None:
|
||||
try:
|
||||
dialog.set_current_project(current_project_id, refresh=False)
|
||||
dialog.set_current_project_filter(
|
||||
current_project_only,
|
||||
refresh=False,
|
||||
)
|
||||
dialog.refresh_history()
|
||||
dialog.show()
|
||||
dialog.raise_()
|
||||
@@ -4929,6 +5016,7 @@ class ProductSuiteTab(QWidget):
|
||||
|
||||
dialog = ProductSuiteGlobalHistoryDialog(
|
||||
current_project_id=current_project_id,
|
||||
current_project_only=current_project_only,
|
||||
db_path=self.db_path,
|
||||
parent=self,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user