chore: 批量整理代码格式与优化细节

- 修复多处代码缩进、换行不规范问题
- 调整部分配置注释与字符串格式对齐
- 优化导入语句与多行表达式的排版
- 统一枚举、模型字段的注释风格
- 调整部分校验逻辑与提示文案
- 重构部分长函数参数与查询语句格式
This commit is contained in:
zhangtao
2026-06-02 08:19:10 +08:00
parent c0733d9861
commit 290728d9d2
98 changed files with 4884 additions and 1764 deletions
@@ -16,17 +16,24 @@ from app.utils.xss_util import sanitize_html
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:禁用)")
notice_title: str = Field(..., min_length=1, max_length=64, description="公告标题")
notice_type: str = Field(..., max_length=1, description="公告类型(1:通知 2:公告)")
notice_content: str = Field(..., max_length=65535, description="公告内容")
status: str = Field(default="0", max_length=1, 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'(公告)")
raise ValueError("公告类型仅支持 1(通知) 或 2(公告)")
return value
@field_validator("status")
@classmethod
def _validate_status(cls, value: str):
if value not in {"0", "1"}:
raise ValueError("状态仅支持 0(正常) 或 1(禁用)")
return value
@field_validator("notice_content")
@@ -256,7 +256,7 @@ class NoticeService:
@classmethod
async def get_latest_notices_service(cls, auth: AuthSchema, limit: int = 5) -> list[dict]:
"""获取最新 N 条已启用公告"""
from sqlalchemy import select, desc
from sqlalchemy import desc, select
from .model import NoticeModel
from .schema import NoticeOutSchema
@@ -274,7 +274,7 @@ class NoticeService:
@classmethod
async def get_panel_data_service(cls, auth: AuthSchema) -> dict:
"""聚合通知面板数据:通知 + 消息 + 待办"""
from sqlalchemy import select, desc
from sqlalchemy import desc, select
# 1. 通知:最新 5 条已启用公告
notices = await cls.get_latest_notices_service(auth, limit=5)
@@ -284,11 +284,7 @@ class NoticeService:
try:
from app.api.v1.module_system.log.model import OperationLogModel
stmt = (
select(OperationLogModel)
.order_by(desc(OperationLogModel.created_time))
.limit(5)
)
stmt = select(OperationLogModel).order_by(desc(OperationLogModel.created_time)).limit(5)
result = await auth.db.execute(stmt)
logs = result.scalars().all()
for log_entry in logs:
@@ -296,7 +292,9 @@ class NoticeService:
"id": log_entry.id,
"title": log_entry.oper_param or "系统操作",
"content": f"{log_entry.oper_user_name or '系统'} 执行了 {log_entry.title or '操作'}",
"time": log_entry.created_time.strftime("%Y-%m-%d %H:%M") if log_entry.created_time else "",
"time": log_entry.created_time.strftime("%Y-%m-%d %H:%M")
if log_entry.created_time
else "",
"type": "system",
})
except Exception: