fix: 杜邦分析period格式兼容 — 2026H1/2026-H1变体匹配,酣客ROE正常返回-12.74%
- _get_dupont_kpi支持6字符(2026H1)和7字符(2026-H1)period格式 - 之前数据库存'2026-H1'但API查'2026H1'导致读不到数据,酣客ROE返回None - 验证:酣客ROE=-12.74%(净利率-12.74%,亏损企业正确为负)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user