1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- from typing import Sequence
- from app.admin.crud.crud_intent_org import intent_org_dao
- from model.intent_org import IntentOrg
- from app.admin.schema.intent_org import CreateIntentOrgParam, UpdateIntentOrgParam
- from common.exception import errors
- from database.db_mysql import async_db_session
- from sqlalchemy import Select
- class IntentOrgService:
- @staticmethod
- async def get(*, pk: int) -> IntentOrg:
- async with async_db_session() as db:
- intent_org = await intent_org_dao.get(db, pk)
- if not intent_org:
- raise errors.NotFoundError(msg='intent_org 不存在')
- return intent_org
- @staticmethod
- async def get_select() -> Select:
- return await intent_org_dao.get_list()
- @staticmethod
- async def get_all() -> Sequence[IntentOrg]:
- async with async_db_session() as db:
- intent_org = await intent_org_dao.get_all(db)
- return intent_org
- @staticmethod
- async def create(*, obj: CreateIntentOrgParam) -> None:
- async with async_db_session.begin() as db:
- await intent_org_dao.create(db, obj)
- @staticmethod
- async def update(*, pk: int, obj: UpdateIntentOrgParam) -> int:
- async with async_db_session.begin() as db:
- count = await intent_org_dao.update(db, pk, obj)
- return count
- @staticmethod
- async def delete(*, pk: list[int]) -> int:
- async with async_db_session.begin() as db:
- count = await intent_org_dao.delete(db, pk)
- return count
- intent_org_service: IntentOrgService = IntentOrgService()
|