- 后端: kpis/bsc_layers/cash/predict/growth_quality/tax_compliance/data 的 entity_id 参数统一改为 Depends(get_entity_id) - 前端: 拦截器删除自动附加X-Entity-Id/entity_id; 登录页公司选择器(按用户名授权过滤); 切换器改POST /auth/switch-entity重新签发token+整页刷新; ReportCenter同步改造 - 修复前后端不匹配: login-entities路由→/auth/entities; login响应entity_id取user.entity_id
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""BSC四层配置 API"""
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.orm import Session
|
|
from typing import List
|
|
|
|
from app.database import get_db
|
|
from app.deps import get_entity_id
|
|
from app.auth_middleware import require_auth
|
|
from app.models import BscLayerConfig, Entity
|
|
|
|
router = APIRouter(prefix="/api/cma/bsc-layers", tags=["BSC层配置"],
|
|
dependencies=[Depends(require_auth)],
|
|
)
|
|
|
|
|
|
@router.get("")
|
|
def list_bsc_layers(entity_id: int = Depends(get_entity_id), db: Session = Depends(get_db)):
|
|
"""获取某企业的BSC四层权重配置"""
|
|
# 验证企业存在
|
|
entity = db.query(Entity).filter(Entity.id == entity_id).first()
|
|
if not entity:
|
|
from fastapi.responses import JSONResponse
|
|
return JSONResponse(status_code=404, content={"detail": "企业不存在"})
|
|
|
|
layers = db.query(BscLayerConfig).filter(
|
|
BscLayerConfig.entity_id == entity_id
|
|
).order_by(BscLayerConfig.id).all()
|
|
|
|
return {
|
|
"entity_id": entity_id,
|
|
"entity_name": entity.short_name or entity.name,
|
|
"layers": [
|
|
{
|
|
"id": l.id,
|
|
"layer": l.layer,
|
|
"weight": float(l.weight),
|
|
"kpi_count_min": l.kpi_count_min,
|
|
"kpi_count_max": l.kpi_count_max,
|
|
}
|
|
for l in layers
|
|
]
|
|
}
|