style: 使用ruff格式化参数配置模块,优化导入
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from sqlalchemy import select, update, delete
|
||||
from datetime import datetime, time
|
||||
from sqlalchemy import delete, select, update
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from module_admin.entity.do.config_do import SysConfig
|
||||
from module_admin.entity.vo.config_vo import *
|
||||
from module_admin.entity.vo.config_vo import ConfigModel, ConfigPageQueryModel
|
||||
from utils.page_util import PageUtil
|
||||
from datetime import datetime, time
|
||||
|
||||
|
||||
class ConfigDao:
|
||||
@@ -19,10 +19,7 @@ class ConfigDao:
|
||||
:param config_id: 参数配置id
|
||||
:return: 参数配置信息对象
|
||||
"""
|
||||
config_info = (await db.execute(
|
||||
select(SysConfig)
|
||||
.where(SysConfig.config_id == config_id)
|
||||
)).scalars().first()
|
||||
config_info = (await db.execute(select(SysConfig).where(SysConfig.config_id == config_id))).scalars().first()
|
||||
|
||||
return config_info
|
||||
|
||||
@@ -34,11 +31,18 @@ class ConfigDao:
|
||||
:param config: 参数配置参数对象
|
||||
:return: 参数配置信息对象
|
||||
"""
|
||||
config_info = (await db.execute(
|
||||
select(SysConfig)
|
||||
.where(SysConfig.config_key == config.config_key if config.config_key else True,
|
||||
SysConfig.config_value == config.config_value if config.config_value else True)
|
||||
)).scalars().first()
|
||||
config_info = (
|
||||
(
|
||||
await db.execute(
|
||||
select(SysConfig).where(
|
||||
SysConfig.config_key == config.config_key if config.config_key else True,
|
||||
SysConfig.config_value == config.config_value if config.config_value else True,
|
||||
)
|
||||
)
|
||||
)
|
||||
.scalars()
|
||||
.first()
|
||||
)
|
||||
|
||||
return config_info
|
||||
|
||||
@@ -51,15 +55,21 @@ class ConfigDao:
|
||||
:param is_page: 是否开启分页
|
||||
:return: 参数配置列表信息对象
|
||||
"""
|
||||
query = select(SysConfig) \
|
||||
.where(SysConfig.config_name.like(f'%{query_object.config_name}%') if query_object.config_name else True,
|
||||
SysConfig.config_key.like(f'%{query_object.config_key}%') if query_object.config_key else True,
|
||||
SysConfig.config_type == query_object.config_type if query_object.config_type else True,
|
||||
SysConfig.create_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) \
|
||||
query = (
|
||||
select(SysConfig)
|
||||
.where(
|
||||
SysConfig.config_name.like(f'%{query_object.config_name}%') if query_object.config_name else True,
|
||||
SysConfig.config_key.like(f'%{query_object.config_key}%') if query_object.config_key else True,
|
||||
SysConfig.config_type == query_object.config_type if query_object.config_type else True,
|
||||
SysConfig.create_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()
|
||||
)
|
||||
config_list = await PageUtil.paginate(db, query, query_object.page_num, query_object.page_size, is_page)
|
||||
|
||||
return config_list
|
||||
@@ -86,10 +96,7 @@ class ConfigDao:
|
||||
:param config: 需要更新的参数配置字典
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
update(SysConfig),
|
||||
[config]
|
||||
)
|
||||
await db.execute(update(SysConfig), [config])
|
||||
|
||||
@classmethod
|
||||
async def delete_config_dao(cls, db: AsyncSession, config: ConfigModel):
|
||||
@@ -99,7 +106,4 @@ class ConfigDao:
|
||||
:param config: 参数配置对象
|
||||
:return:
|
||||
"""
|
||||
await db.execute(
|
||||
delete(SysConfig)
|
||||
.where(SysConfig.config_id.in_([config.config_id]))
|
||||
)
|
||||
await db.execute(delete(SysConfig).where(SysConfig.config_id.in_([config.config_id])))
|
||||
|
Reference in New Issue
Block a user