feat(apply): block abnormal product statuses
This commit is contained in:
+57
-3
@@ -125,7 +125,61 @@ def build_generation_plan(tasks, generate_mode, scope=SCOPE_NORMAL_ONLY) -> dict
|
||||
"execution_tasks": execution_tasks,
|
||||
"scope": normalized_scope,
|
||||
"scope_excluded": len(base_candidates) - len(execution_tasks),
|
||||
"fingerprint": _generation_fingerprint(base_candidates, generate_mode),
|
||||
"fingerprint": _task_plan_fingerprint(base_candidates, generate_mode),
|
||||
}
|
||||
|
||||
|
||||
def build_apply_plan(tasks, update_mode) -> dict:
|
||||
"""Return a status-first, content-aware plan for Shopee update actions."""
|
||||
|
||||
base_candidates = _deduplicate_tasks(tasks)
|
||||
status_counts = {status: 0 for status in VALID_PRODUCT_STATUSES}
|
||||
status_excluded = {
|
||||
STATUS_UNLISTED: [],
|
||||
STATUS_REVIEWING: [],
|
||||
STATUS_UNKNOWN: [],
|
||||
}
|
||||
normal_candidates = []
|
||||
for task in base_candidates:
|
||||
status = _task_status(task)
|
||||
status_counts[status] += 1
|
||||
if status == STATUS_NORMAL:
|
||||
normal_candidates.append(task)
|
||||
else:
|
||||
status_excluded[status].append(task)
|
||||
|
||||
mode = str(update_mode or "").strip().lower()
|
||||
requires_title = mode in {"title", "title_cover"}
|
||||
requires_cover = mode in {"cover", "title_cover"}
|
||||
missing_title = [
|
||||
task
|
||||
for task in normal_candidates
|
||||
if requires_title and not str(_task_value(task, "new_title") or "").strip()
|
||||
]
|
||||
missing_cover = [
|
||||
task
|
||||
for task in normal_candidates
|
||||
if requires_cover and not str(_task_value(task, "new_cover_path") or "").strip()
|
||||
]
|
||||
content_excluded_ids = {id(task) for task in missing_title + missing_cover}
|
||||
executable_tasks = [
|
||||
task for task in normal_candidates if id(task) not in content_excluded_ids
|
||||
]
|
||||
status_excluded_count = sum(len(rows) for rows in status_excluded.values())
|
||||
|
||||
return {
|
||||
"base_candidates": base_candidates,
|
||||
"status_counts": status_counts,
|
||||
"executable": executable_tasks,
|
||||
"unlisted": status_excluded[STATUS_UNLISTED],
|
||||
"reviewing": status_excluded[STATUS_REVIEWING],
|
||||
"unknown": status_excluded[STATUS_UNKNOWN],
|
||||
"missing_title": missing_title,
|
||||
"missing_cover": missing_cover,
|
||||
"status_scope_excluded": status_excluded_count,
|
||||
"content_scope_excluded": len(content_excluded_ids),
|
||||
"scope_excluded": status_excluded_count + len(content_excluded_ids),
|
||||
"fingerprint": _task_plan_fingerprint(base_candidates, update_mode),
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +213,7 @@ def _deduplicate_tasks(tasks) -> list:
|
||||
return unique
|
||||
|
||||
|
||||
def _generation_fingerprint(tasks, generate_mode) -> str:
|
||||
def _task_plan_fingerprint(tasks, mode) -> str:
|
||||
snapshots = [
|
||||
{
|
||||
"task_id": _task_value(task, "id"),
|
||||
@@ -167,7 +221,7 @@ def _generation_fingerprint(tasks, generate_mode) -> str:
|
||||
"product_status": _task_status(task),
|
||||
"new_title": _task_value(task, "new_title"),
|
||||
"new_cover_path": _task_value(task, "new_cover_path"),
|
||||
"generate_mode": str(generate_mode or ""),
|
||||
"mode": str(mode or ""),
|
||||
}
|
||||
for task in tasks
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user