fix(data): 自动归集空汇总不写0 + Excel导入示例文件防线 (DAMA审计20260906代码类)
This commit is contained in:
@@ -945,6 +945,8 @@ async def api_import_vouchers(
|
|||||||
|
|
||||||
content = await file.read()
|
content = await file.read()
|
||||||
fname = (file.filename or "网银流水.xlsx").strip()
|
fname = (file.filename or "网银流水.xlsx").strip()
|
||||||
|
if any(kw in fname.lower() for kw in ("示例", "sample", "test", "demo", "测试")):
|
||||||
|
raise HTTPException(400, f"文件名含测试标识,拒绝导入生产库: {fname}")
|
||||||
try:
|
try:
|
||||||
df = pd.read_excel(io.BytesIO(content))
|
df = pd.read_excel(io.BytesIO(content))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -123,7 +123,10 @@ def collect_for_mapping(db, mapping: KPIValueSource, period: str, write_kpi: boo
|
|||||||
q = q.filter(model.carry_forward == 0)
|
q = q.filter(model.carry_forward == 0)
|
||||||
|
|
||||||
value = q.scalar()
|
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)
|
value = round(value * unit, 2)
|
||||||
|
|
||||||
message = f"表{table}.{field} {aggregate}(period={period}) × {unit}"
|
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:
|
for m in mappings:
|
||||||
try:
|
try:
|
||||||
value, message = collect_for_mapping(db, m, period, write_kpi=True)
|
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(
|
db.add(KPIValueCollectLog(
|
||||||
entity_id=m.entity_id,
|
entity_id=m.entity_id,
|
||||||
kpi_id=m.kpi_id,
|
kpi_id=m.kpi_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user