29 lines
636 B
Python
29 lines
636 B
Python
from fastapi import APIRouter
|
||
from pydantic import BaseModel
|
||
|
||
INDEX = "总资产报酬率(%)"
|
||
|
||
router = APIRouter()
|
||
|
||
|
||
class Params(BaseModel):
|
||
净利润: float
|
||
所得税: float
|
||
利息费用: float
|
||
期末资产总计: float
|
||
期初资产总计: float
|
||
|
||
|
||
# 计算接口
|
||
@router.post("/{}".format(INDEX))
|
||
def func(p: Params):
|
||
try:
|
||
d = (p.期末资产总计 + p.期初资产总计) / 2
|
||
result = (p.净利润 + p.所得税 + p.利息费用) / d * 100
|
||
return round(result, 2)
|
||
|
||
except ZeroDivisionError:
|
||
return "算式无意义"
|
||
except Exception:
|
||
return "计算错误"
|