mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-23 13:13:09 +00:00
refactor: 完成项目大规模代码重构与依赖清理
这是一次综合性的重构更新,包含以下主要变更: 1. 升级Python版本到3.12,更新依赖配置 2. 替换旧的.j2模板为.jinja2格式,新增代码生成模板 3. 重构权限过滤策略,更新权限枚举与模型配置 4. 移除Prefect依赖,替换为自研拓扑并行执行引擎 5. 重构认证与上下文管理,拆分租户/请求上下文 6. 简化响应模型、CRUD与服务层代码 7. 清理废弃的支付网关模块,重构订单定时任务 8. 更新在线用户、监控等模块的接口与路由 9. 优化邮件模板与工具类,新增邮件模板文件 10. 修复数据库会话配置与类型提示
This commit is contained in:
@@ -13,22 +13,15 @@ from .schema import (
|
||||
class WorkflowNodeTypeService:
|
||||
"""工作流编排节点类型(与定时任务 task_node 无关)"""
|
||||
|
||||
@classmethod
|
||||
def _out(cls, obj) -> WorkflowNodeTypeOutSchema:
|
||||
def __init__(self, auth: AuthSchema) -> None:
|
||||
self.auth = auth
|
||||
|
||||
@staticmethod
|
||||
def _out(obj) -> WorkflowNodeTypeOutSchema:
|
||||
return WorkflowNodeTypeOutSchema.model_validate(obj)
|
||||
|
||||
@classmethod
|
||||
async def get_options_service(cls, auth: AuthSchema) -> list[dict]:
|
||||
"""
|
||||
画布左侧 palette:仅返回启用项,结构与前端 Node options 对齐。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息。
|
||||
|
||||
返回:
|
||||
- list[dict]: 选项字典列表。
|
||||
"""
|
||||
objs = await WorkflowNodeTypeCRUD(auth).list_active_options_crud()
|
||||
async def get_options(self) -> list[dict]:
|
||||
objs = await WorkflowNodeTypeCRUD(self.auth).list_active_options_crud()
|
||||
return [
|
||||
{
|
||||
"id": o.id,
|
||||
@@ -41,77 +34,35 @@ class WorkflowNodeTypeService:
|
||||
for o in objs
|
||||
]
|
||||
|
||||
@classmethod
|
||||
async def get_detail_service(cls, auth: AuthSchema, id: int) -> WorkflowNodeTypeOutSchema:
|
||||
"""
|
||||
获取编排节点类型详情。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息。
|
||||
- id (int): 主键。
|
||||
|
||||
返回:
|
||||
- dict: 序列化后的详情。
|
||||
|
||||
异常:
|
||||
- CustomException: 不存在时抛出。
|
||||
"""
|
||||
obj = await WorkflowNodeTypeCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
async def get_detail(self, id: int) -> WorkflowNodeTypeOutSchema:
|
||||
obj = await WorkflowNodeTypeCRUD(self.auth).get_obj_by_id_crud(id=id)
|
||||
if not obj:
|
||||
raise CustomException(msg="编排节点类型不存在")
|
||||
return cls._out(obj)
|
||||
return self._out(obj)
|
||||
|
||||
@classmethod
|
||||
async def get_list_service(
|
||||
cls,
|
||||
auth: AuthSchema,
|
||||
async def get_list(
|
||||
self,
|
||||
search: WorkflowNodeTypeQueryParam | None = None,
|
||||
order_by: list[dict[str, str]] | None = None,
|
||||
) -> list[WorkflowNodeTypeOutSchema]:
|
||||
"""
|
||||
获取编排节点类型列表(非分页)。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息。
|
||||
- search (WorkflowNodeTypeQueryParam | None): 查询条件。
|
||||
- order_by (list[dict[str, str]] | None): 排序。
|
||||
|
||||
返回:
|
||||
- list[dict]: 字典列表。
|
||||
"""
|
||||
if order_by is None:
|
||||
order_by = [{"sort_order": "asc"}, {"id": "asc"}]
|
||||
obj_list = await WorkflowNodeTypeCRUD(auth).get_obj_list_crud(
|
||||
obj_list = await WorkflowNodeTypeCRUD(self.auth).get_obj_list_crud(
|
||||
search=vars(search) if search else None,
|
||||
order_by=order_by,
|
||||
)
|
||||
return [cls._out(o) for o in obj_list]
|
||||
return [self._out(o) for o in obj_list]
|
||||
|
||||
@classmethod
|
||||
async def get_page_service(
|
||||
cls,
|
||||
auth: AuthSchema,
|
||||
async def get_page(
|
||||
self,
|
||||
page_no: int,
|
||||
page_size: int,
|
||||
search: WorkflowNodeTypeQueryParam | None = None,
|
||||
order_by: list[dict[str, str]] | None = None,
|
||||
) -> dict:
|
||||
"""
|
||||
分页查询编排节点类型(数据库 OFFSET/LIMIT)。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息。
|
||||
- page_no (int): 页码。
|
||||
- page_size (int): 每页条数。
|
||||
- search (WorkflowNodeTypeQueryParam | None): 查询条件。
|
||||
- order_by (list[dict[str, str]] | None): 排序。
|
||||
|
||||
返回:
|
||||
- dict: 分页结果(items 已 JSON 友好序列化)。
|
||||
"""
|
||||
offset = (page_no - 1) * page_size
|
||||
order = order_by or [{"sort_order": "asc"}, {"id": "asc"}]
|
||||
result = await WorkflowNodeTypeCRUD(auth).page(
|
||||
result = await WorkflowNodeTypeCRUD(self.auth).page(
|
||||
offset=offset,
|
||||
limit=page_size,
|
||||
order_by=order,
|
||||
@@ -121,86 +72,33 @@ class WorkflowNodeTypeService:
|
||||
result.items = [WorkflowNodeTypeOutSchema.model_validate(item).model_dump(mode="json") for item in result.items]
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
async def create_service(cls, auth: AuthSchema, data: WorkflowNodeTypeCreateSchema) -> WorkflowNodeTypeOutSchema:
|
||||
"""
|
||||
创建编排节点类型。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息。
|
||||
- data (WorkflowNodeTypeCreateSchema): 创建体。
|
||||
|
||||
返回:
|
||||
- dict: 新建记录字典。
|
||||
|
||||
异常:
|
||||
- CustomException: 编码重复或创建失败。
|
||||
"""
|
||||
exist = await WorkflowNodeTypeCRUD(auth).get(code=data.code)
|
||||
async def create(self, data: WorkflowNodeTypeCreateSchema) -> WorkflowNodeTypeOutSchema:
|
||||
exist = await WorkflowNodeTypeCRUD(self.auth).get(code=data.code)
|
||||
if exist:
|
||||
raise CustomException(msg="节点编码已存在")
|
||||
obj = await WorkflowNodeTypeCRUD(auth).create_obj_crud(data=data)
|
||||
obj = await WorkflowNodeTypeCRUD(self.auth).create_obj_crud(data=data)
|
||||
if not obj:
|
||||
raise CustomException(msg="创建失败")
|
||||
return cls._out(obj)
|
||||
return self._out(obj)
|
||||
|
||||
@classmethod
|
||||
async def update_service(cls, auth: AuthSchema, id: int, data: WorkflowNodeTypeUpdateSchema) -> WorkflowNodeTypeOutSchema:
|
||||
"""
|
||||
更新编排节点类型。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息。
|
||||
- id (int): 主键。
|
||||
- data (WorkflowNodeTypeUpdateSchema): 更新体。
|
||||
|
||||
返回:
|
||||
- dict: 更新后字典。
|
||||
|
||||
异常:
|
||||
- CustomException: 不存在、编码冲突或更新失败。
|
||||
"""
|
||||
exist = await WorkflowNodeTypeCRUD(auth).get_obj_by_id_crud(id=id)
|
||||
async def update(self, id: int, data: WorkflowNodeTypeUpdateSchema) -> WorkflowNodeTypeOutSchema:
|
||||
exist = await WorkflowNodeTypeCRUD(self.auth).get_obj_by_id_crud(id=id)
|
||||
if not exist:
|
||||
raise CustomException(msg="编排节点类型不存在")
|
||||
if exist.code != data.code:
|
||||
other = await WorkflowNodeTypeCRUD(auth).get(code=data.code)
|
||||
other = await WorkflowNodeTypeCRUD(self.auth).get(code=data.code)
|
||||
if other:
|
||||
raise CustomException(msg="节点编码已存在")
|
||||
obj = await WorkflowNodeTypeCRUD(auth).update_obj_crud(id=id, data=data)
|
||||
obj = await WorkflowNodeTypeCRUD(self.auth).update_obj_crud(id=id, data=data)
|
||||
if not obj:
|
||||
raise CustomException(msg="更新失败")
|
||||
return cls._out(obj)
|
||||
return self._out(obj)
|
||||
|
||||
@classmethod
|
||||
async def delete_service(cls, auth: AuthSchema, ids: list[int]) -> None:
|
||||
"""
|
||||
批量删除编排节点类型。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息。
|
||||
- ids (list[int]): ID 列表。
|
||||
|
||||
返回:
|
||||
- None
|
||||
|
||||
异常:
|
||||
- CustomException: ID 为空时抛出。
|
||||
"""
|
||||
async def delete(self, ids: list[int]) -> None:
|
||||
if not ids:
|
||||
raise CustomException(msg="删除ID不能为空")
|
||||
await WorkflowNodeTypeCRUD(auth).delete_obj_crud(ids=ids)
|
||||
await WorkflowNodeTypeCRUD(self.auth).delete_obj_crud(ids=ids)
|
||||
|
||||
@classmethod
|
||||
async def get_select_service(cls, auth: AuthSchema) -> list[dict]:
|
||||
"""
|
||||
获取编排节点类型选择列表。
|
||||
|
||||
参数:
|
||||
- auth (AuthSchema): 认证信息。
|
||||
|
||||
返回:
|
||||
- list[dict]: 选择列表,包含 id 和 name。
|
||||
"""
|
||||
objs = await WorkflowNodeTypeCRUD(auth).get_obj_list_crud()
|
||||
async def get_select(self) -> list[dict]:
|
||||
objs = await WorkflowNodeTypeCRUD(self.auth).get_obj_list_crud()
|
||||
return [{"id": o.id, "name": o.name} for o in objs]
|
||||
|
||||
Reference in New Issue
Block a user