mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-27 06:41:12 +00:00
style: 统一代码风格和格式 docs: 完善函数和方法的文档字符串 refactor(base_model): 移除冗余的表名和表参数生成方法 refactor(constant): 更新返回码注释格式 refactor(router_class): 添加路由处理器的详细文档 refactor(database): 完善数据库连接函数的文档 refactor(security): 添加认证类和方法的详细文档 refactor(validator): 更新验证器函数的文档格式 refactor(serialize): 优化序列化工具类的文档 refactor(response): 完善响应类的文档字符串 refactor(dependencies): 添加依赖函数的详细文档 refactor(initialize): 完善初始化脚本的文档 refactor(plugin): 添加生命周期和中间件注册的文档 refactor(service): 完善服务层方法的文档 refactor(controller): 添加控制器方法的详细文档 refactor(crud): 完善CRUD操作的文档字符串 refactor(schema): 简化模型类并移除冗余字段 refactor(param): 更新查询参数类的注释格式 refactor(template): 优化代码生成模板的格式 refactor(console): 添加控制台输出功能的实现 refactor(util): 完善工具函数的文档字符串
85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from typing import Dict, List, Optional, Sequence
|
|
|
|
from app.core.base_crud import CRUDBase
|
|
from ..auth.schema import AuthSchema
|
|
from .model import DeptModel
|
|
from .schema import DeptCreateSchema, DeptUpdateSchema
|
|
|
|
|
|
class DeptCRUD(CRUDBase[DeptModel, DeptCreateSchema, DeptUpdateSchema]):
|
|
"""部门模块数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""初始化部门CRUD"""
|
|
self.auth = auth
|
|
super().__init__(model=DeptModel, auth=auth)
|
|
|
|
async def get_by_id_crud(self, id: int) -> Optional[DeptModel]:
|
|
"""
|
|
根据 id 获取部门信息。
|
|
|
|
参数:
|
|
- id (int): 部门 ID。
|
|
|
|
返回:
|
|
- DeptModel | None: 部门信息,未找到返回 None。
|
|
"""
|
|
obj = await self.get(id=id)
|
|
if not obj:
|
|
return None
|
|
return obj
|
|
|
|
async def get_list_crud(self, search: Optional[Dict] = None, order_by: Optional[List[Dict[str, str]]] = None) -> Sequence[DeptModel]:
|
|
"""
|
|
获取部门列表。
|
|
|
|
参数:
|
|
- search (Dict | None): 搜索条件。
|
|
- order_by (List[Dict[str, str]] | None): 排序字段列表。
|
|
|
|
返回:
|
|
- Sequence[DeptModel]: 部门列表。
|
|
"""
|
|
return await self.list(search=search, order_by=order_by)
|
|
|
|
async def get_tree_list_crud(self, search: Optional[Dict] = None, order_by: Optional[List[Dict[str, str]]] = None) -> Sequence[DeptModel]:
|
|
"""
|
|
获取部门树形列表。
|
|
|
|
参数:
|
|
- search (Dict | None): 搜索条件。
|
|
- order_by (List[Dict[str, str]] | None): 排序字段列表。
|
|
|
|
返回:
|
|
- Sequence[DeptModel]: 部门树形列表。
|
|
"""
|
|
return await self.tree_list(search=search, order_by=order_by, children_attr='children')
|
|
|
|
async def set_available_crud(self, ids: List[int], status: bool) -> None:
|
|
"""
|
|
批量设置部门可用状态。
|
|
|
|
参数:
|
|
- ids (List[int]): 部门 ID 列表。
|
|
- status (bool): 可用状态。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
await self.set(ids=ids, status=status)
|
|
|
|
async def get_name_crud(self, id: int) -> Optional[str]:
|
|
"""
|
|
根据 id 获取部门名称。
|
|
|
|
参数:
|
|
- id (int): 部门 ID。
|
|
|
|
返回:
|
|
- str | None: 部门名称,未找到返回 None。
|
|
"""
|
|
obj = await self.get(id=id)
|
|
return obj.name if obj else None
|