Merge branch 'master' of http://192.168.5.5:10010/r/rag-gateway
| | |
| | | from fastapi import APIRouter, File, UploadFile, Depends |
| | | from fastapi import APIRouter, File, UploadFile |
| | | from fastapi.responses import JSONResponse, FileResponse |
| | | from fastapi.exceptions import HTTPException |
| | | from sqlalchemy.orm import Session |
| | | from starlette.websockets import WebSocket, WebSocketDisconnect |
| | | from werkzeug.utils import secure_filename |
| | | from app.api import get_current_user_websocket |
| | | from app.models.agent_model import AgentModel, AgentType |
| | | from app.models.base_model import get_db |
| | | from app.models.user_model import UserModel |
| | | from starlette.websockets import WebSocket |
| | | from app.utils.excelmerge.conformity import run_conformity |
| | | import shutil |
| | | import os |
| | |
| | | ALLOWED_EXTENSIONS = {'xlsx'} |
| | | EXCEL_FILES_PATH = 'data/output' |
| | | SOURCE_FILES_PATH = 'data/source' |
| | | |
| | | |
| | | def allowed_file(filename): |
| | | return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS |
| | |
| | | data = await websocket.receive_text() |
| | | try: |
| | | if data == "\"合并Excel\"": |
| | | output_file_path = run_conformity() |
| | | output_file_path = run_conformity() |
| | | run_excel = run_conformity() |
| | | files = os.listdir(EXCEL_FILES_PATH) |
| | | if files: |
| | | if run_excel: |
| | | first_file = files[0] |
| | | file_name = os.path.basename(first_file) |
| | | file_url = f"./api/document/download/{first_file}" |
| | | download_url = f"./api/document/download/{first_file}" |
| | | await websocket.send_json({ |
| | | "message": "文档合并成功!", |
| | | "type": "stream", |
| | | "files": [{ |
| | | "file_name": file_name, |
| | | "file_url": file_url |
| | | "file_url": download_url |
| | | }] |
| | | }) |
| | | await websocket.send_json({ |
| | |
| | | "type": "close", |
| | | }) |
| | | else: |
| | | await websocket.send_json({"error": "合并操作未生成文件", "type": "stream", "files": []}) |
| | | await websocket.send_json({"error": "合并失败", "type": "stream", "files": []}) |
| | | elif data == "\"查询合并进度\"": |
| | | files = os.listdir(EXCEL_FILES_PATH) |
| | | if not files: |
| | |
| | | register_dict = {} |
| | | token = "" |
| | | app_password = await generate_password(10) |
| | | crypt_password = UserAppModel.encrypted_password(app_password) |
| | | for app in app_register: |
| | | if app["id"] == 'ragflow_app': |
| | | user_rag_app = db.query(UserAppModel).filter(UserAppModel.user_id == userid, |
| | |
| | | app_name = register_info.get("name") |
| | | app_id = register_info.get("id") |
| | | app_email = register_info.get("email") |
| | | await save_db(db, app_name, user.password, app_email, user.id, app_id, "ragflow_app") |
| | | await save_db(db, app_name, crypt_password, app_email, user.id, app_id, "ragflow_app") |
| | | elif app["id"] == 'bisheng_app': |
| | | user_bs_app = db.query(UserAppModel).filter(UserAppModel.user_id == userid, |
| | | UserAppModel.app_type == 'bisheng_app').all() |
| | |
| | | app_name = register_info.get("name") |
| | | app_id = register_info.get("id") |
| | | app_email = register_info.get("email") |
| | | await save_db(db, app_name, user.password, app_email, user.id, app_id, "bisheng_app") |
| | | await save_db(db, app_name, crypt_password, app_email, user.id, app_id, "bisheng_app") |
| | | elif app["id"] == 'dify_app': |
| | | user_df_app = db.query(UserAppModel).filter(UserAppModel.user_id == userid, |
| | | UserAppModel.app_type == 'dify_app').all() |
| | |
| | | app_name = register_info.get("name") |
| | | app_id = register_info.get("id") |
| | | app_email = register_info.get("email") |
| | | df_password = await generate_password(10) |
| | | password = cipher_suite.encrypt(df_password.encode("utf-8")).decode("utf-8") |
| | | await save_db(db, app_name, password, app_email, user.id, app_id, "dify_app") |
| | | await save_db(db, app_name, crypt_password, app_email, user.id, app_id, "dify_app") |
| | | else: |
| | | raise Exception("未知注册应用---") |
| | | |
| | |
| | | from openpyxl import load_workbook |
| | | from openpyxl.utils import get_column_letter |
| | | from datetime import datetime |
| | | import os |
| | | |
| | | |
| | | def run_conformity(): |
| | | try: |
| | | # 加载模板文件 |
| | | template_path = os.path.join('app', 'utils', 'excelmerge', '国网上海电力整合模版.xlsx') |
| | | template_excel = load_workbook(template_path) |
| | |
| | | a_cell_value = ssheet.cell(row=row, column=1).value |
| | | if isinstance(a_cell_value, (int, float)) and any( |
| | | ssheet.cell(row=row, column=col).value for col in range(2, ssheet.max_column + 1)): |
| | | tsheet.append([ssheet.cell(row=row, column=col).value for col in range(1, ssheet.max_column + 1)]) |
| | | tsheet.append( |
| | | [ssheet.cell(row=row, column=col).value for col in range(1, ssheet.max_column + 1)]) |
| | | |
| | | source_excel.close() |
| | | |
| | |
| | | template_excel.save(output_path) |
| | | template_excel.close() |
| | | |
| | | return timestamp |
| | | return True |
| | | except Exception as e: |
| | | print(f"读取数据发生错误: {e}") |
| | | return False |