64dc85bd14
- inventory业务层下沉(薄路由+service orchestration模式): - customer/supplier/warehouse -> master_data_service - material_routes(价格历史/趋势/供应商关联)-> material_service - product_routes(CRUD/BOM/from-task跨模块桥接)-> product_service - dashboard_routes(首页统计/低库存预警)-> dashboard_service - inventory侧新增service回归覆盖(dashboard 2 / master_data 10 / material 10 / product 14),含跨模块桥接测试种子 - Pydantic v2弃用清零:全仓14处 class Config 全部迁移到 model_config = ConfigDict(from_attributes=True)(含 shared auth) - datetime.utcnow() 弃用清零:auth_service 3处统一改 datetime.now(timezone.utc) - 同步文档:STATUS / ROADMAP / TECH_DEBT(D12清偿)/ AGENTS 代码地图 测试基线:126 passed, 4 skipped(无deprecation warning) Co-Authored-By: Claude Code <noreply@anthropic.com>
95 lines
3.4 KiB
Python
95 lines
3.4 KiB
Python
"""
|
|
物料管理路由模块
|
|
|
|
提供物料价格历史和供应商关联管理功能,包括:
|
|
- 物料价格历史记录
|
|
- 物料供应商关联管理
|
|
- 物料价格趋势分析
|
|
|
|
路由前缀: /api/materials
|
|
"""
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from typing import List
|
|
|
|
from shared.database.database import get_db_session
|
|
from shared.services.auth_service import get_current_active_user
|
|
from shared.models.identity import User
|
|
from ..schemas import (
|
|
MaterialPriceHistoryCreate,
|
|
MaterialPriceHistoryResponse,
|
|
MaterialSupplierCreate,
|
|
MaterialSupplierResponse,
|
|
MaterialPriceTrendResponse
|
|
)
|
|
from ..services.material_service import material_service
|
|
|
|
router = APIRouter(prefix="/materials", tags=["物料管理"])
|
|
|
|
|
|
@router.post("/{product_id}/price-history", response_model=MaterialPriceHistoryResponse, status_code=201)
|
|
async def add_material_price_history(
|
|
product_id: int,
|
|
price_data: MaterialPriceHistoryCreate,
|
|
db_session: AsyncSession = Depends(get_db_session),
|
|
current_user: User = Depends(get_current_active_user)
|
|
):
|
|
return await material_service.add_price_history(db_session, product_id, price_data, current_user)
|
|
|
|
|
|
@router.get("/{product_id}/price-history", response_model=List[MaterialPriceHistoryResponse])
|
|
async def get_material_price_history(
|
|
product_id: int,
|
|
limit: int = Query(20, ge=1, le=100),
|
|
db_session: AsyncSession = Depends(get_db_session),
|
|
current_user: User = Depends(get_current_active_user)
|
|
):
|
|
return await material_service.get_price_history(db_session, product_id, limit)
|
|
|
|
|
|
@router.get("/{product_id}/price-trend", response_model=MaterialPriceTrendResponse)
|
|
async def get_material_price_trend(
|
|
product_id: int,
|
|
months: int = Query(6, ge=1, le=24),
|
|
db_session: AsyncSession = Depends(get_db_session),
|
|
current_user: User = Depends(get_current_active_user)
|
|
):
|
|
return await material_service.get_price_trend(db_session, product_id, months)
|
|
|
|
|
|
@router.post("/{product_id}/suppliers", response_model=MaterialSupplierResponse, status_code=201)
|
|
async def add_material_supplier(
|
|
product_id: int,
|
|
supplier_data: MaterialSupplierCreate,
|
|
db_session: AsyncSession = Depends(get_db_session),
|
|
current_user: User = Depends(get_current_active_user)
|
|
):
|
|
return await material_service.add_material_supplier(db_session, product_id, supplier_data, current_user)
|
|
|
|
|
|
@router.get("/{product_id}/suppliers", response_model=List[MaterialSupplierResponse])
|
|
async def get_material_suppliers(
|
|
product_id: int,
|
|
db_session: AsyncSession = Depends(get_db_session),
|
|
current_user: User = Depends(get_current_active_user)
|
|
):
|
|
return await material_service.get_material_suppliers(db_session, product_id)
|
|
|
|
|
|
@router.delete("/suppliers/{supplier_id}")
|
|
async def remove_material_supplier(
|
|
supplier_id: int,
|
|
db_session: AsyncSession = Depends(get_db_session),
|
|
current_user: User = Depends(get_current_active_user)
|
|
):
|
|
return await material_service.remove_material_supplier(db_session, supplier_id, current_user)
|
|
|
|
|
|
@router.get("/suppliers/{supplier_id}/materials", response_model=List[MaterialSupplierResponse])
|
|
async def get_supplier_materials(
|
|
supplier_id: int,
|
|
db_session: AsyncSession = Depends(get_db_session),
|
|
current_user: User = Depends(get_current_active_user)
|
|
):
|
|
return await material_service.get_supplier_materials(db_session, supplier_id)
|