Skip to content

Commit 26664e1

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 080d4e0 + 0c91240 commit 26664e1

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

backend/apps/system/api/user.py

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
from fastapi import APIRouter
1+
from typing import Optional
2+
from fastapi import APIRouter, Query
3+
from sqlmodel import func, or_, select
24
from apps.system.crud.user import get_db_user, user_ws_options
5+
from apps.system.models.system_model import UserWsModel, WorkspaceModel
36
from apps.system.models.user import UserModel
47
from apps.system.schemas.auth import CacheName, CacheNamespace
58
from apps.system.schemas.system_schema import PwdEditor, UserCreator, UserEditor, UserGrid, UserLanguage, UserWs
@@ -18,13 +21,54 @@ async def user_info(current_user: CurrentUser):
1821
async def pager(
1922
session: SessionDep,
2023
pageNum: int,
21-
pageSize: int
24+
pageSize: int,
25+
keyword: Optional[str] = Query(None, description="搜索关键字(可选)"),
26+
status: Optional[int] = Query(None, description="状态"),
27+
origins: Optional[list[int]] = Query(None, description="来源"),
28+
oidlist: Optional[list[int]] = Query(None, description="空间ID集合(可选)"),
2229
):
2330
pagination = PaginationParams(page=pageNum, size=pageSize)
2431
paginator = Paginator(session)
2532
filters = {}
33+
34+
stmt = (
35+
select(
36+
UserModel,
37+
func.coalesce(func.string_agg(WorkspaceModel.name, ','), '').label("space_name")
38+
)
39+
.join(UserWsModel, UserModel.id == UserWsModel.uid, isouter=True)
40+
.join(WorkspaceModel, UserWsModel.oid == WorkspaceModel.id, isouter=True)
41+
.group_by(UserModel.id)
42+
.order_by(UserModel.create_time)
43+
)
44+
45+
if status is not None:
46+
stmt = stmt.where(UserModel.status == status)
47+
48+
if oidlist:
49+
user_filter = (
50+
select(UserModel.id)
51+
.join(UserWsModel, UserModel.id == UserWsModel.uid)
52+
.where(UserWsModel.oid.in_(oidlist))
53+
.distinct()
54+
)
55+
stmt = stmt.where(UserModel.id.in_(user_filter))
56+
57+
""" if origins is not None:
58+
stmt = stmt.where(UserModel.origin == origins) """
59+
60+
if keyword:
61+
keyword_pattern = f"%{keyword}%"
62+
stmt = stmt.where(
63+
or_(
64+
UserModel.account.ilike(keyword_pattern),
65+
UserModel.name.ilike(keyword_pattern),
66+
UserModel.email.ilike(keyword_pattern)
67+
)
68+
)
69+
2670
return await paginator.get_paginated_response(
27-
stmt=UserModel,
71+
stmt=stmt,
2872
pagination=pagination,
2973
**filters)
3074

backend/apps/system/crud/user.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ async def user_ws_options(session: Session, uid: int, trans: Optional[I18n] = No
4444
if uid == 1:
4545
stmt = select(WorkspaceModel.id, WorkspaceModel.name).order_by(WorkspaceModel.create_time)
4646
else:
47-
stmt = select(UserWsModel.oid, WorkspaceModel.name).join(
48-
WorkspaceModel, UserWsModel.oid == WorkspaceModel.id
47+
stmt = select(WorkspaceModel.id, WorkspaceModel.name).join(
48+
UserWsModel, UserWsModel.oid == WorkspaceModel.id
4949
).where(
5050
UserWsModel.uid == uid,
5151
).order_by(WorkspaceModel.create_time)

backend/apps/system/schemas/system_schema.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class UserEditor(UserCreator, BaseCreatorDTO):
3737
class UserGrid(UserEditor):
3838
create_time: int
3939
language: str = "zh-CN"
40+
space_name: Optional[str] = None
41+
origin: str = ''
42+
4043

4144
class PwdEditor(BaseModel):
4245
pwd: str

backend/common/core/sqlbot_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ async def wrapper(*args, **kwargs):
168168
)
169169

170170
logger.debug(f"Clearing cache for key: {cache_key}")
171-
172171
# 2. 清除缓存
173-
await FastAPICache.clear(key=cache_key)
172+
if await FastAPICache.get_backend().get(cache_key):
173+
await FastAPICache.clear(key=cache_key)
174174

175175
# 3. 执行原函数
176176
return await func(*args, **kwargs)

0 commit comments

Comments
 (0)