-
-
Notifications
You must be signed in to change notification settings - Fork 376
Expand file tree
/
Copy pathbusiness_service.py
More file actions
73 lines (59 loc) · 2.16 KB
/
Copy pathbusiness_service.py
File metadata and controls
73 lines (59 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from typing import Sequence
from backend.common.exception import errors
from backend.database.db import async_db_session
from backend.plugin.code_generator.crud.crud_business import gen_business_dao
from backend.plugin.code_generator.model import GenBusiness
from backend.plugin.code_generator.schema.business import CreateGenBusinessParam, UpdateGenBusinessParam
class GenBusinessService:
"""代码生成业务服务类"""
@staticmethod
async def get(*, pk: int) -> GenBusiness:
"""
获取指定 ID 的业务
:param pk: 业务 ID
:return:
"""
async with async_db_session() as db:
business = await gen_business_dao.get(db, pk)
if not business:
raise errors.NotFoundError(msg='代码生成业务不存在')
return business
@staticmethod
async def get_all() -> Sequence[GenBusiness]:
"""获取所有业务"""
async with async_db_session() as db:
return await gen_business_dao.get_all(db)
@staticmethod
async def create(*, obj: CreateGenBusinessParam) -> None:
"""
创建业务
:param obj: 创建业务参数
:return:
"""
async with async_db_session.begin() as db:
business = await gen_business_dao.get_by_name(db, obj.table_name)
if business:
raise errors.ConflictError(msg='代码生成业务已存在')
await gen_business_dao.create(db, obj)
@staticmethod
async def update(*, pk: int, obj: UpdateGenBusinessParam) -> int:
"""
更新业务
:param pk: 业务 ID
:param obj: 更新业务参数
:return:
"""
async with async_db_session.begin() as db:
return await gen_business_dao.update(db, pk, obj)
@staticmethod
async def delete(*, pk: int) -> int:
"""
删除业务
:param pk: 业务 ID
:return:
"""
async with async_db_session.begin() as db:
return await gen_business_dao.delete(db, pk)
gen_business_service: GenBusinessService = GenBusinessService()