| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- from __future__ import annotations
- from sqlalchemy import select
- from sqlalchemy.orm import Session
- from app.db.models.mine import Mine, MineArea, Roadway, WorkFace
- def list_mines(db: Session, *, include_inactive: bool = False) -> list[Mine]:
- statement = select(Mine).order_by(Mine.is_default.desc(), Mine.name)
- if not include_inactive:
- statement = statement.where(Mine.status == "active")
- return list(db.scalars(statement).all())
- def get_mine(db: Session, mine_id: str) -> Mine | None:
- return db.get(Mine, mine_id)
- def get_mine_by_code(db: Session, code: str) -> Mine | None:
- return db.scalar(select(Mine).where(Mine.code == code))
- def get_default_mine(db: Session) -> Mine | None:
- return db.scalar(
- select(Mine)
- .where(Mine.status == "active")
- .order_by(Mine.is_default.desc(), Mine.created_at)
- )
- def list_areas(db: Session, mine_id: str) -> list[MineArea]:
- return list(
- db.scalars(
- select(MineArea)
- .where(MineArea.mine_id == mine_id)
- .order_by(MineArea.code)
- ).all()
- )
- def list_work_faces(db: Session, mine_id: str) -> list[WorkFace]:
- return list(
- db.scalars(
- select(WorkFace)
- .where(WorkFace.mine_id == mine_id)
- .order_by(WorkFace.code)
- ).all()
- )
- def list_roadways(db: Session, mine_id: str) -> list[Roadway]:
- return list(
- db.scalars(
- select(Roadway)
- .where(Roadway.mine_id == mine_id)
- .order_by(Roadway.code)
- ).all()
- )
|