|
@@ -10,7 +10,7 @@ from typing import Any, Optional
|
|
|
|
|
|
from flask_login import current_user # type: ignore
|
|
from flask_login import current_user # type: ignore
|
|
from sqlalchemy import func, literal, text
|
|
from sqlalchemy import func, literal, text
|
|
-from sqlalchemy.orm import Session
|
|
|
|
|
|
+from sqlalchemy.orm import Session, aliased
|
|
from werkzeug.exceptions import NotFound
|
|
from werkzeug.exceptions import NotFound
|
|
|
|
|
|
from configs import dify_config
|
|
from configs import dify_config
|
|
@@ -833,12 +833,17 @@ class DatasetService:
|
|
|
|
|
|
# 添加创建人部门过滤
|
|
# 添加创建人部门过滤
|
|
if creator_dept:
|
|
if creator_dept:
|
|
- union_query = union_query.join(Account, Dataset.created_by == Account.id)
|
|
|
|
- union_query = union_query.filter(Account.dept_id == literal(str(creator_dept)))
|
|
|
|
|
|
+ from sqlalchemy.orm import aliased
|
|
|
|
+ CreatorAccount = aliased(Account)
|
|
|
|
+ union_query = union_query.join(CreatorAccount, Dataset.created_by == CreatorAccount.id)
|
|
|
|
+ union_query = union_query.filter(CreatorAccount.dept_id == literal(str(creator_dept)))
|
|
|
|
|
|
# 添加创建人过滤
|
|
# 添加创建人过滤
|
|
if creator:
|
|
if creator:
|
|
- union_query = union_query.filter(Dataset.created_by == creator)
|
|
|
|
|
|
+ from sqlalchemy.orm import aliased
|
|
|
|
+ CreatorAccount = aliased(Account)
|
|
|
|
+ union_query = union_query.join(CreatorAccount, Dataset.created_by == CreatorAccount.id)
|
|
|
|
+ union_query = union_query.filter(CreatorAccount.name.ilike(f"%{creator}%"))
|
|
|
|
|
|
# 其它过滤
|
|
# 其它过滤
|
|
if search:
|
|
if search:
|
|
@@ -857,7 +862,7 @@ class DatasetService:
|
|
union_query = union_query.filter(Dataset.id.in_(target_ids_by_category_ids))
|
|
union_query = union_query.filter(Dataset.id.in_(target_ids_by_category_ids))
|
|
else:
|
|
else:
|
|
return [], 0
|
|
return [], 0
|
|
-
|
|
|
|
|
|
+ print(str(union_query))
|
|
datasets = union_query.order_by(Dataset.created_at.desc()).paginate(
|
|
datasets = union_query.order_by(Dataset.created_at.desc()).paginate(
|
|
page=page, per_page=per_page, max_per_page=100, error_out=False
|
|
page=page, per_page=per_page, max_per_page=100, error_out=False
|
|
)
|
|
)
|