refactor: 重构服务层方法命名规范

fix: 修复文件下载和删除功能
fix: 修复Redis哈希获取方法返回值类型
fix: 修复权限检查逻辑

perf: 优化部门和服务详情查询性能
perf: 优化角色数据范围显示

style: 清理无用导入和注释
style: 统一CRUD方法命名

docs: 更新main.py中的命令说明

chore: 移动IP定位工具类位置
chore: 更新.gitignore忽略迁移版本文件
This commit is contained in:
zhangtao
2025-10-03 03:31:45 +08:00
parent 7b9d8d7854
commit 119964e6f9
42 changed files with 326 additions and 545 deletions
+19 -14
View File
@@ -79,7 +79,7 @@ class UserCRUD(CRUDBase[UserModel, UserCreateSchema, UserUpdateSchema]):
Returns:
Optional[UserModel]: 更新后的用户信息
"""
return await self.update(id=id, data={"last_login": datetime.now()})
return await self.update(id=id, data=UserUpdateSchema(last_login=datetime.now()))
async def set_available_crud(self, ids: List[int], status: bool) -> None:
"""
@@ -104,11 +104,13 @@ class UserCRUD(CRUDBase[UserModel, UserCreateSchema, UserUpdateSchema]):
role_objs = await RoleCRUD(self.auth).get_list_crud(search={"id": ("in", role_ids)})
else:
role_objs = []
await self.update_relationships(
objs_to_update=user_objs,
relationship_field="roles",
related_objs=role_objs
)
for obj in user_objs:
relationship = obj.roles
relationship.clear()
relationship.extend(role_objs)
await self.db.flush()
async def set_user_positions_crud(self, user_ids: List[int], position_ids: List[int]) -> None:
"""
@@ -123,11 +125,12 @@ class UserCRUD(CRUDBase[UserModel, UserCreateSchema, UserUpdateSchema]):
position_objs = await PositionCRUD(self.auth).get_list_crud(search={"id": ("in", position_ids)})
else:
position_objs = []
await self.update_relationships(
objs_to_update=user_objs,
relationship_field="positions",
related_objs=position_objs
)
for obj in user_objs:
relationship = obj.positions
relationship.clear()
relationship.extend(position_objs)
await self.db.flush()
async def change_password_crud(self, id: int, password_hash: str) -> Optional[UserModel]:
"""
@@ -140,7 +143,9 @@ class UserCRUD(CRUDBase[UserModel, UserCreateSchema, UserUpdateSchema]):
Returns:
Optional[UserModel]: 更新后的用户信息
"""
return await self.update(id=id, data={"password": password_hash})
return await self.update(id=id, data=UserUpdateSchema(password=password_hash))
async def forget_password_crud(self, id: int, password_hash: str) -> Optional[UserModel]:
"""
@@ -153,7 +158,7 @@ class UserCRUD(CRUDBase[UserModel, UserCreateSchema, UserUpdateSchema]):
Returns:
Optional[UserModel]: 更新后的用户信息
"""
return await self.update(id=id, data={"password": password_hash})
return await self.update(id=id, data=UserUpdateSchema(password=password_hash))
async def register_user_crud(self, data: UserForgetPasswordSchema) -> Optional[UserModel]:
"""
@@ -168,4 +173,4 @@ class UserCRUD(CRUDBase[UserModel, UserCreateSchema, UserUpdateSchema]):
if await self.get_by_username_crud(username=data.username):
return None
return await self.create(data=data)
return await self.create(data=UserCreateSchema(**data.model_dump()))