From 2e7a7f38f2fa0e758453ae97e0bc1b88fd45db06 Mon Sep 17 00:00:00 2001 From: PoetryL <1093755773@qq.com> Date: Thu, 27 Mar 2025 17:31:49 +0800 Subject: [PATCH] fix(dept): Fixed the dept del logic. Fixed the situation where the parent department could not be deleted when all its subordinate departments under it were logically deleted. --- backend/app/admin/crud/crud_dept.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/app/admin/crud/crud_dept.py b/backend/app/admin/crud/crud_dept.py index d23897fed..80bf286c3 100644 --- a/backend/app/admin/crud/crud_dept.py +++ b/backend/app/admin/crud/crud_dept.py @@ -100,7 +100,7 @@ async def get_with_relation(self, db: AsyncSession, dept_id: int) -> list[User]: user_relation = result.scalars().first() return user_relation.users - async def get_children(self, db: AsyncSession, dept_id: int) -> list[Dept]: + async def get_children(self, db: AsyncSession, dept_id: int) -> Sequence[Dept]: """ 获取子部门 @@ -108,10 +108,9 @@ async def get_children(self, db: AsyncSession, dept_id: int) -> list[Dept]: :param dept_id: :return: """ - stmt = select(self.model).options(selectinload(self.model.children)).where(self.model.id == dept_id) + stmt = select(self.model).where(self.model.parent_id == dept_id, self.model.del_flag == 0) result = await db.execute(stmt) - dept = result.scalars().first() - return dept.children + return result.scalars().all() dept_dao: CRUDDept = CRUDDept(Dept)