调整部分前端布局和后端增删改逻辑
This commit is contained in:
@@ -11,7 +11,6 @@ from openpyxl.utils import get_column_letter
|
||||
from openpyxl.worksheet.datavalidation import DataValidation
|
||||
from sqlalchemy.engine.row import Row
|
||||
from sqlalchemy.orm.collections import InstrumentedList
|
||||
from sqlalchemy.sql.expression import TextClause, null
|
||||
|
||||
from config.database import Base
|
||||
from config.env import CachePathConfig
|
||||
@@ -153,17 +152,14 @@ class SqlalchemyUtil:
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def get_server_default_null(cls, dialect_name: str, need_explicit_null: bool = True) -> TextClause | None:
|
||||
def get_server_default_null(cls, dialect_name: str, need_explicit_null: bool = True) -> None:
|
||||
"""
|
||||
根据数据库方言动态返回值为null的server_default
|
||||
|
||||
:param dialect_name: 数据库方言名称
|
||||
:param need_explicit_null: 是否需要显式DEFAULT NULL
|
||||
:return: 不同数据库方言对应的null_server_default
|
||||
:return: MySQL 使用隐式 NULL,不设置显式默认值
|
||||
"""
|
||||
if need_explicit_null and dialect_name == 'postgresql':
|
||||
return null()
|
||||
return None
|
||||
|
||||
|
||||
class CamelCaseUtil:
|
||||
|
||||
@@ -13,6 +13,27 @@ class PageUtil:
|
||||
分页工具类
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def _remove_excluded_fields(cls, value: Any, excluded_fields: set[str]) -> Any:
|
||||
if isinstance(value, dict):
|
||||
return {
|
||||
key: cls._remove_excluded_fields(item, excluded_fields)
|
||||
for key, item in value.items()
|
||||
if key not in excluded_fields
|
||||
}
|
||||
if isinstance(value, list):
|
||||
return [cls._remove_excluded_fields(item, excluded_fields) for item in value]
|
||||
return value
|
||||
|
||||
@classmethod
|
||||
def _transform_rows(cls, rows: list[Any], exclude_fields: set[str] | None) -> Any:
|
||||
transformed = CamelCaseUtil.transform_result(rows)
|
||||
if not exclude_fields:
|
||||
return transformed
|
||||
excluded_fields = set(exclude_fields)
|
||||
excluded_fields.update(CamelCaseUtil.snake_to_camel(field) for field in exclude_fields)
|
||||
return cls._remove_excluded_fields(transformed, excluded_fields)
|
||||
|
||||
@classmethod
|
||||
def get_page_obj(cls, data_list: list, page_num: int, page_size: int) -> PageModel:
|
||||
"""
|
||||
@@ -39,7 +60,14 @@ class PageUtil:
|
||||
|
||||
@classmethod
|
||||
async def paginate(
|
||||
cls, db: AsyncSession, query: Select, page_num: int, page_size: int, is_page: bool = False
|
||||
cls,
|
||||
db: AsyncSession,
|
||||
query: Select,
|
||||
page_num: int,
|
||||
page_size: int,
|
||||
is_page: bool = False,
|
||||
*,
|
||||
exclude_fields: set[str] | None = None,
|
||||
) -> PageModel | list[dict[str, Any] | list[dict[Any, Any]]]:
|
||||
"""
|
||||
输入查询语句和分页信息,返回分页数据列表结果
|
||||
@@ -62,7 +90,7 @@ class PageUtil:
|
||||
paginated_data.append(row)
|
||||
has_next = math.ceil(total / page_size) > page_num
|
||||
result = PageModel[Any](
|
||||
rows=CamelCaseUtil.transform_result(paginated_data),
|
||||
rows=cls._transform_rows(paginated_data, exclude_fields),
|
||||
pageNum=page_num,
|
||||
pageSize=page_size,
|
||||
total=total,
|
||||
@@ -76,7 +104,7 @@ class PageUtil:
|
||||
no_paginated_data.append(row[0])
|
||||
else:
|
||||
no_paginated_data.append(row)
|
||||
result = CamelCaseUtil.transform_result(no_paginated_data)
|
||||
result = cls._transform_rows(no_paginated_data, exclude_fields)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user