Commit 65293ff9 65293ff9412649bf7692cf7950db50f9fb3c0cb6 by 沈秋雨

feat(audit): 新增 --delete-zero-duration 软删 song_time=0 记录

1 parent 666fd63f
......@@ -558,9 +558,52 @@ def main() -> int:
help="补处理暂存表中 merge+skipped 记录:existing_into_new 入库+软删旧记录,new_into_existing 补作者合并",
)
parser.add_argument("--skip-oss", action="store_true", help="--fix-merge 时跳过歌词 OSS 上传,保留原始文本")
parser.add_argument("--dry-run", action="store_true", help="仅打印计划,不写库(配合 --fix-merge 使用)")
parser.add_argument("--dry-run", action="store_true", help="仅打印计划,不写库(配合 --fix-merge / --delete-zero-duration 使用)")
parser.add_argument(
"--delete-zero-duration",
action="store_true",
help="软删除 song_time=0 的记录(置 deleted='1')",
)
args = parser.parse_args()
# --delete-zero-duration 模式
if args.delete_zero_duration:
conn = pymysql.connect(**TARGET_DB_CONFIG)
try:
table = quote_identifier(DEFAULT_TARGET_TABLE)
with conn.cursor() as cursor:
cursor.execute(
f"SELECT id, name, lyricist, composer, song_time "
f"FROM {table} WHERE deleted = '0' AND song_time = 0"
)
rows = list(cursor.fetchall())
print(f"song_time=0 记录数: {len(rows)}")
if args.dry_run:
for row in rows[:20]:
print(row)
if len(rows) > 20:
print(f"... {len(rows) - 20} more rows")
return 0
if not rows:
print("无需处理")
return 0
ids = [row["id"] for row in rows]
placeholders = ",".join(["%s"] * len(ids))
with conn.cursor() as cursor:
cursor.execute(
f"UPDATE {table} "
f"SET deleted = '1', modify_time = NOW(), "
f" off_shelf_remark = 'song_time=0 soft-deleted by audit script' "
f"WHERE deleted = '0' AND id IN ({placeholders})",
ids,
)
affected = cursor.rowcount
conn.commit()
print(f"soft_deleted={affected}")
finally:
conn.close()
return 0
# --fix-merge 模式:连双库,执行合并方向后处理
if args.fix_merge:
target_conn = pymysql.connect(**TARGET_DB_CONFIG)
......