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 条) # 最近评分(最多 10 条)
recent_result = await db.execute( recent_result = await db.execute(
select(HealthScore) select(HealthScore, Company.name.label("company_name"))
.join(Company, HealthScore.company_id == Company.id) .join(Company, HealthScore.company_id == Company.id)
.where(Company.tenant_id == tenant_id) .where(Company.tenant_id == tenant_id)
.order_by(HealthScore.calculated_at.desc()) .order_by(HealthScore.calculated_at.desc())
.limit(10) .limit(10)
) )
recent_scores = [ recent_rows = recent_result.all()
HealthScoreResponse.model_validate(s, from_attributes=True) recent_scores = []
for s in recent_result.scalars().all() 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( return success(
data=DashboardSummary( data=DashboardSummary(
@@ -100,7 +104,7 @@ async def list_health_scores(
): ):
"""获取健康度评分列表。""" """获取健康度评分列表。"""
query = ( query = (
select(HealthScore) select(HealthScore, Company.name.label("company_name"))
.join(Company, HealthScore.company_id == Company.id) .join(Company, HealthScore.company_id == Company.id)
.where(Company.tenant_id == user.tenant_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) query = query.order_by(HealthScore.calculated_at.desc()).limit(limit)
result = await db.execute(query) result = await db.execute(query)
scores = [ scores = []
HealthScoreResponse.model_validate(s, from_attributes=True) for row in result.all():
for s in result.scalars().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) return success(data=scores)
+1
View File
@@ -9,6 +9,7 @@ class HealthScoreResponse(BaseModel):
id: str id: str
company_id: str company_id: str
company_name: str | None = None
total_score: float total_score: float
financial_score: float | None = None financial_score: float | None = None
operational_score: float | None = None operational_score: float | None = None
@@ -120,7 +120,7 @@ export default function InvestorDashboardPage() {
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<HealthScoreBadge score={Math.round(score.total_score)} /> <HealthScoreBadge score={Math.round(score.total_score)} />
<div> <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"> <p className="text-xs text-muted-foreground">
{new Date(score.calculated_at).toLocaleDateString("zh-CN")} {new Date(score.calculated_at).toLocaleDateString("zh-CN")}
</p> </p>
+1
View File
@@ -6,6 +6,7 @@ import { apiFetch, type ApiResponse } from "./api";
export interface HealthScore { export interface HealthScore {
id: string; id: string;
company_id: string; company_id: string;
company_name: string | null;
total_score: number; total_score: number;
financial_score: number | null; financial_score: number | null;
operational_score: number | null; operational_score: number | null;