| | |
| | | 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: |