feat(generate): confirm product status scope
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
from PySide6.QtCore import QEvent, QRectF, QSize
|
||||
from PySide6.QtGui import QColor, QPainter
|
||||
|
||||
from ... import product_status
|
||||
from .. import file_manager
|
||||
from ..models import GenerateTaskTableModel
|
||||
from ..widgets import *
|
||||
@@ -1732,16 +1733,33 @@ class GenerateTab(QWidget):
|
||||
return
|
||||
generate_mode = self._current_generate_mode()
|
||||
generate_cover = appconfig.generate_mode_includes_cover(generate_mode)
|
||||
tasks = [
|
||||
task for task in self.model.tasks
|
||||
if ai.is_generatable_task(task, generate_mode=generate_mode)
|
||||
]
|
||||
if not tasks:
|
||||
base_candidates = self._generation_candidates(generate_mode)
|
||||
if not base_candidates:
|
||||
if generate_mode == "cover":
|
||||
self._set_status("当前筛选结果没有可生成的封面;请确认商品已完成采集且尚未生成新封面。")
|
||||
else:
|
||||
self._set_status("当前筛选结果没有可生成的缺失内容;请先在①导入采集完成采集,或调整生成内容")
|
||||
return
|
||||
preview_plan = product_status.build_generation_plan(
|
||||
base_candidates,
|
||||
generate_mode,
|
||||
)
|
||||
generation_scope = self._choose_generation_scope(preview_plan)
|
||||
if generation_scope is None:
|
||||
self._set_status("已取消 AI 生成")
|
||||
return
|
||||
current_plan = product_status.build_generation_plan(
|
||||
self._generation_candidates(generate_mode),
|
||||
generate_mode,
|
||||
generation_scope,
|
||||
)
|
||||
if current_plan["fingerprint"] != preview_plan["fingerprint"]:
|
||||
self._set_status("当前任务数据已变化,请重新开始生成")
|
||||
return
|
||||
tasks = current_plan["execution_tasks"]
|
||||
if not tasks:
|
||||
self._set_status("当前筛选结果没有状态正常的可生成任务;请先完成采集或选择生成所有状态的商品")
|
||||
return
|
||||
component_totals = ai.generation_component_totals(
|
||||
tasks,
|
||||
generate_mode=generate_mode,
|
||||
@@ -1756,6 +1774,10 @@ class GenerateTab(QWidget):
|
||||
db_path=self.db_path,
|
||||
config=self.config,
|
||||
diagnostic_log_dir=diagnostics.DEFAULT_LOG_DIR,
|
||||
generation_scope=generation_scope,
|
||||
product_status_counts=current_plan["status_counts"],
|
||||
status_scope_excluded=current_plan["scope_excluded"],
|
||||
generation_plan_fingerprint=current_plan["fingerprint"],
|
||||
)
|
||||
worker.progress.connect(self._on_generate_progress)
|
||||
worker.row_updated.connect(self._on_generate_row_updated)
|
||||
@@ -1790,6 +1812,54 @@ class GenerateTab(QWidget):
|
||||
self._set_status(f"开始 AI 生成:{len(tasks)} 条")
|
||||
thread.start()
|
||||
|
||||
def _generation_candidates(self, generate_mode):
|
||||
return [
|
||||
task
|
||||
for task in self.model.tasks
|
||||
if ai.is_generatable_task(task, generate_mode=generate_mode)
|
||||
]
|
||||
|
||||
def _choose_generation_scope(self, plan):
|
||||
status_counts = dict(plan.get("status_counts") or {})
|
||||
normal_count = status_counts.get(product_status.STATUS_NORMAL, 0)
|
||||
unlisted_count = status_counts.get(product_status.STATUS_UNLISTED, 0)
|
||||
reviewing_count = status_counts.get(product_status.STATUS_REVIEWING, 0)
|
||||
unknown_count = status_counts.get(product_status.STATUS_UNKNOWN, 0)
|
||||
total = len(plan.get("base_candidates") or [])
|
||||
non_normal_count = total - normal_count
|
||||
|
||||
box = QMessageBox(self)
|
||||
box.setIcon(QMessageBox.Question)
|
||||
box.setWindowTitle("选择生成范围")
|
||||
box.setText("请选择本轮要生成的商品范围。")
|
||||
box.setInformativeText(
|
||||
"真实候选共{total}条:正常{normal},未上架{unlisted},审核中{reviewing},状态未知{unknown}。\n"
|
||||
"生成所有状态的商品会让非正常状态商品也调用 AI,可能额外消耗点数。"
|
||||
"状态未知商品请优先回到①重新采集确认。".format(
|
||||
total=total,
|
||||
normal=normal_count,
|
||||
unlisted=unlisted_count,
|
||||
reviewing=reviewing_count,
|
||||
unknown=unknown_count,
|
||||
)
|
||||
)
|
||||
normal_button = box.addButton("只生成状态正常的商品", QMessageBox.AcceptRole)
|
||||
normal_button.setObjectName("generateNormalOnlyButton")
|
||||
all_button = box.addButton("生成所有状态的商品", QMessageBox.DestructiveRole)
|
||||
all_button.setObjectName("generateAllStatusesButton")
|
||||
all_button.setStyleSheet("color: #cf222e; font-weight: 600;")
|
||||
all_button.setEnabled(non_normal_count > 0)
|
||||
cancel_button = box.addButton("取消", QMessageBox.RejectRole)
|
||||
cancel_button.setObjectName("generateScopeCancelButton")
|
||||
box.setDefaultButton(normal_button)
|
||||
box.setEscapeButton(cancel_button)
|
||||
box.exec()
|
||||
if box.clickedButton() is normal_button:
|
||||
return product_status.SCOPE_NORMAL_ONLY
|
||||
if all_button.isEnabled() and box.clickedButton() is all_button:
|
||||
return product_status.SCOPE_ALL
|
||||
return None
|
||||
|
||||
def stop_generate(self, checked=False):
|
||||
if self.generate_worker is not None:
|
||||
self.generate_worker.cancel()
|
||||
|
||||
Reference in New Issue
Block a user