From 8138fb5540b12bce7280268b2afe5eee4ae49022 Mon Sep 17 00:00:00 2001 From: selfrelease Date: Sun, 19 Jul 2026 21:39:49 +0800 Subject: [PATCH] fix(dashboard): display company name instead of ID in health score overview --- backend/app/routers/dashboard.py | 27 ++++++++++++------- backend/app/schemas/health_score.py | 1 + .../src/app/(investor)/dashboard/page.tsx | 2 +- frontend/src/lib/dashboard.ts | 1 + 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/backend/app/routers/dashboard.py b/backend/app/routers/dashboard.py index ae3ff2a..377f786 100644 --- a/backend/app/routers/dashboard.py +++ b/backend/app/routers/dashboard.py @@ -69,16 +69,20 @@ async def get_dashboard_summary( # 最近评分(最多 10 条) recent_result = await db.execute( - select(HealthScore) + select(HealthScore, Company.name.label("company_name")) .join(Company, HealthScore.company_id == Company.id) .where(Company.tenant_id == tenant_id) .order_by(HealthScore.calculated_at.desc()) .limit(10) ) - recent_scores = [ - HealthScoreResponse.model_validate(s, from_attributes=True) - for s in recent_result.scalars().all() - ] + recent_rows = recent_result.all() + recent_scores = [] + for row in recent_rows: + score = row[0] + company_name = row[1] + resp = HealthScoreResponse.model_validate(score, from_attributes=True) + resp.company_name = company_name + recent_scores.append(resp) return success( data=DashboardSummary( @@ -100,7 +104,7 @@ async def list_health_scores( ): """获取健康度评分列表。""" query = ( - select(HealthScore) + select(HealthScore, Company.name.label("company_name")) .join(Company, HealthScore.company_id == Company.id) .where(Company.tenant_id == user.tenant_id) ) @@ -109,10 +113,13 @@ async def list_health_scores( query = query.order_by(HealthScore.calculated_at.desc()).limit(limit) result = await db.execute(query) - scores = [ - HealthScoreResponse.model_validate(s, from_attributes=True) - for s in result.scalars().all() - ] + scores = [] + for row in result.all(): + score = row[0] + company_name = row[1] + resp = HealthScoreResponse.model_validate(score, from_attributes=True) + resp.company_name = company_name + scores.append(resp) return success(data=scores) diff --git a/backend/app/schemas/health_score.py b/backend/app/schemas/health_score.py index e5a2b78..21f753b 100644 --- a/backend/app/schemas/health_score.py +++ b/backend/app/schemas/health_score.py @@ -9,6 +9,7 @@ class HealthScoreResponse(BaseModel): id: str company_id: str + company_name: str | None = None total_score: float financial_score: float | None = None operational_score: float | None = None diff --git a/frontend/src/app/(investor)/dashboard/page.tsx b/frontend/src/app/(investor)/dashboard/page.tsx index 3c760dd..a2e2f20 100644 --- a/frontend/src/app/(investor)/dashboard/page.tsx +++ b/frontend/src/app/(investor)/dashboard/page.tsx @@ -120,7 +120,7 @@ export default function InvestorDashboardPage() {
-

企业 ID: {score.company_id.slice(0, 8)}...

+

{score.company_name ?? `企业 ${score.company_id.slice(0, 8)}`}

{new Date(score.calculated_at).toLocaleDateString("zh-CN")}

diff --git a/frontend/src/lib/dashboard.ts b/frontend/src/lib/dashboard.ts index 689c399..cbf126b 100644 --- a/frontend/src/lib/dashboard.ts +++ b/frontend/src/lib/dashboard.ts @@ -6,6 +6,7 @@ import { apiFetch, type ApiResponse } from "./api"; export interface HealthScore { id: string; company_id: string; + company_name: string | null; total_score: number; financial_score: number | null; operational_score: number | null;