From 0b305e3ab3d8b8fed12eb28e8ebac1b7d4a43534 Mon Sep 17 00:00:00 2001 From: Hermes CI Fix Date: Tue, 18 Aug 2026 09:54:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9D=9C=E9=82=A6=E5=88=86=E6=9E=90peri?= =?UTF-8?q?od=E6=A0=BC=E5=BC=8F=E5=85=BC=E5=AE=B9=20=E2=80=94=202026H1/202?= =?UTF-8?q?6-H1=E5=8F=98=E4=BD=93=E5=8C=B9=E9=85=8D=EF=BC=8C=E9=85=A3?= =?UTF-8?q?=E5=AE=A2ROE=E6=AD=A3=E5=B8=B8=E8=BF=94=E5=9B=9E-12.74%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _get_dupont_kpi支持6字符(2026H1)和7字符(2026-H1)period格式 - 之前数据库存'2026-H1'但API查'2026H1'导致读不到数据,酣客ROE返回None - 验证:酣客ROE=-12.74%(净利率-12.74%,亏损企业正确为负) --- backend/app/api/reports.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/app/api/reports.py b/backend/app/api/reports.py index 357e0040..22469d09 100644 --- a/backend/app/api/reports.py +++ b/backend/app/api/reports.py @@ -1846,9 +1846,18 @@ def _get_dupont_kpi(db: Session, entity_id: int, kpi_code: str, period: str = "2 ).first() if not kpi: return None + # 兼容period格式:数据库存"2026-H1",查询可能传"2026H1" + period_variants = [period] + if period: + # "2026H1"(6字符) → 补横线 "2026-H1" + if len(period) == 6: + period_variants.append(period[:4] + "-" + period[4:]) + # "2026-H1"(7字符) → 去横线 "2026H1" + elif len(period) == 7: + period_variants.append(period.replace("-", "")) v = db.query(KPIValue).filter( KPIValue.kpi_id == kpi.id, - KPIValue.period == period, + KPIValue.period.in_(period_variants), KPIValue.data_status == "verified", ).order_by(KPIValue.id.desc()).first() return v.actual_value if v else None