fix(dashboard): total_companies returns 1 in single-company scope; KPI labels adapt

This commit is contained in:
selfrelease
2026-07-20 07:50:39 +08:00
parent e81aa6828e
commit 4265f4bc4c
2 changed files with 11 additions and 8 deletions
+8 -5
View File
@@ -35,11 +35,14 @@ async def get_dashboard_summary(
"""获取仪表盘汇总数据。支持按企业过滤。"""
tenant_id = user.tenant_id
# 企业总数
companies_result = await db.execute(
select(func.count()).select_from(Company).where(Company.tenant_id == tenant_id)
)
total_companies = companies_result.scalar_one()
# 企业总数(单企业视角时为 1
if company_id:
total_companies = 1
else:
companies_result = await db.execute(
select(func.count()).select_from(Company).where(Company.tenant_id == tenant_id)
)
total_companies = companies_result.scalar_one()
# 平均健康度(按企业过滤时只算该企业)
avg_query = (