mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-23 21:18:09 +00:00
refactor: 重构前端组件和样式,添加AI助手功能 docs: 更新README文档,添加ruff代码检查说明 feat: 新增AI助手相关API和前端组件 chore: 更新.gitignore文件,添加ruff缓存配置 fix: 修复前端布局和设置相关的问题 perf: 优化代码结构和性能,移除冗余代码 test: 更新测试文件,移除编码声明 build: 更新依赖版本,调整requirements.txt
78 lines
3.0 KiB
Python
78 lines
3.0 KiB
Python
from fastapi import Query
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
|
|
|
from app.core.base_schema import BaseSchema, UserBySchema
|
|
from app.core.validator import DateTimeStr
|
|
|
|
|
|
class NoticeCreateSchema(BaseModel):
|
|
"""公告通知创建模型"""
|
|
notice_title: str = Field(..., max_length=50, description='公告标题')
|
|
notice_type: str = Field(..., description='公告类型(1通知 2公告)')
|
|
notice_content: str = Field(..., description='公告内容')
|
|
status: str = Field(default="0", description="是否启用(0:启用 1:禁用)")
|
|
description: str | None = Field(default=None, max_length=255, description="描述")
|
|
|
|
@field_validator("notice_type")
|
|
@classmethod
|
|
def _validate_notice_type(cls, value: str):
|
|
if value not in {"1", "2"}:
|
|
raise ValueError("公告类型仅支持 '1'(通知) 或 '2'(公告)")
|
|
return value
|
|
|
|
@model_validator(mode='after')
|
|
def _validate_after(self):
|
|
if not self.notice_title.strip():
|
|
raise ValueError("公告标题不能为空")
|
|
if not self.notice_content.strip():
|
|
raise ValueError("公告内容不能为空")
|
|
return self
|
|
|
|
|
|
class NoticeUpdateSchema(NoticeCreateSchema):
|
|
"""公告通知更新模型"""
|
|
|
|
|
|
class NoticeOutSchema(NoticeCreateSchema, BaseSchema, UserBySchema):
|
|
"""公告通知响应模型"""
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class NoticeQueryParam:
|
|
"""公告通知查询参数"""
|
|
|
|
def __init__(
|
|
self,
|
|
notice_title: str | None = Query(None, description="公告标题"),
|
|
notice_type: str | None = Query(None, description="公告类型"),
|
|
description: str | None = Query(None, description="描述"),
|
|
status: str | None = Query(None, description="是否启用"),
|
|
created_time: list[DateTimeStr] | None = Query(None, description="创建时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
|
updated_time: list[DateTimeStr] | None = Query(None, description="更新时间范围", examples=["2025-01-01 00:00:00", "2025-12-31 23:59:59"]),
|
|
created_id: int | None = Query(None, description="创建人"),
|
|
updated_id: int | None = Query(None, description="更新人")
|
|
) -> None:
|
|
# 模糊查询字段
|
|
self.notice_title = ("like", notice_title)
|
|
# 精确查询字段
|
|
self.notice_type = notice_type
|
|
# 模糊查询字段
|
|
if description:
|
|
self.description = ("like", description)
|
|
|
|
# 精确查询字段
|
|
if status:
|
|
self.status = ("eq", status)
|
|
|
|
# 时间范围查询
|
|
if created_time and len(created_time) == 2:
|
|
self.created_time = ("between", (created_time[0], created_time[1]))
|
|
if updated_time and len(updated_time) == 2:
|
|
self.updated_time = ("between", (updated_time[0], updated_time[1]))
|
|
|
|
# 关联查询字段
|
|
if created_id:
|
|
self.created_id = ("eq", created_id)
|
|
if updated_id:
|
|
self.updated_id = ("eq", updated_id)
|