fix(data): 自动归集空汇总不写0 + Excel导入示例文件防线 (DAMA审计20260906代码类)
This commit is contained in:
@@ -123,7 +123,10 @@ def collect_for_mapping(db, mapping: KPIValueSource, period: str, write_kpi: boo
|
||||
q = q.filter(model.carry_forward == 0)
|
||||
|
||||
value = q.scalar()
|
||||
value = float(value or 0)
|
||||
if value is None:
|
||||
# 源表无记录 → 不写 0,交由 run_collector 记 skipped,避免污染 KPI 实际值
|
||||
return None, "源表无记录"
|
||||
value = float(value)
|
||||
value = round(value * unit, 2)
|
||||
|
||||
message = f"表{table}.{field} {aggregate}(period={period}) × {unit}"
|
||||
@@ -185,6 +188,18 @@ def run_collector(db, entity_id: Optional[int] = None, period: Optional[str] = N
|
||||
for m in mappings:
|
||||
try:
|
||||
value, message = collect_for_mapping(db, m, period, write_kpi=True)
|
||||
if value is None:
|
||||
# 源表无记录 → 跳过,不落 pending=0 的 KPIValue
|
||||
db.add(KPIValueCollectLog(
|
||||
entity_id=m.entity_id,
|
||||
kpi_id=m.kpi_id,
|
||||
period=period,
|
||||
source_table=m.source_table,
|
||||
collected_value=None,
|
||||
status="skipped",
|
||||
message=message,
|
||||
))
|
||||
continue
|
||||
db.add(KPIValueCollectLog(
|
||||
entity_id=m.entity_id,
|
||||
kpi_id=m.kpi_id,
|
||||
|
||||
Reference in New Issue
Block a user