mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-23 13:13:09 +00:00
refactor: 重构前端组件和样式,添加AI助手功能 docs: 更新README文档,添加ruff代码检查说明 feat: 新增AI助手相关API和前端组件 chore: 更新.gitignore文件,添加ruff缓存配置 fix: 修复前端布局和设置相关的问题 perf: 优化代码结构和性能,移除冗余代码 test: 更新测试文件,移除编码声明 build: 更新依赖版本,调整requirements.txt
87 lines
2.8 KiB
Python
87 lines
2.8 KiB
Python
from collections.abc import Sequence
|
|
|
|
from app.api.v1.module_system.auth.schema import AuthSchema
|
|
from app.core.base_crud import CRUDBase
|
|
|
|
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, preload: list | None = None) -> DeptModel | None:
|
|
"""
|
|
根据 id 获取部门信息。
|
|
|
|
参数:
|
|
- id (int): 部门 ID。
|
|
- preload (list | None): 预加载关系,未提供时使用模型默认项
|
|
|
|
返回:
|
|
- DeptModel | None: 部门信息,未找到返回 None。
|
|
"""
|
|
obj = await self.get(id=id, preload=preload)
|
|
if not obj:
|
|
return None
|
|
return obj
|
|
|
|
async def get_list_crud(self, search: dict | None = None, order_by: list[dict] | None = None, preload: list | None = None) -> Sequence[DeptModel]:
|
|
"""
|
|
获取部门列表。
|
|
|
|
参数:
|
|
- search (dict | None): 搜索条件。
|
|
- order_by (list[dict] | None): 排序字段列表。
|
|
- preload (list | None): 预加载关系,未提供时使用模型默认项
|
|
|
|
返回:
|
|
- Sequence[DeptModel]: 部门列表。
|
|
"""
|
|
return await self.list(search=search, order_by=order_by, preload=preload)
|
|
|
|
async def get_tree_list_crud(self, search: dict | None = None, order_by: list[dict] | None = None, preload: list | None = None) -> Sequence[DeptModel]:
|
|
"""
|
|
获取部门树形列表。
|
|
|
|
参数:
|
|
- search (dict | None): 搜索条件。
|
|
- order_by (list[dict] | None): 排序字段列表。
|
|
- preload (list | None): 预加载关系,未提供时使用模型默认项
|
|
|
|
返回:
|
|
- Sequence[DeptModel]: 部门树形列表。
|
|
"""
|
|
return await self.tree_list(search=search, order_by=order_by, children_attr='children', preload=preload)
|
|
|
|
async def set_available_crud(self, ids: list[int], status: str) -> None:
|
|
"""
|
|
批量设置部门可用状态。
|
|
|
|
参数:
|
|
- ids (list[int]): 部门 ID 列表。
|
|
- status (str): 可用状态。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
await self.set(ids=ids, status=status)
|
|
|
|
async def get_name_crud(self, id: int) -> str | None:
|
|
"""
|
|
根据 id 获取部门名称。
|
|
|
|
参数:
|
|
- id (int): 部门 ID。
|
|
|
|
返回:
|
|
- str | None: 部门名称,未找到返回 None。
|
|
"""
|
|
obj = await self.get(id=id)
|
|
return obj.name if obj else None
|