style: 移除Python文件中的编码声明并优化代码格式

refactor: 重构前端组件和样式,添加AI助手功能

docs: 更新README文档,添加ruff代码检查说明

feat: 新增AI助手相关API和前端组件

chore: 更新.gitignore文件,添加ruff缓存配置

fix: 修复前端布局和设置相关的问题

perf: 优化代码结构和性能,移除冗余代码

test: 更新测试文件,移除编码声明

build: 更新依赖版本,调整requirements.txt
This commit is contained in:
zhangtao
2026-01-16 01:13:59 +08:00
parent 59c1ce1104
commit d50dd9dd1e
210 changed files with 5236 additions and 4037 deletions
@@ -1,66 +1,66 @@
# -*- coding: utf-8 -*-
import urllib.parse
from fastapi import APIRouter, Depends, Body, Path, UploadFile, Request
from typing import Annotated
from fastapi import APIRouter, Body, Depends, Path, Request, UploadFile
from fastapi.responses import JSONResponse, StreamingResponse
from sqlalchemy.ext.asyncio import AsyncSession
from app.common.response import StreamResponse, SuccessResponse
from app.api.v1.module_system.auth.schema import AuthSchema
from app.common.request import PaginationService
from app.core.router_class import OperationLogRoute
from app.utils.common_util import bytes2file_response
from app.core.dependencies import db_getter, get_current_user, AuthPermission
from app.common.response import StreamResponse, SuccessResponse
from app.core.base_params import PaginationQueryParam
from app.core.base_schema import BatchSetAvailable
from app.core.dependencies import AuthPermission, db_getter, get_current_user
from app.core.logger import log
from app.core.router_class import OperationLogRoute
from app.utils.common_util import bytes2file_response
from ..auth.schema import AuthSchema
from .service import UserService
from .schema import (
CurrentUserUpdateSchema,
ResetPasswordSchema,
UserChangePasswordSchema,
UserCreateSchema,
UserForgetPasswordSchema,
UserQueryParam,
UserRegisterSchema,
UserUpdateSchema,
UserChangePasswordSchema,
UserQueryParam
)
from .service import UserService
UserRouter = APIRouter(route_class=OperationLogRoute, prefix="/user", tags=["用户管理"])
@UserRouter.get("/current/info", summary="查询当前用户信息", description="查询当前用户信息")
async def get_current_user_info_controller(
auth: AuthSchema = Depends(get_current_user)
auth: Annotated[AuthSchema, Depends(get_current_user)]
) -> JSONResponse:
"""
查询当前用户信息
参数:
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 当前用户信息JSON响应
"""
result_dict = await UserService.get_current_user_info_service(auth=auth)
log.info(f"获取当前用户信息成功")
log.info("获取当前用户信息成功")
return SuccessResponse(data=result_dict, msg='获取当前用户信息成功')
@UserRouter.post("/current/avatar/upload", summary="上传当前用户头像", dependencies=[Depends(get_current_user)])
async def user_avatar_upload_controller(
file: UploadFile,
file: UploadFile,
request: Request
) -> JSONResponse:
"""
上传当前用户头像
参数:
- file (UploadFile): 上传的文件
- request (Request): 请求对象
返回:
- JSONResponse: 上传头像JSON响应
"""
@@ -72,15 +72,15 @@ async def user_avatar_upload_controller(
@UserRouter.put("/current/info/update", summary="更新当前用户基本信息", description="更新当前用户基本信息")
async def update_current_user_info_controller(
data: CurrentUserUpdateSchema,
auth: AuthSchema = Depends(get_current_user)
auth: Annotated[AuthSchema, Depends(get_current_user)]
) -> JSONResponse:
"""
更新当前用户基本信息
参数:
- data (CurrentUserUpdateSchema): 当前用户更新模型
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 更新当前用户基本信息JSON响应
"""
@@ -92,15 +92,15 @@ async def update_current_user_info_controller(
@UserRouter.put("/current/password/change", summary="修改当前用户密码", description="修改当前用户密码")
async def change_current_user_password_controller(
data: UserChangePasswordSchema,
auth: AuthSchema = Depends(get_current_user)
auth: Annotated[AuthSchema, Depends(get_current_user)]
) -> JSONResponse:
"""
修改当前用户密码
参数:
- data (UserChangePasswordSchema): 用户密码修改模型
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 修改密码JSON响应
"""
@@ -108,18 +108,19 @@ async def change_current_user_password_controller(
log.info(f"修改密码成功: {result_dict}")
return SuccessResponse(data=result_dict, msg='修改密码成功, 请重新登录')
@UserRouter.put("/reset/password", summary="重置密码", description="重置密码")
async def reset_password_controller(
data: ResetPasswordSchema,
auth: AuthSchema = Depends(get_current_user)
auth: Annotated[AuthSchema, Depends(get_current_user)]
) -> JSONResponse:
"""
重置密码
参数:
- data (ResetPasswordSchema): 重置密码模型
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 重置密码JSON响应
"""
@@ -127,18 +128,19 @@ async def reset_password_controller(
log.info(f"重置密码成功: {result_dict}")
return SuccessResponse(data=result_dict, msg='重置密码成功')
@UserRouter.post('/register', summary="注册用户", description="注册用户")
async def register_user_controller(
data: UserRegisterSchema,
db: AsyncSession = Depends(db_getter),
data: UserRegisterSchema,
db: Annotated[AsyncSession, Depends(db_getter)],
) -> JSONResponse:
"""
注册用户
参数:
- data (UserRegisterSchema): 用户注册模型
- db (AsyncSession): 异步数据库会话
返回:
- JSONResponse: 注册用户JSON响应
"""
@@ -150,16 +152,16 @@ async def register_user_controller(
@UserRouter.post('/forget/password', summary="忘记密码", description="忘记密码")
async def forget_password_controller(
data: UserForgetPasswordSchema,
db: AsyncSession = Depends(db_getter),
data: UserForgetPasswordSchema,
db: Annotated[AsyncSession, Depends(db_getter)],
) -> JSONResponse:
"""
忘记密码
参数:
- data (UserForgetPasswordSchema): 用户忘记密码模型
- db (AsyncSession): 异步数据库会话
返回:
- JSONResponse: 忘记密码JSON响应
"""
@@ -171,39 +173,39 @@ async def forget_password_controller(
@UserRouter.get("/list", summary="查询用户", description="查询用户")
async def get_obj_list_controller(
page: PaginationQueryParam = Depends(),
search: UserQueryParam = Depends(),
auth: AuthSchema = Depends(AuthPermission(["module_system:user:query"])),
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[UserQueryParam, Depends()],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:user:query"]))],
) -> JSONResponse:
"""
查询用户
参数:
- page (PaginationQueryParam): 分页查询参数模型
- search (UserQueryParam): 查询参数模型
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 分页查询结果JSON响应
"""
result_dict_list = await UserService.get_user_list_service(search=search, auth=auth, order_by=page.order_by)
result_dict = await PaginationService.paginate(data_list= result_dict_list, page_no= page.page_no, page_size = page.page_size)
log.info(f"查询用户成功")
result_dict = await PaginationService.paginate(data_list=result_dict_list, page_no=page.page_no, page_size=page.page_size)
log.info("查询用户成功")
return SuccessResponse(data=result_dict, msg="查询用户成功")
@UserRouter.get("/detail/{id}", summary="查询用户详情", description="查询用户详情")
async def get_obj_detail_controller(
id: int = Path(..., description="用户ID"),
auth: AuthSchema = Depends(AuthPermission(["module_system:user:detail"])),
id: Annotated[int, Path(description="用户ID")],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:user:detail"]))],
) -> JSONResponse:
"""
查询用户详情
参数:
- id (int): 用户ID
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 用户详情JSON响应
"""
@@ -215,19 +217,19 @@ async def get_obj_detail_controller(
@UserRouter.post("/create", summary="创建用户", description="创建用户")
async def create_obj_controller(
data: UserCreateSchema,
auth: AuthSchema = Depends(AuthPermission(["module_system:user:create"])),
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:user:create"]))],
) -> JSONResponse:
"""
创建用户
**注意**:
- 创建用户时, 默认密码为: <PASSWORD>
- 创建用户时, 默认用户状态为: 启用
参数:
- data (UserCreateSchema): 用户创建模型
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 创建用户JSON响应
"""
@@ -239,17 +241,17 @@ async def create_obj_controller(
@UserRouter.put("/update/{id}", summary="修改用户", description="修改用户")
async def update_obj_controller(
data: UserUpdateSchema,
id: int = Path(..., description="用户ID"),
auth: AuthSchema = Depends(AuthPermission(["module_system:user:update"])),
id: Annotated[int, Path(description="用户ID")],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:user:update"]))],
) -> JSONResponse:
"""
修改用户
参数:
- data (UserUpdateSchema): 用户修改模型
- id (int): 用户ID
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 修改用户JSON响应
"""
@@ -260,16 +262,16 @@ async def update_obj_controller(
@UserRouter.delete("/delete", summary="删除用户", description="删除用户")
async def delete_obj_controller(
ids: list[int] = Body(..., description="ID列表"),
auth: AuthSchema = Depends(AuthPermission(["module_system:user:delete"])),
ids: Annotated[list[int], Body(description="ID列表")],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:user:delete"]))],
) -> JSONResponse:
"""
删除用户
参数:
- ids (list[int]): 用户ID列表
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 删除用户JSON响应
"""
@@ -281,15 +283,15 @@ async def delete_obj_controller(
@UserRouter.patch("/available/setting", summary="批量修改用户状态", description="批量修改用户状态")
async def batch_set_available_obj_controller(
data: BatchSetAvailable,
auth: AuthSchema = Depends(AuthPermission(["module_system:user:patch"])),
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:user:patch"]))],
) -> JSONResponse:
"""
批量修改用户状态
参数:
- data (BatchSetAvailable): 批量修改用户状态模型
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 批量修改用户状态JSON响应
"""
@@ -299,10 +301,10 @@ async def batch_set_available_obj_controller(
@UserRouter.post('/import/template', summary="获取用户导入模板", description="获取用户导入模板", dependencies=[Depends(AuthPermission(["module_system:user:download"]))])
async def export_obj_template_controller()-> StreamingResponse:
async def export_obj_template_controller() -> StreamingResponse:
"""
获取用户导入模板
返回:
- StreamingResponse: 用户导入模板流响应
"""
@@ -312,7 +314,7 @@ async def export_obj_template_controller()-> StreamingResponse:
return StreamResponse(
data=bytes2file_response(user_import_template_result),
media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
headers = {
headers={
'Content-Disposition': f'attachment; filename={urllib.parse.quote("用户导入模板.xlsx")}',
'Access-Control-Expose-Headers': 'Content-Disposition'
}
@@ -321,18 +323,18 @@ async def export_obj_template_controller()-> StreamingResponse:
@UserRouter.post('/export', summary="导出用户", description="导出用户")
async def export_obj_list_controller(
page: PaginationQueryParam = Depends(),
search: UserQueryParam = Depends(),
auth: AuthSchema = Depends(AuthPermission(["module_system:user:export"])),
page: Annotated[PaginationQueryParam, Depends()],
search: Annotated[UserQueryParam, Depends()],
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:user:export"]))],
) -> StreamingResponse:
"""
导出用户
参数:
- page (PaginationQueryParam): 分页查询参数模型
- search (UserQueryParam): 查询参数模型
- auth (AuthSchema): 认证信息模型
返回:
- StreamingResponse: 用户导出模板流响应
"""
@@ -343,7 +345,7 @@ async def export_obj_list_controller(
return StreamResponse(
data=bytes2file_response(user_export_result),
media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
headers = {
headers={
'Content-Disposition': 'attachment; filename=user.xlsx'
}
)
@@ -352,15 +354,15 @@ async def export_obj_list_controller(
@UserRouter.post('/import/data', summary="导入用户", description="导入用户")
async def import_obj_list_controller(
file: UploadFile,
auth: AuthSchema = Depends(AuthPermission(["module_system:user:import"]))
auth: Annotated[AuthSchema, Depends(AuthPermission(["module_system:user:import"]))]
) -> JSONResponse:
"""
导入用户
参数:
- file (UploadFile): 用户导入文件
- auth (AuthSchema): 认证信息模型
返回:
- JSONResponse: 导入用户JSON响应
"""