style: 使用ruff格式化岗位管理模块,优化导入
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from sqlalchemy import select, update, delete, func
|
||||
from sqlalchemy import delete, func, select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from module_admin.entity.do.post_do import SysPost
|
||||
from module_admin.entity.do.user_do import SysUserPost
|
||||
from module_admin.entity.vo.post_vo import *
|
||||
from module_admin.entity.vo.post_vo import PostModel, PostPageQueryModel
|
||||
from utils.page_util import PageUtil
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ class PostDao:
|
||||
:param post_id: 岗位id
|
||||
:return: 在用岗位信息对象
|
||||
"""
|
||||
post_info = (await db.execute(
|
||||
select(SysPost)
|
||||
.where(SysPost.post_id == post_id,
|
||||
SysPost.status == '0')
|
||||
)).scalars().first()
|
||||
post_info = (
|
||||
(await db.execute(select(SysPost).where(SysPost.post_id == post_id, SysPost.status == '0')))
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
return post_info
|
||||
|
||||
@@ -35,10 +35,7 @@ class PostDao:
|
||||
:param post_id: 岗位id
|
||||
:return: 岗位信息对象
|
||||
"""
|
||||
post_info = (await db.execute(
|
||||
select(SysPost)
|
||||
.where(SysPost.post_id == post_id)
|
||||
)).scalars().first()
|
||||
post_info = (await db.execute(select(SysPost).where(SysPost.post_id == post_id))).scalars().first()
|
||||
|
||||
return post_info
|
||||
|
||||
@@ -50,12 +47,19 @@ class PostDao:
|
||||
:param post: 岗位参数对象
|
||||
:return: 岗位信息对象
|
||||
"""
|
||||
post_info = (await db.execute(
|
||||
select(SysPost)
|
||||
.where(SysPost.post_name == post.post_name if post.post_name else True,
|
||||
SysPost.post_code == post.post_code if post.post_code else True,
|
||||
SysPost.post_sort == post.post_sort if post.post_sort else True)
|
||||
)).scalars().first()
|
||||
post_info = (
|
||||
(
|
||||
await db.execute(
|
||||
select(SysPost).where(
|
||||
SysPost.post_name == post.post_name if post.post_name else True,
|
||||
SysPost.post_code == post.post_code if post.post_code else True,
|
||||
SysPost.post_sort == post.post_sort if post.post_sort else True,
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
return post_info
|
||||
|
||||
@@ -68,12 +72,16 @@ class PostDao:
|
||||
:param is_page: 是否开启分页
|
||||
:return: 岗位列表信息对象
|
||||
"""
|
||||
query = select(SysPost) \
|
||||
.where(SysPost.post_code.like(f'%{query_object.post_code}%') if query_object.post_code else True,
|
||||
SysPost.post_name.like(f'%{query_object.post_name}%') if query_object.post_name else True,
|
||||
SysPost.status == query_object.status if query_object.status else True) \
|
||||
.order_by(SysPost.post_sort) \
|
||||
query = (
|
||||
select(SysPost)
|
||||
.where(
|
||||
SysPost.post_code.like(f'%{query_object.post_code}%') if query_object.post_code else True,
|
||||
SysPost.post_name.like(f'%{query_object.post_name}%') if query_object.post_name else True,
|
||||
SysPost.status == query_object.status if query_object.status else True,
|
||||
)
|
||||
.order_by(SysPost.post_sort)
|
||||
.distinct()
|
||||
)
|
||||
post_list = await PageUtil.paginate(db, query, query_object.page_num, query_object.page_size, is_page)
|
||||
|
||||
return post_list
|
||||
@@ -100,10 +108,7 @@ class PostDao:
|
||||
:param post: 需要更新的岗位字典
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
update(SysPost),
|
||||
[post]
|
||||
)
|
||||
await db.execute(update(SysPost), [post])
|
||||
|
||||
@classmethod
|
||||
async def delete_post_dao(cls, db: AsyncSession, post: PostModel):
|
||||
@@ -113,10 +118,7 @@ class PostDao:
|
||||
:param post: 岗位对象
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
delete(SysPost)
|
||||
.where(SysPost.post_id.in_([post.post_id]))
|
||||
)
|
||||
await db.execute(delete(SysPost).where(SysPost.post_id.in_([post.post_id])))
|
||||
|
||||
@classmethod
|
||||
async def count_user_post_dao(cls, db: AsyncSession, post_id: int):
|
||||
@@ -126,10 +128,8 @@ class PostDao:
|
||||
:param post_id: 岗位id
|
||||
:return: 岗位关联的用户数量
|
||||
"""
|
||||
user_post_count = (await db.execute(
|
||||
select(func.count('*'))
|
||||
.select_from(SysUserPost)
|
||||
.where(SysUserPost.post_id == post_id)
|
||||
)).scalar()
|
||||
user_post_count = (
|
||||
await db.execute(select(func.count('*')).select_from(SysUserPost).where(SysUserPost.post_id == post_id))
|
||||
).scalar()
|
||||
|
||||
return user_post_count
|
||||
|
Reference in New Issue
Block a user