""" 利润核算路由 —— /api/profit """ from __future__ import annotations import uuid from fastapi import APIRouter, Depends, Query from sqlalchemy.ext.asyncio import AsyncSession from app.api.deps import get_current_user, get_current_company_id from app.db.database import get_db from app.schemas.auth import CurrentUserPayload from app.schemas.response import ok from app.services import profit_service as svc router = APIRouter(prefix="/profit", tags=["利润核算"]) @router.get("/report", summary="利润报表(订单维度)") async def profit_report( start_date: str | None = Query(None, description="起始日期 YYYY-MM-DD"), end_date: str | None = Query(None, description="结束日期 YYYY-MM-DD"), db: AsyncSession = Depends(get_db), current_user: CurrentUserPayload = Depends(get_current_user), company_id: uuid.UUID = Depends(get_current_company_id), ) -> dict: result = await svc.get_profit_report(db, company_id, start_date, end_date) return ok(data=result) @router.post("/snapshot/{order_id}", summary="为订单锚定成本快照") async def snapshot_costs( order_id: uuid.UUID, db: AsyncSession = Depends(get_db), current_user: CurrentUserPayload = Depends(get_current_user), company_id: uuid.UUID = Depends(get_current_company_id), ) -> dict: result = await svc.snapshot_order_item_costs(db, order_id, company_id) return ok(data=result, message=f"已为 {len(result)} 项明细锚定成本")