From 8e85ef5796e901a4860ab0d39961e9b343fd30e0 Mon Sep 17 00:00:00 2001
From: zhangxiao <898441624@qq.com>
Date: 星期三, 23 十月 2024 10:48:18 +0800
Subject: [PATCH] 指令由 {"action": "process"} 改为 '合并Excel文件' 收到的数据格式与报告生成返回一致

---
 app/api/excel.py |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/app/api/excel.py b/app/api/excel.py
index 4110527..f056617 100644
--- a/app/api/excel.py
+++ b/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": "姝e湪鍚堝苟涓�"})
+                    await websocket.send_json({"step_message": "姝e湪鍚堝苟涓�", "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:

--
Gitblit v1.8.0