fix(dashboard): display company name instead of ID in health score overview

This commit is contained in:
selfrelease
2026-07-19 21:39:49 +08:00
parent 4980ebcd30
commit 8138fb5540
4 changed files with 20 additions and 11 deletions
+17 -10
View File
@@ -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)
+1
View File
@@ -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
@@ -120,7 +120,7 @@ export default function InvestorDashboardPage() {
<div className="flex items-center gap-3">
<HealthScoreBadge score={Math.round(score.total_score)} />
<div>
<p className="text-sm font-medium"> ID: {score.company_id.slice(0, 8)}...</p>
<p className="text-sm font-medium">{score.company_name ?? `企业 ${score.company_id.slice(0, 8)}`}</p>
<p className="text-xs text-muted-foreground">
{new Date(score.calculated_at).toLocaleDateString("zh-CN")}
</p>
+1
View File
@@ -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;