fix(dashboard): display company name instead of ID in health score overview
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user