Commit 6c676159 by zhouhaibao

fix(budget): 将 renovation_amortization NULL 值默认为 0

- 在 clean_budget_achievement.py 中新增先清逻辑,将任务所有行的 renovation_amortization 置为 0,确保未匹配行不再保持 NULL
- 在 processor.py 的 biz_budget_achieve 更新语句中增加 COALESCE(renovation_amortization, 0) 处理
- 更新日志信息,将"未匹配行保持 NULL"改为"未匹配行已默认为 0"
1 parent 77c29fc6
...@@ -1067,8 +1067,22 @@ def process_renovation(conn, task_id, stat_month, dry_run=False): ...@@ -1067,8 +1067,22 @@ def process_renovation(conn, task_id, stat_month, dry_run=False):
if dry_run: if dry_run:
return (len(amounts), unmatched) return (len(amounts), unmatched)
# 先清:把该任务所有行 renovation_amortization 置 0,确保未匹配行默认为 0
# (update_renovation 只写匹配命中的行,其他行需要明确的 0 而非 NULL)
try:
with conn.cursor() as cur:
cur.execute(
f"UPDATE {TARGET_TABLE} SET renovation_amortization = 0 "
"WHERE task_id = %s AND stat_month = %s",
(task_id, stat_month),
)
conn.commit()
log(f' 先清 renovation_amortization:影响 {cur.rowcount} 行')
except Exception:
conn.rollback()
raise
updated = update_renovation(conn, amounts) updated = update_renovation(conn, amounts)
log(f' 写入 renovation_amortization:更新 {updated} 行(未匹配行保持 NULL)') log(f' 写入 renovation_amortization:更新 {updated} 行(未匹配行已默认为 0)')
return (updated, unmatched) return (updated, unmatched)
......
...@@ -1540,6 +1540,7 @@ class DataProcessor: ...@@ -1540,6 +1540,7 @@ class DataProcessor:
_cur.execute(""" _cur.execute("""
UPDATE biz_budget_achieve UPDATE biz_budget_achieve
SET rent_utilities = 0, SET rent_utilities = 0,
renovation_amortization = COALESCE(renovation_amortization, 0),
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE task_id = %s AND stat_month = %s WHERE task_id = %s AND stat_month = %s
""", (task.id, task.month)) """, (task.id, task.month))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!