feat: KPI通用化数据层改造
- 新增entities表(企业实体)+ 种子数据(酣客/博海) - kpi_definitions新增entity_id字段(DEFAULT 1,向后兼容) - 后端API list_kpis支持可选的entity_id过滤参数 - 新增 GET /api/cma/entities API返回企业列表 - 43个现有KPI自动获得entity_id=1(酣客) - 前端重新构建并部署
This commit is contained in:
+10
-2
@@ -8,7 +8,7 @@ import json
|
||||
|
||||
from app.database import get_db
|
||||
from app.auth_middleware import require_auth, require_role, filter_kpis_by_role, kpi_visible_dims
|
||||
from app.models import StrategicMap, MapObjective, KPIDefinition, KPIValue, KPIAlert, OperationLog
|
||||
from app.models import StrategicMap, MapObjective, KPIDefinition, KPIValue, KPIAlert, OperationLog, Entity
|
||||
|
||||
router = APIRouter(prefix="/api/cma/kpis", tags=["KPI字典"],
|
||||
dependencies=[Depends(require_role("ceo", "finance", "business", "it"))],
|
||||
@@ -26,6 +26,7 @@ def list_kpis(
|
||||
keyword: Optional[str] = None,
|
||||
epic: Optional[str] = None,
|
||||
category: Optional[str] = None,
|
||||
entity_id: Optional[int] = None,
|
||||
db: Session = Depends(get_db),
|
||||
current_user = Depends(require_auth),
|
||||
):
|
||||
@@ -42,9 +43,16 @@ def list_kpis(
|
||||
if category:
|
||||
cats_list = [c.strip() for c in category.split(',')] if ',' in category else [category]
|
||||
query = query.filter(KPIDefinition.category.in_(cats_list))
|
||||
if entity_id is not None:
|
||||
query = query.filter(KPIDefinition.entity_id == entity_id)
|
||||
total = query.count()
|
||||
kpis = query.order_by(KPIDefinition.kpi_code).offset((page-1)*page_size).limit(page_size).all()
|
||||
return {"total": total, "page": page, "page_size": page_size, "data": [kpi_to_dict(k) for k in kpis]}
|
||||
result = {"total": total, "page": page, "page_size": page_size, "data": [kpi_to_dict(k) for k in kpis]}
|
||||
if entity_id is not None:
|
||||
ent = db.query(Entity).filter(Entity.id == entity_id).first()
|
||||
if ent:
|
||||
result["entity"] = {"id": ent.id, "name": ent.name, "short_name": ent.short_name}
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/categories")
|
||||
|
||||
Reference in New Issue
Block a user