feat: CMA P1+P2 Round1 — 成本法对比+杜邦分析+本量利

This commit is contained in:
Hermes CI Fix
2026-07-16 16:39:24 +08:00
parent 46fa811d52
commit 4b25f46124
8728 changed files with 1772671 additions and 151 deletions
+73
View File
@@ -420,3 +420,76 @@ def _build_scorecard_from_kpis(db: Session, period: str) -> dict:
"overall_score": round(total_score / dim_count, 1) if dim_count > 0 else 0,
"dimensions": dimensions,
}
# ============================================================
# 杜邦分析 (CMA P2)
# ============================================================
@router.get("/dupont")
def get_dupont_analysis(
entity: str = Query("bohai"),
db: Session = Depends(get_db),
):
"""杜邦分析 — ROE三级拆解 (CMA P2)"""
if entity == "bohai":
net_profit = 14.1 # 万
revenue = 383 # 万
total_assets = 533 # 万
equity = 114 # 万
net_profit_margin = round(net_profit / revenue * 100, 2)
asset_turnover = round(revenue / total_assets, 4)
financial_leverage = round(total_assets / equity, 2)
roe = round(net_profit_margin / 100 * asset_turnover * financial_leverage * 100, 2)
# 上期对比(模拟上一期数据)
prev_roe = round(11.2, 2)
roe_change = round(roe - prev_roe, 2)
return {
"entity": "bohai",
"entity_name": "陕西博海科技(IT服务)",
"period": "2026年H1",
"roe": roe,
"roe_change": roe_change,
"roe_trend": "up" if roe_change > 0 else "down",
"prev_roe": prev_roe,
"factors": {
"net_profit_margin": {
"value": net_profit_margin,
"label": "净利润率",
"desc": "净利润/收入",
"status": "🟡" if net_profit_margin < 5 else "",
"assessment": "IT经销行业正常偏低",
"raw": {"net_profit": net_profit, "revenue": revenue},
},
"asset_turnover": {
"value": asset_turnover,
"label": "资产周转率",
"desc": "收入/总资产",
"status": "🟡" if asset_turnover < 1 else "",
"assessment": "资金效率中等",
"raw": {"revenue": revenue, "total_assets": total_assets},
},
"financial_leverage": {
"value": financial_leverage,
"label": "财务杠杆",
"desc": "总资产/净资产",
"status": "🟡" if financial_leverage > 3 else "",
"assessment": "负债率78.6%,偏高但可控",
"raw": {"total_assets": total_assets, "equity": equity},
},
},
"raw_data": {
"net_profit": net_profit,
"revenue": revenue,
"total_assets": total_assets,
"equity": equity,
},
"insight": {
"improvement": "提高周转率或利润率,而非加杠杆",
"detail": f"净利润率{net_profit_margin}%偏低,资产周转率{asset_turnover}x中等,财务杠杆{financial_leverage}x偏高。改善方向:提升毛利率或加快库存周转。",
},
}
return {"error": "不支持的实体"}