From 966f9e7367684f93349a347c9dbd69c763d3ae7b Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期三, 08 一月 2025 14:24:40 +0800 Subject: [PATCH] 出错时返回错误信息 --- app/service/knowledge.py | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/app/service/knowledge.py b/app/service/knowledge.py index e69de29..043db0f 100644 --- a/app/service/knowledge.py +++ b/app/service/knowledge.py @@ -0,0 +1,26 @@ +from app.models import KnowledgeModel, group_knowledge_table +from app.models.user_model import UserModel +from Log import logger + + +async def get_knowledge_list(db, user_id, page_size, page_index): + user = db.query(UserModel).filter(UserModel.id == user_id).first() + if user is None: + return {"rows": []} + if user.permission == "admin": + query = db.query(KnowledgeModel) + else: + group_list = [i.id for i in user.groups] + query = db.query(KnowledgeModel) + query = query.filter(KnowledgeModel.tenant_id == user_id) + query = query.union( + db.query(KnowledgeModel).join( + group_knowledge_table, + KnowledgeModel.id == group_knowledge_table.c.knowledge_id + ).filter( + group_knowledge_table.c.group_id.in_(group_list) + ) + ) + if page_size: + query = query.limit(page_size).offset((page_index - 1) * page_size) + return {"rows": [kld.to_json() for kld in query.all()]} -- Gitblit v1.8.0