crud.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from typing import Any
  2. from app.api.v1.module_system.auth.schema import AuthSchema
  3. from app.core.base_crud import CRUDBase
  4. from .model import IssueBatchModel, QuotaChangeLogModel, QuotaModel
  5. from .schema import QuotaCreateSchema, QuotaUpdateSchema
  6. class QuotaCRUD(CRUDBase[QuotaModel, QuotaCreateSchema, QuotaUpdateSchema]):
  7. """额度 CRUD 操作"""
  8. def __init__(self, auth: AuthSchema) -> None:
  9. self.auth = auth
  10. super().__init__(model=QuotaModel, auth=auth)
  11. async def get_by_out_biz_no(
  12. self, out_biz_no: str
  13. ) -> QuotaModel | None:
  14. return await self.get(out_biz_no=out_biz_no)
  15. async def get_by_employee_id(
  16. self, employee_id: str
  17. ) -> QuotaModel | None:
  18. return await self.get(employee_id=employee_id)
  19. class IssueBatchCRUD(CRUDBase[IssueBatchModel, dict[str, Any], dict[str, Any]]):
  20. """手工发放批次 CRUD 操作"""
  21. def __init__(self, auth: AuthSchema) -> None:
  22. self.auth = auth
  23. super().__init__(model=IssueBatchModel, auth=auth)
  24. async def get_by_batch_no(
  25. self, batch_no: str
  26. ) -> IssueBatchModel | None:
  27. return await self.get(batch_no=batch_no)
  28. async def get_by_issue_batch_id(
  29. self, issue_batch_id: str
  30. ) -> IssueBatchModel | None:
  31. return await self.get(issue_batch_id=issue_batch_id)
  32. class QuotaChangeLogCRUD(CRUDBase[QuotaChangeLogModel, dict[str, Any], dict[str, Any]]):
  33. """额度变更记录 CRUD"""
  34. def __init__(self, auth: AuthSchema) -> None:
  35. self.auth = auth
  36. super().__init__(model=QuotaChangeLogModel, auth=auth)