feat: add system quality improvement plan and implementation
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"""
|
||||
审计日志API封装
|
||||
"""
|
||||
|
||||
from typing import Dict, Any
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
class SysLogAPI:
|
||||
"""审计日志API"""
|
||||
|
||||
def __init__(self, client: AsyncClient):
|
||||
self.client = client
|
||||
self.base_path = "/api/logs"
|
||||
|
||||
async def get_login_logs(self) -> Any:
|
||||
"""获取所有登录日志"""
|
||||
return await self.client.get(f"{self.base_path}/login")
|
||||
|
||||
async def get_login_log_by_id(self, log_id: int) -> Any:
|
||||
"""根据ID获取登录日志"""
|
||||
return await self.client.get(f"{self.base_path}/login/{log_id}")
|
||||
|
||||
async def create_login_log(self, data: Dict[str, Any]) -> Any:
|
||||
"""创建登录日志"""
|
||||
return await self.client.post(f"{self.base_path}/login", json=data)
|
||||
|
||||
async def get_exception_logs(self) -> Any:
|
||||
"""获取所有异常日志"""
|
||||
return await self.client.get(f"{self.base_path}/exception")
|
||||
|
||||
async def get_exception_log_by_id(self, log_id: int) -> Any:
|
||||
"""根据ID获取异常日志"""
|
||||
return await self.client.get(f"{self.base_path}/exception/{log_id}")
|
||||
|
||||
async def create_exception_log(self, data: Dict[str, Any]) -> Any:
|
||||
"""创建异常日志"""
|
||||
return await self.client.post(f"{self.base_path}/exception", json=data)
|
||||
|
||||
async def get_login_logs_by_page(self, page: int = 0, size: int = 10,
|
||||
sort: str = "id", order: str = "asc",
|
||||
keyword: str = None) -> Any:
|
||||
"""分页获取登录日志"""
|
||||
params = {"page": page, "size": size, "sort": sort, "order": order}
|
||||
if keyword:
|
||||
params["keyword"] = keyword
|
||||
return await self.client.get(f"{self.base_path}/login/page", params=params)
|
||||
|
||||
async def get_operation_logs_by_page(self, page: int = 0, size: int = 10,
|
||||
sort: str = "id", order: str = "asc",
|
||||
keyword: str = None) -> Any:
|
||||
"""分页获取操作日志"""
|
||||
params = {"page": page, "size": size, "sort": sort, "order": order}
|
||||
if keyword:
|
||||
params["keyword"] = keyword
|
||||
return await self.client.get(f"{self.base_path}/operation/page", params=params)
|
||||
|
||||
async def get_login_log_count(self) -> Any:
|
||||
"""获取登录日志总数"""
|
||||
return await self.client.get(f"{self.base_path}/login/count")
|
||||
|
||||
async def get_operation_log_count(self) -> Any:
|
||||
"""获取操作日志总数"""
|
||||
return await self.client.get(f"{self.base_path}/operation/count")
|
||||
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
系统配置API封装
|
||||
"""
|
||||
|
||||
from typing import Dict, Any
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
class SysConfigAPI:
|
||||
"""系统参数配置API"""
|
||||
|
||||
def __init__(self, client: AsyncClient):
|
||||
self.client = client
|
||||
self.base_path = "/api/config"
|
||||
|
||||
async def get_all(self) -> Any:
|
||||
"""获取所有配置"""
|
||||
return await self.client.get(self.base_path)
|
||||
|
||||
async def get_by_key(self, config_key: str) -> Any:
|
||||
"""根据key获取配置"""
|
||||
return await self.client.get(f"{self.base_path}/key/{config_key}")
|
||||
|
||||
async def create(self, data: Dict[str, Any]) -> Any:
|
||||
"""创建配置"""
|
||||
return await self.client.post(self.base_path, json=data)
|
||||
|
||||
async def update(self, config_id: int, data: Dict[str, Any]) -> Any:
|
||||
"""更新配置"""
|
||||
return await self.client.put(f"{self.base_path}/{config_id}", json=data)
|
||||
|
||||
async def delete(self, config_id: int) -> Any:
|
||||
"""删除配置"""
|
||||
return await self.client.delete(f"{self.base_path}/{config_id}")
|
||||
|
||||
async def refresh_cache(self) -> Any:
|
||||
"""刷新缓存"""
|
||||
return await self.client.post(f"{self.base_path}/refresh")
|
||||
@@ -0,0 +1,66 @@
|
||||
"""
|
||||
字典管理API封装
|
||||
"""
|
||||
|
||||
from typing import Dict, Any, Optional
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
class DictTypeAPI:
|
||||
"""字典类型API"""
|
||||
|
||||
def __init__(self, client: AsyncClient):
|
||||
self.client = client
|
||||
self.base_path = "/api/dict/types"
|
||||
|
||||
async def get_all(self) -> Any:
|
||||
"""获取所有字典类型"""
|
||||
return await self.client.get(self.base_path)
|
||||
|
||||
async def get_by_id(self, dict_id: int) -> Any:
|
||||
"""根据ID获取字典类型"""
|
||||
return await self.client.get(f"{self.base_path}/{dict_id}")
|
||||
|
||||
async def create(self, data: Dict[str, Any]) -> Any:
|
||||
"""创建字典类型"""
|
||||
return await self.client.post(self.base_path, json=data)
|
||||
|
||||
async def update(self, dict_id: int, data: Dict[str, Any]) -> Any:
|
||||
"""更新字典类型"""
|
||||
return await self.client.put(f"{self.base_path}/{dict_id}", json=data)
|
||||
|
||||
async def delete(self, dict_id: int) -> Any:
|
||||
"""删除字典类型"""
|
||||
return await self.client.delete(f"{self.base_path}/{dict_id}")
|
||||
|
||||
|
||||
class DictDataAPI:
|
||||
"""字典数据API"""
|
||||
|
||||
def __init__(self, client: AsyncClient):
|
||||
self.client = client
|
||||
self.base_path = "/api/dict/data"
|
||||
|
||||
async def get_all(self) -> Any:
|
||||
"""获取所有字典数据"""
|
||||
return await self.client.get(self.base_path)
|
||||
|
||||
async def get_by_id(self, data_id: int) -> Any:
|
||||
"""根据ID获取字典数据"""
|
||||
return await self.client.get(f"{self.base_path}/{data_id}")
|
||||
|
||||
async def get_by_type(self, dict_type: str) -> Any:
|
||||
"""根据字典类型获取字典数据"""
|
||||
return await self.client.get(f"{self.base_path}/type/{dict_type}")
|
||||
|
||||
async def create(self, data: Dict[str, Any]) -> Any:
|
||||
"""创建字典数据"""
|
||||
return await self.client.post(self.base_path, json=data)
|
||||
|
||||
async def update(self, data_id: int, data: Dict[str, Any]) -> Any:
|
||||
"""更新字典数据"""
|
||||
return await self.client.put(f"{self.base_path}/{data_id}", json=data)
|
||||
|
||||
async def delete(self, data_id: int) -> Any:
|
||||
"""删除字典数据"""
|
||||
return await self.client.delete(f"{self.base_path}/{data_id}")
|
||||
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
文件管理API封装
|
||||
"""
|
||||
|
||||
from typing import Dict, Any
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
class SysFileAPI:
|
||||
"""文件管理API"""
|
||||
|
||||
def __init__(self, client: AsyncClient):
|
||||
self.client = client
|
||||
self.base_path = "/api/files"
|
||||
|
||||
async def get_all(self) -> Any:
|
||||
"""获取所有文件"""
|
||||
return await self.client.get(self.base_path)
|
||||
|
||||
async def get_by_id(self, file_id: int) -> Any:
|
||||
"""根据ID获取文件信息"""
|
||||
return await self.client.get(f"{self.base_path}/{file_id}")
|
||||
|
||||
async def upload(self, file_path: str, create_by: str = "test") -> Any:
|
||||
"""上传文件"""
|
||||
with open(file_path, "rb") as f:
|
||||
files = {"file": f}
|
||||
data = {"createBy": create_by}
|
||||
return await self.client.post(f"{self.base_path}/upload", files=files, data=data)
|
||||
|
||||
async def download(self, file_name: str) -> Any:
|
||||
"""下载文件"""
|
||||
return await self.client.get(f"{self.base_path}/download/{file_name}")
|
||||
|
||||
async def preview(self, file_name: str) -> Any:
|
||||
"""预览文件"""
|
||||
return await self.client.get(f"{self.base_path}/preview/{file_name}")
|
||||
|
||||
async def delete(self, file_id: int) -> Any:
|
||||
"""删除文件"""
|
||||
return await self.client.delete(f"{self.base_path}/{file_id}")
|
||||
@@ -0,0 +1,70 @@
|
||||
"""
|
||||
通知公告API封装
|
||||
"""
|
||||
|
||||
from typing import Dict, Any
|
||||
from httpx import AsyncClient
|
||||
|
||||
|
||||
class SysNoticeAPI:
|
||||
"""系统公告API"""
|
||||
|
||||
def __init__(self, client: AsyncClient):
|
||||
self.client = client
|
||||
self.base_path = "/api/notices"
|
||||
|
||||
async def get_all(self) -> Any:
|
||||
"""获取所有公告"""
|
||||
return await self.client.get(self.base_path)
|
||||
|
||||
async def get_by_id(self, notice_id: int) -> Any:
|
||||
"""根据ID获取公告"""
|
||||
return await self.client.get(f"{self.base_path}/{notice_id}")
|
||||
|
||||
async def get_by_status(self, status: str) -> Any:
|
||||
"""根据状态获取公告"""
|
||||
return await self.client.get(f"{self.base_path}/status/{status}")
|
||||
|
||||
async def create(self, data: Dict[str, Any]) -> Any:
|
||||
"""创建公告"""
|
||||
return await self.client.post(self.base_path, json=data)
|
||||
|
||||
async def update(self, notice_id: int, data: Dict[str, Any]) -> Any:
|
||||
"""更新公告"""
|
||||
return await self.client.put(f"{self.base_path}/{notice_id}", json=data)
|
||||
|
||||
async def delete(self, notice_id: int) -> Any:
|
||||
"""删除公告"""
|
||||
return await self.client.delete(f"{self.base_path}/{notice_id}")
|
||||
|
||||
|
||||
class SysMessageAPI:
|
||||
"""用户消息API"""
|
||||
|
||||
def __init__(self, client: AsyncClient):
|
||||
self.client = client
|
||||
self.base_path = "/api/messages"
|
||||
|
||||
async def get_by_user(self, user_id: int) -> Any:
|
||||
"""获取用户所有消息"""
|
||||
return await self.client.get(f"{self.base_path}/user/{user_id}")
|
||||
|
||||
async def get_unread_count(self, user_id: int) -> Any:
|
||||
"""获取未读消息数量"""
|
||||
return await self.client.get(f"{self.base_path}/user/{user_id}/unread")
|
||||
|
||||
async def get_unread_list(self, user_id: int) -> Any:
|
||||
"""获取未读消息列表"""
|
||||
return await self.client.get(f"{self.base_path}/user/{user_id}/unread/list")
|
||||
|
||||
async def create(self, data: Dict[str, Any]) -> Any:
|
||||
"""创建消息"""
|
||||
return await self.client.post(self.base_path, json=data)
|
||||
|
||||
async def mark_as_read(self, message_id: int) -> Any:
|
||||
"""标记消息为已读"""
|
||||
return await self.client.put(f"{self.base_path}/{message_id}/read")
|
||||
|
||||
async def delete(self, message_id: int) -> Any:
|
||||
"""删除消息"""
|
||||
return await self.client.delete(f"{self.base_path}/{message_id}")
|
||||
+16
-15
@@ -34,25 +34,26 @@ class RoleAPI(BaseAPI):
|
||||
return await self.put(f"/{role_id}", json=role_data)
|
||||
|
||||
async def delete_role(self, role_id: int) -> Response:
|
||||
"""删除角色"""
|
||||
"""删除角色(逻辑删除)"""
|
||||
return await self.delete(f"/{role_id}")
|
||||
|
||||
async def logical_delete_role(self, role_id: int) -> Response:
|
||||
"""逻辑删除角色"""
|
||||
return await self.delete(f"/{role_id}/logical")
|
||||
|
||||
async def logical_delete_roles(self, role_ids: List[int]) -> Response:
|
||||
"""批量逻辑删除角色"""
|
||||
return await self.post("/logical-delete", json=role_ids)
|
||||
|
||||
|
||||
async def restore_role(self, role_id: int) -> Response:
|
||||
"""恢复角色"""
|
||||
return await self.post(f"/{role_id}/restore")
|
||||
|
||||
async def restore_roles(self, role_ids: List[int]) -> Response:
|
||||
"""批量恢复角色"""
|
||||
return await self.post("/restore", json=role_ids)
|
||||
|
||||
async def check_name_exists(self, role_name: str) -> Response:
|
||||
"""检查角色名是否存在"""
|
||||
return await self.get("/check/name", params={"name": role_name})
|
||||
return await self.get("/check-name", params={"name": role_name})
|
||||
|
||||
async def get_roles_by_page(self, page: int = 0, size: int = 10,
|
||||
sort: str = "id", order: str = "asc",
|
||||
keyword: str = None) -> Response:
|
||||
"""分页获取角色"""
|
||||
params = {"page": page, "size": size, "sort": sort, "order": order}
|
||||
if keyword:
|
||||
params["keyword"] = keyword
|
||||
return await self.get("/page", params=params)
|
||||
|
||||
async def get_role_count(self) -> Response:
|
||||
"""获取角色总数"""
|
||||
return await self.get("/count")
|
||||
|
||||
@@ -56,3 +56,16 @@ class UserAPI(BaseAPI):
|
||||
async def check_email_exists(self, email: str) -> Response:
|
||||
"""检查邮箱是否存在"""
|
||||
return await self.get("/check/email", params={"email": email})
|
||||
|
||||
async def get_users_by_page(self, page: int = 0, size: int = 10,
|
||||
sort: str = "id", order: str = "asc",
|
||||
keyword: str = None) -> Response:
|
||||
"""分页获取用户"""
|
||||
params = {"page": page, "size": size, "sort": sort, "order": order}
|
||||
if keyword:
|
||||
params["keyword"] = keyword
|
||||
return await self.get("/page", params=params)
|
||||
|
||||
async def get_user_count(self) -> Response:
|
||||
"""获取用户总数"""
|
||||
return await self.get("/count")
|
||||
|
||||
Reference in New Issue
Block a user