crud.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from collections.abc import Sequence
  2. from app.api.v1.module_system.auth.schema import AuthSchema
  3. from app.core.base_crud import CRUDBase
  4. from .model import OperationLogModel
  5. from .schema import OperationLogCreateSchema
  6. class OperationLogCRUD(
  7. CRUDBase[OperationLogModel, OperationLogCreateSchema, OperationLogCreateSchema]
  8. ):
  9. """
  10. 操作日志数据层。
  11. """
  12. def __init__(self, auth: AuthSchema) -> None:
  13. """
  14. 初始化操作日志数据层。
  15. 参数:
  16. - auth (AuthSchema): 认证信息模型(含 DB 会话等上下文)。
  17. 返回:
  18. - None
  19. """
  20. self.auth = auth
  21. super().__init__(model=OperationLogModel, auth=auth)
  22. async def create_crud(self, data: OperationLogCreateSchema) -> OperationLogModel | None:
  23. """
  24. 创建操作日志记录。
  25. 参数:
  26. - data (OperationLogCreateSchema): 操作日志创建模型。
  27. 返回:
  28. - OperationLogModel | None: 创建后的日志记录。
  29. """
  30. return await self.create(data=data)
  31. async def get_by_id_crud(
  32. self, id: int, preload: list | None = None
  33. ) -> OperationLogModel | None:
  34. """
  35. 根据ID获取操作日志详情。
  36. 参数:
  37. - id (int): 操作日志ID。
  38. - preload (list | None): 预加载关系,未提供时使用模型默认项
  39. 返回:
  40. - OperationLogModel | None: 操作日志记录。
  41. """
  42. return await self.get(id=id, preload=preload)
  43. async def get_list_crud(
  44. self,
  45. search: dict | None = None,
  46. order_by: list | None = None,
  47. preload: list | None = None,
  48. ) -> Sequence[OperationLogModel]:
  49. """
  50. 获取操作日志列表。
  51. 参数:
  52. - search (dict | None): 搜索条件字典。
  53. - order_by (list | None): 排序字段列表。
  54. - preload (list | None): 预加载关系,未提供时使用模型默认项
  55. 返回:
  56. - Sequence[OperationLogModel]: 操作日志列表。
  57. """
  58. return await self.list(search=search, order_by=order_by, preload=preload)