style: 使用ruff格式化日志管理模块,优化导入
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
from sqlalchemy import select, update, delete, asc, desc
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from module_admin.entity.do.log_do import SysOperLog, SysLogininfor
|
||||
from module_admin.entity.vo.log_vo import *
|
||||
from utils.page_util import PageUtil
|
||||
from utils.common_util import SnakeCaseUtil
|
||||
from datetime import datetime, time
|
||||
from sqlalchemy import asc, delete, desc, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from module_admin.entity.do.log_do import SysLogininfor, SysOperLog
|
||||
from module_admin.entity.vo.log_vo import LogininforModel, LoginLogPageQueryModel, OperLogModel, OperLogPageQueryModel
|
||||
from utils.common_util import SnakeCaseUtil
|
||||
from utils.page_util import PageUtil
|
||||
|
||||
|
||||
class OperationLogDao:
|
||||
@@ -25,20 +25,27 @@ class OperationLogDao:
|
||||
order_by_column = asc(getattr(SysOperLog, SnakeCaseUtil.camel_to_snake(query_object.order_by_column), None))
|
||||
elif query_object.is_asc == 'descending':
|
||||
order_by_column = desc(
|
||||
getattr(SysOperLog, SnakeCaseUtil.camel_to_snake(query_object.order_by_column), None))
|
||||
getattr(SysOperLog, SnakeCaseUtil.camel_to_snake(query_object.order_by_column), None)
|
||||
)
|
||||
else:
|
||||
order_by_column = desc(SysOperLog.oper_time)
|
||||
query = select(SysOperLog) \
|
||||
.where(SysOperLog.title.like(f'%{query_object.title}%') if query_object.title else True,
|
||||
SysOperLog.oper_name.like(f'%{query_object.oper_name}%') if query_object.oper_name else True,
|
||||
SysOperLog.business_type == query_object.business_type if query_object.business_type else True,
|
||||
SysOperLog.status == query_object.status if query_object.status else True,
|
||||
SysOperLog.oper_time.between(
|
||||
datetime.combine(datetime.strptime(query_object.begin_time, '%Y-%m-%d'), time(00, 00, 00)),
|
||||
datetime.combine(datetime.strptime(query_object.end_time, '%Y-%m-%d'), time(23, 59, 59)))
|
||||
if query_object.begin_time and query_object.end_time else True) \
|
||||
.distinct() \
|
||||
query = (
|
||||
select(SysOperLog)
|
||||
.where(
|
||||
SysOperLog.title.like(f'%{query_object.title}%') if query_object.title else True,
|
||||
SysOperLog.oper_name.like(f'%{query_object.oper_name}%') if query_object.oper_name else True,
|
||||
SysOperLog.business_type == query_object.business_type if query_object.business_type else True,
|
||||
SysOperLog.status == query_object.status if query_object.status else True,
|
||||
SysOperLog.oper_time.between(
|
||||
datetime.combine(datetime.strptime(query_object.begin_time, '%Y-%m-%d'), time(00, 00, 00)),
|
||||
datetime.combine(datetime.strptime(query_object.end_time, '%Y-%m-%d'), time(23, 59, 59)),
|
||||
)
|
||||
if query_object.begin_time and query_object.end_time
|
||||
else True,
|
||||
)
|
||||
.distinct()
|
||||
.order_by(order_by_column)
|
||||
)
|
||||
operation_log_list = await PageUtil.paginate(db, query, query_object.page_num, query_object.page_size, is_page)
|
||||
|
||||
return operation_log_list
|
||||
@@ -65,10 +72,7 @@ class OperationLogDao:
|
||||
:param operation_log: 操作日志对象
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
delete(SysOperLog)
|
||||
.where(SysOperLog.oper_id.in_([operation_log.oper_id]))
|
||||
)
|
||||
await db.execute(delete(SysOperLog).where(SysOperLog.oper_id.in_([operation_log.oper_id])))
|
||||
|
||||
@classmethod
|
||||
async def clear_operation_log_dao(cls, db: AsyncSession):
|
||||
@@ -77,9 +81,7 @@ class OperationLogDao:
|
||||
:param db: orm对象
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
delete(SysOperLog)
|
||||
)
|
||||
await db.execute(delete(SysOperLog))
|
||||
|
||||
|
||||
class LoginLogDao:
|
||||
@@ -98,22 +100,30 @@ class LoginLogDao:
|
||||
"""
|
||||
if query_object.is_asc == 'ascending':
|
||||
order_by_column = asc(
|
||||
getattr(SysLogininfor, SnakeCaseUtil.camel_to_snake(query_object.order_by_column), None))
|
||||
getattr(SysLogininfor, SnakeCaseUtil.camel_to_snake(query_object.order_by_column), None)
|
||||
)
|
||||
elif query_object.is_asc == 'descending':
|
||||
order_by_column = desc(
|
||||
getattr(SysLogininfor, SnakeCaseUtil.camel_to_snake(query_object.order_by_column), None))
|
||||
getattr(SysLogininfor, SnakeCaseUtil.camel_to_snake(query_object.order_by_column), None)
|
||||
)
|
||||
else:
|
||||
order_by_column = desc(SysLogininfor.login_time)
|
||||
query = select(SysLogininfor) \
|
||||
.where(SysLogininfor.ipaddr.like(f'%{query_object.ipaddr}%') if query_object.ipaddr else True,
|
||||
SysLogininfor.user_name.like(f'%{query_object.user_name}%') if query_object.user_name else True,
|
||||
SysLogininfor.status == query_object.status if query_object.status else True,
|
||||
SysLogininfor.login_time.between(
|
||||
datetime.combine(datetime.strptime(query_object.begin_time, '%Y-%m-%d'), time(00, 00, 00)),
|
||||
datetime.combine(datetime.strptime(query_object.end_time, '%Y-%m-%d'), time(23, 59, 59)))
|
||||
if query_object.begin_time and query_object.end_time else True) \
|
||||
.distinct() \
|
||||
query = (
|
||||
select(SysLogininfor)
|
||||
.where(
|
||||
SysLogininfor.ipaddr.like(f'%{query_object.ipaddr}%') if query_object.ipaddr else True,
|
||||
SysLogininfor.user_name.like(f'%{query_object.user_name}%') if query_object.user_name else True,
|
||||
SysLogininfor.status == query_object.status if query_object.status else True,
|
||||
SysLogininfor.login_time.between(
|
||||
datetime.combine(datetime.strptime(query_object.begin_time, '%Y-%m-%d'), time(00, 00, 00)),
|
||||
datetime.combine(datetime.strptime(query_object.end_time, '%Y-%m-%d'), time(23, 59, 59)),
|
||||
)
|
||||
if query_object.begin_time and query_object.end_time
|
||||
else True,
|
||||
)
|
||||
.distinct()
|
||||
.order_by(order_by_column)
|
||||
)
|
||||
login_log_list = await PageUtil.paginate(db, query, query_object.page_num, query_object.page_size, is_page)
|
||||
|
||||
return login_log_list
|
||||
@@ -140,10 +150,7 @@ class LoginLogDao:
|
||||
:param login_log: 登录日志对象
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
delete(SysLogininfor)
|
||||
.where(SysLogininfor.info_id.in_([login_log.info_id]))
|
||||
)
|
||||
await db.execute(delete(SysLogininfor).where(SysLogininfor.info_id.in_([login_log.info_id])))
|
||||
|
||||
@classmethod
|
||||
async def clear_login_log_dao(cls, db: AsyncSession):
|
||||
@@ -152,6 +159,4 @@ class LoginLogDao:
|
||||
:param db: orm对象
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
delete(SysLogininfor)
|
||||
)
|
||||
await db.execute(delete(SysLogininfor))
|
||||
|
Reference in New Issue
Block a user