指令由 {"action": "process"} 改为 '合并Excel文件'
收到的数据格式与报告生成返回一致
1个文件已修改
28 ■■■■■ 已修改文件
app/api/excel.py 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/api/excel.py
@@ -71,26 +71,34 @@
async def ws_excel(websocket: WebSocket):
    await websocket.accept()
    while True:
        data = await websocket.receive_json()
        action = data.get("action")
        data = await websocket.receive_text()
        try:
            if action == "process":
            if data == "合并Excel文件":
                clear_directory(EXCEL_FILES_PATH)
                output_file_path = run_conformity()
                await websocket.send_json({"step_message": "开始合并"})
            elif action == "inquire":
                await websocket.send_json({"step_message": "开始合并", "type": "stream", "files": []})
            elif data == "查询合并进度":
                files = os.listdir(EXCEL_FILES_PATH)
                if not files:
                    await websocket.send_json({"step_message": "正在合并中"})
                    await websocket.send_json({"step_message": "正在合并中", "type": "stream", "files": []})
                else:
                    await websocket.send_json({"step_message": "文档合并成功!"})
            elif action == "download":
                    await websocket.send_json({"step_message": "文档合并成功!", "type": "stream", "files": []})
            elif data == "获取文件":
                files = os.listdir(EXCEL_FILES_PATH)
                if not files:
                    await websocket.send_json({"error": "目录下没有生成的文件"})
                    await websocket.send_json({"error": "目录下没有生成的文件", "type": "stream", "files": []})
                else:
                    first_file = files[0]
                    await websocket.send_json({"step_message": "合并文件已生成", "download_url": f"/download/{first_file}"})
                    file_name = os.path.basename(first_file)
                    file_url = f"./api/document/download/{first_file}"
                    await websocket.send_json({
                        "step_message": "文档合并成功!",
                        "type": "stream",
                        "files": [{
                            "file_name": file_name,
                            "file_url": file_url
                        }]
                    })
            else:
                await websocket.send_json({"error": "未知指令"})
        except Exception as e: