fix(dashboard): total_companies returns 1 in single-company scope; KPI labels adapt
This commit is contained in:
@@ -35,11 +35,14 @@ async def get_dashboard_summary(
|
|||||||
"""获取仪表盘汇总数据。支持按企业过滤。"""
|
"""获取仪表盘汇总数据。支持按企业过滤。"""
|
||||||
tenant_id = user.tenant_id
|
tenant_id = user.tenant_id
|
||||||
|
|
||||||
# 企业总数
|
# 企业总数(单企业视角时为 1)
|
||||||
companies_result = await db.execute(
|
if company_id:
|
||||||
select(func.count()).select_from(Company).where(Company.tenant_id == tenant_id)
|
total_companies = 1
|
||||||
)
|
else:
|
||||||
total_companies = companies_result.scalar_one()
|
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 = (
|
avg_query = (
|
||||||
|
|||||||
@@ -45,15 +45,15 @@ export default function InvestorDashboardPage() {
|
|||||||
|
|
||||||
const kpis = [
|
const kpis = [
|
||||||
{
|
{
|
||||||
label: "被投企业",
|
label: companyName ? "当前企业" : "被投企业",
|
||||||
value: summary?.total_companies ?? 0,
|
value: companyName ?? (summary?.total_companies ?? 0),
|
||||||
icon: Building2,
|
icon: Building2,
|
||||||
href: "/companies",
|
href: "/companies",
|
||||||
color: "text-[var(--investor-primary)]",
|
color: "text-[var(--investor-primary)]",
|
||||||
bg: "bg-[var(--investor-primary)]/10",
|
bg: "bg-[var(--investor-primary)]/10",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "平均健康度",
|
label: "健康度",
|
||||||
value: summary?.avg_health_score?.toFixed(1) ?? "0.0",
|
value: summary?.avg_health_score?.toFixed(1) ?? "0.0",
|
||||||
icon: Heart,
|
icon: Heart,
|
||||||
href: "/companies",
|
href: "/companies",
|
||||||
|
|||||||
Reference in New Issue
Block a user