init: 管理会计OS初始代码

包含前后端完整代码:
- 前端:Vue3+Vite+ElementPlus
- 后端:FastAPI+SQLAlchemy
- 模块:驾驶舱/KPI/战略地图/预警/预算/成本/预测/改善行动
- 当前版本:v1.0.0
This commit is contained in:
Hermes CI Fix
2026-05-28 17:32:22 +08:00
commit 3dddd36866
142 changed files with 18533 additions and 0 deletions
+83
View File
@@ -0,0 +1,83 @@
"""战略地图目标 API"""
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.auth_middleware import require_role
from app.models import MapObjective, StrategicMap, KPIDefinition
router = APIRouter(prefix="/api/cma/maps", tags=["战略地图目标"],
dependencies=[Depends(require_role("ceo", "finance"))],
)
@router.get("/{map_id}/objectives")
def list_objectives(map_id: int, db: Session = Depends(get_db)):
"""获取某地图下的所有目标"""
objs = db.query(MapObjective).filter(
MapObjective.map_id == map_id
).order_by(MapObjective.sort_order).all()
return {"data": [_obj_to_dict(o) for o in objs]}
@router.post("/{map_id}/objectives")
def create_objective(map_id: int, data: dict, db: Session = Depends(get_db)):
"""新增目标"""
m = db.query(StrategicMap).filter(StrategicMap.id == map_id).first()
if not m:
raise HTTPException(404, "战略地图不存在")
obj = MapObjective(
map_id=map_id,
dimension_key=data["dimension_key"],
name=data["name"],
description=data.get("description"),
icon=data.get("icon", "target"),
sort_order=data.get("sort_order", 0),
)
db.add(obj)
db.commit()
db.refresh(obj)
return _obj_to_dict(obj)
@router.put("/{map_id}/objectives/{obj_id}")
def update_objective(map_id: int, obj_id: int, data: dict, db: Session = Depends(get_db)):
"""修改目标"""
obj = db.query(MapObjective).filter(
MapObjective.id == obj_id, MapObjective.map_id == map_id
).first()
if not obj:
raise HTTPException(404, "目标不存在")
for k, v in data.items():
if hasattr(obj, k) and v is not None:
setattr(obj, k, v)
db.commit()
return _obj_to_dict(obj)
@router.delete("/{map_id}/objectives/{obj_id}")
def delete_objective(map_id: int, obj_id: int, db: Session = Depends(get_db)):
"""删除目标"""
obj = db.query(MapObjective).filter(
MapObjective.id == obj_id, MapObjective.map_id == map_id
).first()
if not obj:
raise HTTPException(404, "目标不存在")
db.delete(obj)
db.commit()
return {"message": "已删除"}
@router.put("/{map_id}/objectives/sort")
def sort_objectives(map_id: int, data: dict, db: Session = Depends(get_db)):
"""批量排序: {"ids": [3, 1, 2]}"""
ids = data.get("ids", [])
for idx, obj_id in enumerate(ids):
db.query(MapObjective).filter(
MapObjective.id == obj_id, MapObjective.map_id == map_id
).update({"sort_order": idx})
db.commit()
return {"message": "排序已更新"}
def _obj_to_dict(o):
return {c.name: getattr(o, c.name) for c in o.__table__.columns}