This commit is contained in:
HuangHai
2026-01-15 10:47:59 +08:00
parent 9d9b95037f
commit 3e5ddc587c
9 changed files with 136 additions and 43 deletions

View File

@@ -28,7 +28,7 @@ except ModuleNotFoundError:
# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger("T5_ClearHistory")
logger = logging.getLogger("T6_ClearHistory")
# 供应商配置映射
VENDORS = {
@@ -75,23 +75,31 @@ async def clear_vendor_data(db: Db, redis_kit: RedisKit, vendor_info: Dict, mode
# 分批执行删除,防止 SQL 语句过长
batch_size = 500
total_status_deleted = 0
total_price_deleted = 0
for i in range(0, len(station_hashes), batch_size):
batch = station_hashes[i:i + batch_size]
# 1. t_station_status_scd
sql_status = f"DELETE FROM t_station_status_scd WHERE station_hash IN :hashes {where_clause}"
res_status = await session.execute(text(sql_status), {"hashes": batch})
total_status_deleted += res_status.rowcount
# 2. t_station_price_schedule_scd
sql_price = f"DELETE FROM t_station_price_schedule_scd WHERE station_hash IN :hashes {where_clause}"
res_price = await session.execute(text(sql_price), {"hashes": batch})
total_price_deleted += res_price.rowcount
logger.info(f"[{operator}] 已处理场站分批 {i//batch_size + 1},删除状态记录 {res_status.rowcount} 条,价格记录 {res_price.rowcount} 条。")
logger.info(f"[{operator}] 正在处理分批 {i//batch_size + 1}/{ (len(station_hashes)-1)//batch_size + 1}...")
logger.info(f"[{operator}] 表 t_station_status_scd 清理完成,共删除 {total_status_deleted} 条记录。")
logger.info(f"[{operator}] 表 t_station_price_schedule_scd 清理完成,共删除 {total_price_deleted} 条记录。")
# 3. 最后删除主表记录
sql_profile = f"DELETE FROM t_station_profile_scd WHERE operator = :operator {where_clause}"
res_profile = await session.execute(text(sql_profile) , {"operator": operator})
logger.info(f"[{operator}] t_station_profile_scd 表清理完成,删除 {res_profile.rowcount} 行。")
logger.info(f"[{operator}] 表 t_station_profile_scd 清理完成,共删除 {res_profile.rowcount} 条记录。")
logger.info(f"[{operator}] 数据库记录清理完成。")
except Exception as e: