style: 使用ruff格式化部门管理模块,优化导入
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from sqlalchemy import select, update, delete, or_, func, bindparam
|
||||
from sqlalchemy import bindparam, func, or_, select, update # noqa: F401
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.util import immutabledict
|
||||
from typing import List
|
||||
from module_admin.entity.do.dept_do import SysDept
|
||||
from module_admin.entity.do.role_do import SysRoleDept # noqa: F401
|
||||
from module_admin.entity.do.user_do import SysUser
|
||||
from module_admin.entity.do.role_do import SysRoleDept
|
||||
from module_admin.entity.vo.dept_vo import *
|
||||
from module_admin.entity.vo.dept_vo import DeptModel
|
||||
|
||||
|
||||
class DeptDao:
|
||||
@@ -20,10 +21,7 @@ class DeptDao:
|
||||
:param dept_id: 部门id
|
||||
:return: 在用部门信息对象
|
||||
"""
|
||||
dept_info = (await db.execute(
|
||||
select(SysDept)
|
||||
.where(SysDept.dept_id == dept_id)
|
||||
)).scalars().first()
|
||||
dept_info = (await db.execute(select(SysDept).where(SysDept.dept_id == dept_id))).scalars().first()
|
||||
|
||||
return dept_info
|
||||
|
||||
@@ -35,11 +33,11 @@ class DeptDao:
|
||||
:param dept_id: 部门id
|
||||
:return: 部门信息对象
|
||||
"""
|
||||
dept_info = (await db.execute(
|
||||
select(SysDept)
|
||||
.where(SysDept.dept_id == dept_id,
|
||||
SysDept.del_flag == '0')
|
||||
)).scalars().first()
|
||||
dept_info = (
|
||||
(await db.execute(select(SysDept).where(SysDept.dept_id == dept_id, SysDept.del_flag == '0')))
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
return dept_info
|
||||
|
||||
@@ -51,11 +49,18 @@ class DeptDao:
|
||||
:param dept: 部门参数对象
|
||||
:return: 部门信息对象
|
||||
"""
|
||||
dept_info = (await db.execute(
|
||||
select(SysDept)
|
||||
.where(SysDept.parent_id == dept.parent_id if dept.parent_id else True,
|
||||
SysDept.dept_name == dept.dept_name if dept.dept_name else True)
|
||||
)).scalars().first()
|
||||
dept_info = (
|
||||
(
|
||||
await db.execute(
|
||||
select(SysDept).where(
|
||||
SysDept.parent_id == dept.parent_id if dept.parent_id else True,
|
||||
SysDept.dept_name == dept.dept_name if dept.dept_name else True,
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
return dept_info
|
||||
|
||||
@@ -68,15 +73,26 @@ class DeptDao:
|
||||
:param data_scope_sql: 数据权限对应的查询sql语句
|
||||
:return: 部门列表信息
|
||||
"""
|
||||
dept_result = (await db.execute(
|
||||
select(SysDept)
|
||||
.where(SysDept.dept_id != dept_info.dept_id,
|
||||
~SysDept.dept_id.in_(select(SysDept.dept_id).where(func.find_in_set(dept_info.dept_id, SysDept.ancestors))),
|
||||
SysDept.del_flag == '0', SysDept.status == '0',
|
||||
eval(data_scope_sql))
|
||||
.order_by(SysDept.order_num)
|
||||
.distinct()
|
||||
)).scalars().all()
|
||||
dept_result = (
|
||||
(
|
||||
await db.execute(
|
||||
select(SysDept)
|
||||
.where(
|
||||
SysDept.dept_id != dept_info.dept_id,
|
||||
~SysDept.dept_id.in_(
|
||||
select(SysDept.dept_id).where(func.find_in_set(dept_info.dept_id, SysDept.ancestors))
|
||||
),
|
||||
SysDept.del_flag == '0',
|
||||
SysDept.status == '0',
|
||||
eval(data_scope_sql),
|
||||
)
|
||||
.order_by(SysDept.order_num)
|
||||
.distinct()
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
return dept_result
|
||||
|
||||
@@ -88,10 +104,9 @@ class DeptDao:
|
||||
:param dept_id: 部门id
|
||||
:return: 子部门信息列表
|
||||
"""
|
||||
dept_result = (await db.execute(
|
||||
select(SysDept)
|
||||
.where(func.find_in_set(dept_id, SysDept.ancestors))
|
||||
)).scalars().all()
|
||||
dept_result = (
|
||||
(await db.execute(select(SysDept).where(func.find_in_set(dept_id, SysDept.ancestors)))).scalars().all()
|
||||
)
|
||||
|
||||
return dept_result
|
||||
|
||||
@@ -104,15 +119,23 @@ class DeptDao:
|
||||
:param data_scope_sql: 数据权限对应的查询sql语句
|
||||
:return: 在用部门列表信息
|
||||
"""
|
||||
dept_result = (await db.execute(
|
||||
select(SysDept)
|
||||
.where(SysDept.status == '0',
|
||||
SysDept.del_flag == '0',
|
||||
SysDept.dept_name.like(f'%{dept_info.dept_name}%') if dept_info.dept_name else True,
|
||||
eval(data_scope_sql))
|
||||
.order_by(SysDept.order_num)
|
||||
.distinct()
|
||||
)).scalars().all()
|
||||
dept_result = (
|
||||
(
|
||||
await db.execute(
|
||||
select(SysDept)
|
||||
.where(
|
||||
SysDept.status == '0',
|
||||
SysDept.del_flag == '0',
|
||||
SysDept.dept_name.like(f'%{dept_info.dept_name}%') if dept_info.dept_name else True,
|
||||
eval(data_scope_sql),
|
||||
)
|
||||
.order_by(SysDept.order_num)
|
||||
.distinct()
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
return dept_result
|
||||
|
||||
@@ -125,15 +148,23 @@ class DeptDao:
|
||||
:param data_scope_sql: 数据权限对应的查询sql语句
|
||||
:return: 部门列表信息对象
|
||||
"""
|
||||
dept_result = (await db.execute(
|
||||
select(SysDept)
|
||||
.where(SysDept.del_flag == '0',
|
||||
SysDept.status == page_object.status if page_object.status else True,
|
||||
SysDept.dept_name.like(f'%{page_object.dept_name}%') if page_object.dept_name else True,
|
||||
eval(data_scope_sql))
|
||||
.order_by(SysDept.order_num)
|
||||
.distinct()
|
||||
)).scalars().all()
|
||||
dept_result = (
|
||||
(
|
||||
await db.execute(
|
||||
select(SysDept)
|
||||
.where(
|
||||
SysDept.del_flag == '0',
|
||||
SysDept.status == page_object.status if page_object.status else True,
|
||||
SysDept.dept_name.like(f'%{page_object.dept_name}%') if page_object.dept_name else True,
|
||||
eval(data_scope_sql),
|
||||
)
|
||||
.order_by(SysDept.order_num)
|
||||
.distinct()
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.all()
|
||||
)
|
||||
|
||||
return dept_result
|
||||
|
||||
@@ -159,10 +190,7 @@ class DeptDao:
|
||||
:param dept: 需要更新的部门字典
|
||||
:return: 编辑校验结果
|
||||
"""
|
||||
await db.execute(
|
||||
update(SysDept),
|
||||
[dept]
|
||||
)
|
||||
await db.execute(update(SysDept), [dept])
|
||||
|
||||
@classmethod
|
||||
async def update_dept_children_dao(cls, db: AsyncSession, update_dept: List):
|
||||
@@ -174,17 +202,15 @@ class DeptDao:
|
||||
"""
|
||||
await db.execute(
|
||||
update(SysDept)
|
||||
.where(SysDept.dept_id == bindparam('dept_id'))
|
||||
.values(
|
||||
.where(SysDept.dept_id == bindparam('dept_id'))
|
||||
.values(
|
||||
{
|
||||
'dept_id': bindparam('dept_id'),
|
||||
'ancestors': bindparam('ancestors'),
|
||||
}
|
||||
),
|
||||
update_dept,
|
||||
execution_options=immutabledict(
|
||||
{"synchronize_session": None}
|
||||
)
|
||||
execution_options=immutabledict({'synchronize_session': None}),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -195,11 +221,7 @@ class DeptDao:
|
||||
:param dept_id_list: 部门id列表
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
update(SysDept)
|
||||
.where(SysDept.dept_id.in_(dept_id_list))
|
||||
.values(status='0')
|
||||
)
|
||||
await db.execute(update(SysDept).where(SysDept.dept_id.in_(dept_id_list)).values(status='0'))
|
||||
|
||||
@classmethod
|
||||
async def delete_dept_dao(cls, db: AsyncSession, dept: DeptModel):
|
||||
@@ -211,8 +233,8 @@ class DeptDao:
|
||||
"""
|
||||
await db.execute(
|
||||
update(SysDept)
|
||||
.where(SysDept.dept_id == dept.dept_id)
|
||||
.values(del_flag='2', update_by=dept.update_by, update_time=dept.update_time)
|
||||
.where(SysDept.dept_id == dept.dept_id)
|
||||
.values(del_flag='2', update_by=dept.update_by, update_time=dept.update_time)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -223,15 +245,13 @@ class DeptDao:
|
||||
:param dept_id: 部门id
|
||||
:return: 所有子部门(正常状态)的数量
|
||||
"""
|
||||
normal_children_dept_count = (await db.execute(
|
||||
select(func.count('*'))
|
||||
normal_children_dept_count = (
|
||||
await db.execute(
|
||||
select(func.count('*'))
|
||||
.select_from(SysDept)
|
||||
.where(
|
||||
SysDept.status == '0',
|
||||
SysDept.del_flag == '0',
|
||||
func.find_in_set(dept_id, SysDept.ancestors)
|
||||
.where(SysDept.status == '0', SysDept.del_flag == '0', func.find_in_set(dept_id, SysDept.ancestors))
|
||||
)
|
||||
)).scalar()
|
||||
).scalar()
|
||||
|
||||
return normal_children_dept_count
|
||||
|
||||
@@ -243,13 +263,14 @@ class DeptDao:
|
||||
:param dept_id: 部门id
|
||||
:return: 所有子部门(所有状态)的数量
|
||||
"""
|
||||
children_dept_count = (await db.execute(
|
||||
select(func.count('*'))
|
||||
children_dept_count = (
|
||||
await db.execute(
|
||||
select(func.count('*'))
|
||||
.select_from(SysDept)
|
||||
.where(SysDept.del_flag == '0',
|
||||
SysDept.parent_id == dept_id)
|
||||
.where(SysDept.del_flag == '0', SysDept.parent_id == dept_id)
|
||||
.limit(1)
|
||||
)).scalar()
|
||||
)
|
||||
).scalar()
|
||||
|
||||
return children_dept_count
|
||||
|
||||
@@ -261,10 +282,10 @@ class DeptDao:
|
||||
:param dept_id: 部门id
|
||||
:return: 部门下的用户数量
|
||||
"""
|
||||
dept_user_count = (await db.execute(
|
||||
select(func.count('*'))
|
||||
.select_from(SysUser)
|
||||
.where(SysUser.dept_id == dept_id, SysUser.del_flag == '0')
|
||||
)).scalar()
|
||||
dept_user_count = (
|
||||
await db.execute(
|
||||
select(func.count('*')).select_from(SysUser).where(SysUser.dept_id == dept_id, SysUser.del_flag == '0')
|
||||
)
|
||||
).scalar()
|
||||
|
||||
return dept_user_count
|
||||
|
Reference in New Issue
Block a user