57 lines
1.9 KiB
Python
57 lines
1.9 KiB
Python
"""断面数据接口"""
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from app.core.database import get_tunnel_db
|
|
from app.core.logging_config import get_logger
|
|
from app.schemas.section_data import SectionDataBatchImport, SectionDataQuery
|
|
from app.schemas.common import BatchImportResponse
|
|
from app.servives.section_data_service import SectionDataService
|
|
|
|
router = APIRouter(prefix="/section_data", tags=["断面数据"])
|
|
logger = get_logger(__name__)
|
|
|
|
@router.post("/import", response_model=BatchImportResponse)
|
|
async def batch_import(
|
|
request: SectionDataBatchImport,
|
|
db: Session = Depends(get_tunnel_db)
|
|
):
|
|
"""批量导入断面数据"""
|
|
logger.info(f"断面数据导入请求: account_id={request.account_id}, 数据量={len(request.data)}")
|
|
return SectionDataService.batch_import(db, request.account_id, request.data)
|
|
|
|
@router.post("/query")
|
|
async def query(
|
|
request: SectionDataQuery,
|
|
db: Session = Depends(get_tunnel_db)
|
|
):
|
|
"""查询断面数据"""
|
|
logger.info(f"断面数据查询请求: {request}")
|
|
items, total = SectionDataService.query(db, request)
|
|
return {
|
|
"total": total,
|
|
"page": request.page,
|
|
"page_size": request.page_size,
|
|
"items": items
|
|
}
|
|
|
|
@router.post("/query_by_department")
|
|
async def query_by_department(
|
|
request: SectionDataQuery,
|
|
db: Session = Depends(get_tunnel_db)
|
|
):
|
|
"""根据department_id查询断面数据"""
|
|
logger.info(f"根据department_id查询断面数据: {request}")
|
|
params = SectionDataQuery(
|
|
account_id=request.account_id,
|
|
department_id=request.department_id,
|
|
page=request.page,
|
|
page_size=request.page_size
|
|
)
|
|
items, total = SectionDataService.query(db, params)
|
|
return {
|
|
"total": total,
|
|
"page": request.page,
|
|
"page_size": request.page_size,
|
|
"items": items
|
|
}
|