| | |
| | | from sqlalchemy.testing.pickleable import Order |
| | | |
| | | from app.config.config import settings |
| | | from app.models.group_model import GroupModel |
| | | from app.models.user_model import UserModel |
| | | from app.service.ragflow import RagflowService |
| | | from app.service.token import get_ragflow_token |
| | | from app.Log import logger |
| | | from Log import logger |
| | | |
| | | |
| | | async def group_list(db, page_size: int, page_index: int, keyword: str): |
| | | async def group_list(db, page_size: int, page_index: int, keyword: str, role_key:str, user_id): |
| | | logger.info("-------------------------group_list----------------------------------") |
| | | query = db.query(GroupModel) |
| | | if role_key != "admin": |
| | | query.filter(GroupModel.creator==user_id) |
| | | if keyword: |
| | | query = query.filter(GroupModel.group_name.like('%{}%'.format(keyword))) |
| | | items = query.order_by(GroupModel.id.desc()).limit(page_size).offset( |
| | | (page_index - 1) * page_size).all() |
| | | # items_list = [item.to_dict() for item in items] |
| | | # groups = [i["id"] for i in items_list] |
| | | # group_dict = {} |
| | | # for group_user in db.query(GroupModel.group_id, UserModel.id, UserModel.username).outerjoin(UserModel, |
| | | # UserModel.id == UserGroupModel.user_id).filter( |
| | | # GroupModel.group_id.in_(groups)).all(): |
| | | # if group_user.group_id in group_dict: |
| | | # group_dict[group_user.group_id].append({"user_id": group_user.id, "user_name": group_user.username}) |
| | | # else: |
| | | # group_dict[group_user.group_id] = [{"user_id": group_user.id, "user_name": group_user.username}] |
| | | # for item in items_list: |
| | | # item["users"] = group_dict.get(item["id"], []) |
| | | |
| | | return {"total": query.count(), "items": [item.to_json() for item in items]} |
| | | |
| | | |
| | | async def create_group(db, group_name: str, group_description: str): |
| | | async def create_group(db, group_name: str, group_description: str, user_id): |
| | | try: |
| | | group_model = GroupModel(group_name=group_name, group_description=group_description) |
| | | group_model = GroupModel(group_name=group_name, group_description=group_description, creator=user_id) |
| | | db.add(group_model) |
| | | db.commit() |
| | | db.refresh(group_model) |