mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 13:05:18 +00:00
- 修改alembic配置以使用异步数据库URI和更新Base类引用 - 新增数据库Schema优化脚本,统一字段长度,添加索引,规范外键策略 - 重构API路由管理,按模块类型分组并统一前缀 - 删除示例、监控及系统各子模块的模型定义,减少冗余代码 - 将mcp_server相关代码迁移到module_ai模块下,规范模块目录结构 - 迁移example控制器至module_application.application模块,并重命名相关服务和参数名 - 优化示例控制器中的依赖和响应结构,统一命名规范
62 lines
1.9 KiB
Python
62 lines
1.9 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 MenuModel
|
|
from .schema import MenuCreateSchema, MenuUpdateSchema
|
|
|
|
|
|
class MenuCRUD(CRUDBase[MenuModel, MenuCreateSchema, MenuUpdateSchema]):
|
|
"""菜单模块数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""初始化菜单CRUD"""
|
|
self.auth = auth
|
|
super().__init__(model=MenuModel, auth=auth)
|
|
|
|
async def get_by_id_crud(self, id: int) -> Optional[MenuModel]:
|
|
"""
|
|
根据id获取菜单信息
|
|
|
|
:param id: 菜单ID
|
|
:return: 菜单信息
|
|
"""
|
|
obj = await self.get(id=id)
|
|
if not obj:
|
|
return None
|
|
|
|
if obj.parent_id:
|
|
parent = await self.get(id=obj.parent_id)
|
|
if parent:
|
|
obj.parent_name = parent.name
|
|
return obj
|
|
|
|
async def get_list_crud(self, search: Dict = None, order_by: List[Dict[str, str]] = None) -> Sequence[MenuModel]:
|
|
"""
|
|
获取菜单列表
|
|
|
|
:param search: 搜索条件
|
|
:param order_by: 排序字段
|
|
:return: 菜单列表
|
|
"""
|
|
obj_list = await self.list(search=search, order_by=order_by)
|
|
parent_ids = [obj.parent_id for obj in obj_list if obj.parent_id]
|
|
if parent_ids:
|
|
parents = await self.list(search={"id": ("in", parent_ids)})
|
|
parent_map = {p.id: p.name for p in parents}
|
|
for obj in obj_list:
|
|
if obj.parent_id:
|
|
obj.parent_name = parent_map.get(obj.parent_id)
|
|
return obj_list
|
|
|
|
async def set_available_crud(self, ids: List[int], status: bool) -> None:
|
|
"""
|
|
批量设置菜单可用状态
|
|
|
|
:param ids: 菜单ID列表
|
|
:param status: 可用状态
|
|
"""
|
|
await self.set(ids=ids, status=status)
|