mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-24 05:26:58 +00:00
chore: 批量优化项目代码,修复多处细节问题
本次提交包含多项优化和修复: 1. 修复CRUD初始化参数传递、搜索参数处理逻辑 2. 更新环境配置中的大模型相关参数 3. 重构部分服务方法命名,统一代码风格 4. 新增多个枚举类型,补充模型关联关系和加载选项 5. 优化查询参数类实现,完善字段校验逻辑 6. 调整Pydantic模型字段注释和类型定义 7. 简化并移除冗余的CRUD方法实现 8. 新增超级管理员权限装饰器 9. 修复邮件日志模型的租户关联和字段定义
This commit is contained in:
@@ -14,7 +14,7 @@ class WorkflowModel(ModelMixin, TenantMixin, UserMixin):
|
||||
UniqueConstraint("tenant_id", "code", name="uq_task_workflow_code"),
|
||||
{"comment": "工作流定义表"},
|
||||
)
|
||||
__loader_options__: list[str] = ["created_by", "updated_by", "deleted_by"]
|
||||
__loader_options__: list[str] = ["created_by", "updated_by", "deleted_by", "tenant_by"]
|
||||
|
||||
name: Mapped[str] = mapped_column(String(128), nullable=False, comment="流程名称")
|
||||
code: Mapped[str] = mapped_column(String(64), nullable=False, comment="流程编码")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from fastapi import Query
|
||||
@@ -6,7 +7,7 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_valida
|
||||
|
||||
from app.common.enums import QueueEnum
|
||||
from app.core.base_params import BaseQueryParam, TenantByQueryParam, UserByQueryParam
|
||||
from app.core.base_schema import TenantBySchema, UserBySchema
|
||||
from app.core.base_schema import BaseSchema, TenantBySchema, UserBySchema
|
||||
from app.core.validator import DateTimeStr
|
||||
|
||||
|
||||
@@ -55,7 +56,7 @@ class WorkflowUpdateSchema(WorkflowCreateSchema):
|
||||
return v
|
||||
|
||||
|
||||
class WorkflowOutSchema(UserBySchema, TenantBySchema):
|
||||
class WorkflowOutSchema(BaseSchema, UserBySchema, TenantBySchema):
|
||||
"""工作流输出(status 表示流程状态 draft/published/archived,与 ModelMixin.status 区分)"""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
@@ -94,6 +95,7 @@ class WorkflowOutSchema(UserBySchema, TenantBySchema):
|
||||
return data
|
||||
|
||||
|
||||
@dataclass
|
||||
class WorkflowQueryParam(BaseQueryParam, UserByQueryParam, TenantByQueryParam):
|
||||
"""工作流查询"""
|
||||
|
||||
@@ -121,11 +123,11 @@ class WorkflowExecuteSchema(BaseModel):
|
||||
class WorkflowExecuteResultSchema(BaseModel):
|
||||
"""执行结果"""
|
||||
|
||||
workflow_id: int
|
||||
workflow_name: str
|
||||
workflow_id: int = Field(..., description="工作流ID")
|
||||
workflow_name: str = Field(..., description="工作流名称")
|
||||
status: str = Field(description="completed/failed")
|
||||
start_time: str | None = None
|
||||
end_time: str | None = None
|
||||
variables: dict | None = None
|
||||
node_results: dict | None = None
|
||||
error: str | None = None
|
||||
start_time: str | None = Field(default=None, description="开始时间")
|
||||
end_time: str | None = Field(default=None, description="结束时间")
|
||||
variables: dict | None = Field(default=None, description="变量")
|
||||
node_results: dict | None = Field(default=None, description="节点结果")
|
||||
error: str | None = Field(default=None, description="错误信息")
|
||||
|
||||
@@ -20,8 +20,8 @@ from .schema import (
|
||||
class WorkflowService:
|
||||
"""工作流:画布存储 + 发布校验 + Prefect 执行"""
|
||||
|
||||
@staticmethod
|
||||
def _out(obj: Any) -> WorkflowOutSchema:
|
||||
@classmethod
|
||||
def _out(cls, obj: Any) -> WorkflowOutSchema:
|
||||
return WorkflowOutSchema.model_validate(obj)
|
||||
|
||||
@classmethod
|
||||
@@ -65,7 +65,7 @@ class WorkflowService:
|
||||
if order_by is None:
|
||||
order_by = [{"updated_time": "desc"}]
|
||||
obj_list = await WorkflowCRUD(auth).get_obj_list_crud(
|
||||
search=search.__dict__ if search else None,
|
||||
search=vars(search) if search else None,
|
||||
order_by=order_by,
|
||||
)
|
||||
return [cls._out(o) for o in obj_list]
|
||||
@@ -98,7 +98,7 @@ class WorkflowService:
|
||||
offset=offset,
|
||||
limit=page_size,
|
||||
order_by=order,
|
||||
search=search.__dict__ if search else {},
|
||||
search=vars(search) if search else None,
|
||||
out_schema=WorkflowOutSchema,
|
||||
)
|
||||
result.items = [WorkflowOutSchema.model_validate(item).model_dump(mode="json") for item in result.items]
|
||||
|
||||
@@ -14,7 +14,7 @@ class WorkflowNodeTypeModel(ModelMixin, TenantMixin, UserMixin):
|
||||
UniqueConstraint("tenant_id", "code"),
|
||||
{"comment": "工作流编排节点类型(非定时任务节点)"},
|
||||
)
|
||||
__loader_options__: list[str] = ["created_by", "updated_by", "deleted_by"]
|
||||
__loader_options__: list[str] = ["created_by", "updated_by", "deleted_by", "tenant_by"]
|
||||
|
||||
name: Mapped[str] = mapped_column(String(128), nullable=False, comment="显示名称")
|
||||
code: Mapped[str] = mapped_column(String(64), nullable=False, comment="节点编码,对应画布 node.type")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
from fastapi import Query
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||
@@ -64,6 +65,7 @@ class WorkflowNodeTypeOutSchema(WorkflowNodeTypeCreateSchema, BaseSchema, UserBy
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
@dataclass
|
||||
class WorkflowNodeTypeQueryParam(BaseQueryParam, UserByQueryParam, TenantByQueryParam):
|
||||
"""查询"""
|
||||
|
||||
@@ -77,7 +79,7 @@ class WorkflowNodeTypeQueryParam(BaseQueryParam, UserByQueryParam, TenantByQuery
|
||||
**kwargs,
|
||||
) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.name = (QueueEnum.like.value, name)
|
||||
self.code = (QueueEnum.like.value, code)
|
||||
self.category = (QueueEnum.eq.value, category)
|
||||
self.is_active = (QueueEnum.eq.value, is_active)
|
||||
self.name = (QueueEnum.like.value, name) if name else None
|
||||
self.code = (QueueEnum.like.value, code) if code else None
|
||||
self.category = (QueueEnum.eq.value, category) if category else None
|
||||
self.is_active = (QueueEnum.eq.value, is_active) if is_active is not None else None
|
||||
|
||||
@@ -82,7 +82,7 @@ class WorkflowNodeTypeService:
|
||||
if order_by is None:
|
||||
order_by = [{"sort_order": "asc"}, {"id": "asc"}]
|
||||
obj_list = await WorkflowNodeTypeCRUD(auth).get_obj_list_crud(
|
||||
search=search.__dict__ if search else None,
|
||||
search=vars(search) if search else None,
|
||||
order_by=order_by,
|
||||
)
|
||||
return [cls._out(o) for o in obj_list]
|
||||
@@ -115,7 +115,7 @@ class WorkflowNodeTypeService:
|
||||
offset=offset,
|
||||
limit=page_size,
|
||||
order_by=order,
|
||||
search=search.__dict__ if search else {},
|
||||
search=vars(search) if search else None,
|
||||
out_schema=WorkflowNodeTypeOutSchema,
|
||||
)
|
||||
result.items = [WorkflowNodeTypeOutSchema.model_validate(item).model_dump(mode="json") for item in result.items]
|
||||
|
||||
Reference in New Issue
Block a user