intent_org_service.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from typing import Sequence
  4. from app.admin.crud.crud_intent_org import intent_org_dao
  5. from model.intent_org import IntentOrg
  6. from app.admin.schema.intent_org import CreateIntentOrgParam, UpdateIntentOrgParam
  7. from common.exception import errors
  8. from database.db_mysql import async_db_session
  9. from sqlalchemy import Select
  10. class IntentOrgService:
  11. @staticmethod
  12. async def get(*, pk: int) -> IntentOrg:
  13. async with async_db_session() as db:
  14. intent_org = await intent_org_dao.get(db, pk)
  15. if not intent_org:
  16. raise errors.NotFoundError(msg='intent_org 不存在')
  17. return intent_org
  18. @staticmethod
  19. async def get_select() -> Select:
  20. return await intent_org_dao.get_list()
  21. @staticmethod
  22. async def get_all() -> Sequence[IntentOrg]:
  23. async with async_db_session() as db:
  24. intent_org = await intent_org_dao.get_all(db)
  25. return intent_org
  26. @staticmethod
  27. async def create(*, obj: CreateIntentOrgParam) -> None:
  28. async with async_db_session.begin() as db:
  29. await intent_org_dao.create(db, obj)
  30. @staticmethod
  31. async def update(*, pk: int, obj: UpdateIntentOrgParam) -> int:
  32. async with async_db_session.begin() as db:
  33. count = await intent_org_dao.update(db, pk, obj)
  34. return count
  35. @staticmethod
  36. async def delete(*, pk: list[int]) -> int:
  37. async with async_db_session.begin() as db:
  38. count = await intent_org_dao.delete(db, pk)
  39. return count
  40. intent_org_service: IntentOrgService = IntentOrgService()