Skip to content

Commit beeddb6

Browse files
committed
refactor: system variable sort by create time
1 parent bd7ce47 commit beeddb6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

backend/apps/system/crud/system_variable.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Author: Junjun
22
# Date: 2026/1/26
33
import datetime
4-
54
from typing import List
5+
66
from fastapi import HTTPException
77
from sqlalchemy import and_
88
from sqlmodel import select
@@ -37,11 +37,12 @@ def delete(session: SessionDep, ids: List[int]):
3737

3838
def list_all(session: SessionDep, trans: Trans, variable: SystemVariable):
3939
if variable.name is None:
40-
records = session.query(SystemVariable).order_by(SystemVariable.type.desc()).all()
40+
records = session.query(SystemVariable).order_by(SystemVariable.type.desc(),
41+
SystemVariable.create_time.desc()).all()
4142
else:
4243
records = session.query(SystemVariable).filter(
4344
and_(SystemVariable.name.like(f'%{variable.name}%'), SystemVariable.type != 'system')).order_by(
44-
SystemVariable.type.desc()).all()
45+
SystemVariable.type.desc(), SystemVariable.create_time.desc()).all()
4546

4647
res = []
4748
for r in records:
@@ -58,11 +59,11 @@ async def list_page(session: SessionDep, trans: Trans, pageNum: int, pageSize: i
5859
filters = {}
5960

6061
if variable.name is None:
61-
stmt = select(SystemVariable).order_by(SystemVariable.type.desc())
62+
stmt = select(SystemVariable).order_by(SystemVariable.type.desc(), SystemVariable.create_time.desc())
6263
else:
6364
stmt = select(SystemVariable).where(
6465
and_(SystemVariable.name.like(f'%{variable.name}%'), SystemVariable.type != 'system')).order_by(
65-
SystemVariable.type.desc())
66+
SystemVariable.type.desc(), SystemVariable.create_time.desc())
6667

6768
variable_page = await paginator.get_paginated_response(
6869
stmt=stmt,
@@ -92,7 +93,7 @@ def checkName(session: SessionDep, trans: Trans, variable: SystemVariable):
9293
raise HTTPException(status_code=500, detail=trans('i18n_variable.name_exist'))
9394

9495

95-
def checkValue(session: SessionDep, trans: Trans, values:List):
96+
def checkValue(session: SessionDep, trans: Trans, values: List):
9697
# values: [{"variableId":1,"variableValues":["a","b"]}]
9798

98-
pass
99+
pass

0 commit comments

Comments
 (0)