mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 04:46:26 +00:00
本次提交包含多项优化: 1. 移除大量冗余的文件头注释与过时的from __future__导入 2. 将CRUD的list方法统一重命名为get_list保持接口一致 3. 修复前后端状态字段类型不匹配问题,将string类型status改为number 4. 修正前端文案错别字,将"代办事项"修正为标准写法 5. 更新sqlalchemy版本并调整依赖配置 6. 新增缓存工具类替代fastapi-cache2,重构缓存调用逻辑 7. 新增开源授权函生成相关工具与数据库字段支持 8. 为多个业务模块添加防重复提交loading状态 9. 修复邮件模型的外键关联缺失问题 10. 优化pdf生成工具的导入时机与文档注释
85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
from collections.abc import Sequence
|
|
|
|
from app.api.v1.module_system.dict.model import DictDataModel, DictTypeModel
|
|
from app.api.v1.module_system.dict.schema import (
|
|
DictDataCreateSchema,
|
|
DictDataUpdateSchema,
|
|
DictTypeCreateSchema,
|
|
DictTypeUpdateSchema,
|
|
)
|
|
from app.core.base_crud import CRUDBase
|
|
from app.core.base_schema import AuthSchema
|
|
|
|
|
|
class DictTypeCRUD(CRUDBase[DictTypeModel, DictTypeCreateSchema, DictTypeUpdateSchema]):
|
|
"""数据字典类型数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""
|
|
初始化数据字典类型数据层。
|
|
|
|
参数:
|
|
- auth (AuthSchema): 认证信息模型(含 DB 会话等上下文)。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
super().__init__(model=DictTypeModel, auth=auth)
|
|
|
|
|
|
class DictDataCRUD(CRUDBase[DictDataModel, DictDataCreateSchema, DictDataUpdateSchema]):
|
|
"""数据字典数据层"""
|
|
|
|
def __init__(self, auth: AuthSchema) -> None:
|
|
"""
|
|
初始化数据字典项数据层。
|
|
|
|
参数:
|
|
- auth (AuthSchema): 认证信息模型(含 DB 会话等上下文)。
|
|
|
|
返回:
|
|
- None
|
|
"""
|
|
super().__init__(model=DictDataModel, auth=auth)
|
|
|
|
async def batch_delete(self, ids: list[int], exclude_system: bool = True) -> int:
|
|
"""
|
|
批量删除数据字典数据
|
|
|
|
参数:
|
|
- ids (list[int]): 数据字典数据ID列表
|
|
- exclude_system (bool): 是否排除系统默认数据,默认为True
|
|
|
|
返回:
|
|
- int: 删除的记录数量
|
|
"""
|
|
if exclude_system:
|
|
system_data = await self.get_list(
|
|
search={
|
|
"id__in": ids,
|
|
"remark__contains": "系统默认",
|
|
}
|
|
)
|
|
system_ids = [item.id for item in system_data]
|
|
ids = [id for id in ids if id not in system_ids]
|
|
|
|
if ids:
|
|
await self.delete(ids=ids)
|
|
return len(ids)
|
|
|
|
async def get_list_by_dict_type(self, dict_type: str, status: int | None = 0) -> Sequence[DictDataModel]:
|
|
"""
|
|
根据字典类型获取字典数据列表
|
|
|
|
参数:
|
|
- dict_type (str): 字典类型
|
|
- status (str | None): 状态过滤,None表示不过滤
|
|
|
|
返回:
|
|
- Sequence[DictDataModel]: 数据字典数据模型序列
|
|
"""
|
|
search = {"dict_type": dict_type}
|
|
if status is not None:
|
|
search["status"] = status
|
|
return await self.get_list(search=search, order_by=[{"id": "asc"}])
|