feat(product-suite): refine history account filters

This commit is contained in:
chengma
2026-07-17 11:00:02 +08:00
parent 9f55dcd4f0
commit 098dc667b3
8 changed files with 195 additions and 31 deletions
+51 -12
View File
@@ -1449,12 +1449,11 @@ class ProductSuiteGlobalHistoryDialog(QDialog):
filters = QHBoxLayout()
filters.setSpacing(8)
filters.addWidget(QLabel("店铺"))
self.account_filter_edit = QLineEdit()
self.account_filter_edit.setObjectName("suiteGlobalHistoryAccountFilter")
self.account_filter_edit.setPlaceholderText("店铺或账号")
self.account_filter_edit.setClearButtonEnabled(True)
self.account_filter_edit.returnPressed.connect(self.refresh_history)
filters.addWidget(self.account_filter_edit, 1)
self.account_filter_combo = QComboBox()
self.account_filter_combo.setObjectName("suiteGlobalHistoryAccountFilter")
self.account_filter_combo.setToolTip("选择要查看历史生成记录的店铺")
self.account_filter_combo.currentIndexChanged.connect(self.refresh_history)
filters.addWidget(self.account_filter_combo, 1)
filters.addWidget(QLabel("商品ID"))
self.item_filter_edit = QLineEdit()
self.item_filter_edit.setObjectName("suiteGlobalHistoryItemFilter")
@@ -1531,6 +1530,11 @@ class ProductSuiteGlobalHistoryDialog(QDialog):
def refresh_history(self, checked=False):
scroll_value = self.scroll.verticalScrollBar().value()
try:
self._refresh_account_filter_options()
except Exception as exc:
self._set_error("历史店铺读取失败:%s" % _user_error(exc))
return
self._clear_history_content()
self._offset = 0
self._has_more = False
@@ -1558,7 +1562,7 @@ class ProductSuiteGlobalHistoryDialog(QDialog):
else None
)
rounds = image_studio.list_global_generation_rounds(
account_query=self.account_filter_edit.text(),
account_alias=self.account_filter_combo.currentData(),
item_query=self.item_filter_edit.text(),
project_id=project_id,
limit=self.PAGE_SIZE,
@@ -1582,6 +1586,45 @@ class ProductSuiteGlobalHistoryDialog(QDialog):
self._update_summary()
return True
def _refresh_account_filter_options(self):
selected_alias = self.account_filter_combo.currentData()
current_accounts = accounts.list_accounts(path=self.db_path)
history_accounts = image_studio.list_global_history_accounts(path=self.db_path)
active_by_alias = {}
for account in current_accounts:
alias = str(getattr(account, "alias", "") or "").strip()
if alias:
active_by_alias[alias] = account
previous = self.account_filter_combo.blockSignals(True)
try:
self.account_filter_combo.clear()
self.account_filter_combo.addItem("全部店铺", None)
for alias in sorted(
active_by_alias,
key=lambda value: (value.casefold(), value),
):
account = active_by_alias[alias]
account_name = str(getattr(account, "account_name", "") or "").strip()
self.account_filter_combo.addItem(
"%s(%s)" % (account_name or alias, alias),
alias,
)
for history_account in history_accounts:
alias = str(getattr(history_account, "account_alias", "") or "").strip()
if alias and alias not in active_by_alias:
self.account_filter_combo.addItem(
"历史店铺:%s(账号已删除)" % alias,
alias,
)
selected_index = self.account_filter_combo.findData(selected_alias)
self.account_filter_combo.setCurrentIndex(
selected_index if selected_index >= 0 else 0
)
finally:
self.account_filter_combo.blockSignals(previous)
def _add_round(self, round_info):
try:
jobs = image_studio.list_generation_round_current_jobs(
@@ -1938,11 +1981,8 @@ class ProductSuiteTab(QWidget):
layout.setSpacing(8)
self.history_button = QPushButton("历史生成")
self.history_button.setObjectName("suiteHistoryButton")
self.history_button.setToolTip("查看当前商品的历史生成记录")
self.history_button.setToolTip("查看所有商品的历史生成记录")
layout.addWidget(self.history_button)
self.open_folder_button = QPushButton("打开结果文件夹")
self.open_folder_button.setObjectName("suiteOpenFolderButton")
layout.addWidget(self.open_folder_button)
self.add_images_button = QPushButton("添加图片")
self.add_images_button.setObjectName("suiteAddImagesButton")
self.add_images_button.setAccessibleName("添加商品原图")
@@ -2292,7 +2332,6 @@ class ProductSuiteTab(QWidget):
self.custom_category_edit.editingFinished.connect(self._finish_custom_category_edit)
self.generate_button.clicked.connect(self.toggle_generation)
self.history_button.clicked.connect(self.open_history_dialog)
self.open_folder_button.clicked.connect(self.open_project_folder)
self.undo_button.clicked.connect(self.undo_delete)
self.more_button.clicked.connect(self._show_more_menu)
+40 -1
View File
@@ -151,6 +151,13 @@ class ImageStudioHistoryRound:
is_legacy: bool
@dataclass(frozen=True)
class ImageStudioHistoryAccount:
"""One account alias retained by active product-suite history."""
account_alias: str
@dataclass(frozen=True)
class ImageStudioSuccessfulGenerationHistorySummary:
"""Successful persisted output summary for one active product project."""
@@ -1379,8 +1386,36 @@ def get_successful_generation_history_summary(project_id, path=None, conn=None):
)
def list_global_history_accounts(path=None, conn=None):
"""List account aliases retained by non-deleted product-suite history."""
sql = """
SELECT projects.account_alias AS account_alias
FROM image_studio_projects AS projects
WHERE projects.deleted_at IS NULL
AND TRIM(COALESCE(projects.account_alias, '')) <> ''
AND EXISTS (
SELECT 1
FROM image_studio_jobs AS jobs
WHERE jobs.project_id = projects.id
)
GROUP BY projects.account_alias
ORDER BY projects.account_alias COLLATE NOCASE ASC,
projects.account_alias ASC
"""
with _connection(conn, path) as database:
rows = database.execute(sql).fetchall()
return [
ImageStudioHistoryAccount(
account_alias=str(row["account_alias"] or ""),
)
for row in rows
]
def list_global_generation_rounds(
*,
account_alias=None,
account_query="",
item_query="",
project_id=None,
@@ -1411,8 +1446,12 @@ def list_global_generation_rounds(
params.append(int(project_id))
except (TypeError, ValueError) as exc:
raise db.DbError("当前商品项目无效") from exc
account_alias_text = str(account_alias or "").strip()
account_text = str(account_query or "").strip()
if account_text:
if account_alias_text:
clauses.append("projects.account_alias = ?")
params.append(account_alias_text)
if not account_alias_text and account_text:
pattern = "%%%s%%" % account_text
clauses.append(
"(projects.account_alias LIKE ? OR COALESCE(projects.account_name, '') LIKE ?)"