From 4eb46966002c6ca24cbb8cc8b519a05610e81649 Mon Sep 17 00:00:00 2001
From: admin <cgf12138@163.com>
Date: 星期一, 09 六月 2025 11:17:24 +0800
Subject: [PATCH] 0606

---
 aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/controller/AiBotController.java |   35 +++++++++++++++++++----------------
 1 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/controller/AiBotController.java b/aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/controller/AiBotController.java
index d5543f2..ed66287 100644
--- a/aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/controller/AiBotController.java
+++ b/aiflowy-modules/aiflowy-module-ai/src/main/java/tech/aiflowy/ai/controller/AiBotController.java
@@ -28,13 +28,11 @@
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.*;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
 import tech.aiflowy.ai.config.DifyStreamClient;
 import tech.aiflowy.ai.config.FileReference;
@@ -55,6 +53,7 @@
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.File;
 import java.math.BigInteger;
 import java.util.*;
 
@@ -141,13 +140,22 @@
     @Autowired
     private ObjectMapper objectMapper;
 
+//    @PostMapping("chat")
+//    public SseEmitter chat2(@JsonBody(value = "prompt", required = true) String prompt,
+//                           @JsonBody(value = "botId", required = true) BigInteger botId,
+//                           @JsonBody(value = "sessionId", required = true) String sessionId,
+//                           @JsonBody(value = "isExternalMsg") int isExternalMsg,
+//                           @JsonBody("file") String file,//涓婁紶鏂囦欢
+//                           HttpServletResponse response){
+//        File file =
+//    }
 
     @PostMapping("chat")
     public SseEmitter chat(@JsonBody(value = "prompt", required = true) String prompt,
                            @JsonBody(value = "botId", required = true) BigInteger botId,
                            @JsonBody(value = "sessionId", required = true) String sessionId,
                            @JsonBody(value = "isExternalMsg") int isExternalMsg,
-                           @JsonBody(value = "file") String file,
+                           @JsonBody(value = "file") String file,//涓婁紶鏂囦欢
                            HttpServletResponse response) {
         response.setContentType("text/event-stream");
         AiBot aiBot = service.getById(botId);
@@ -165,17 +173,12 @@
 
                 DifyStreamClient client = new DifyStreamClient(apiUrl, apiKey, aiBotMessageService);
                 DifyStreamClient uploadClient = new DifyStreamClient(aiBot.getModelAPI()+"/files/upload", apiKey, aiBotMessageService);
-                String test = uploadClient.fileUpload(SaTokenUtil.getLoginAccount().getId() + "", file);
-                System.out.println(test);
-                Gson gson = new GsonBuilder().setPrettyPrinting().create();
-                JsonObject fileJson = gson.fromJson(test, JsonObject.class);
-                String fileId = fileJson.get("id").getAsString();
+                String fileId = file;
 
                 // 2. 鏋勫缓鏂囦欢鍙傛暟瀵硅薄
                 Map<String, Object> fileParam = new HashMap<>();
                 fileParam.put("transfer_method", "local_file");
                 fileParam.put("upload_file_id", fileId);
-                String[] split = file.split("\\.");
 //                fileParam.put("type", fileJson.get("extension").getAsString()); // 渚嬪 "excel"銆�"pdf" 绛�
                 fileParam.put("type", "document"); // 渚嬪 "excel"銆�"pdf" 绛�
 
@@ -363,8 +366,8 @@
     }
 
     @PostMapping("files/upload")
-    public Result filesUpload(@JsonBody(value = "botId", required = true) BigInteger botId,
-                           String file,
+    public Result filesUpload(@RequestParam("botId") BigInteger botId,
+                              @RequestParam("file") MultipartFile file,
                            HttpServletResponse response){
         try{
             String userId = SaTokenUtil.getLoginAccount().getId() + "";
@@ -374,10 +377,10 @@
             String apiUrl = aiBot.getModelAPI(); // 鏇挎崲涓哄疄闄匒PI URL
             String apiKey = aiBot.getModelKEY(); // 鏇挎崲涓哄疄闄匒PI Key
             DifyStreamClient client = new DifyStreamClient(apiUrl, apiKey, aiBotMessageService);
-            client.fileUpload(userId,file);
-            return Result.success("鎴愬姛锛�");
+            String s = client.fileUpload(userId, file);
+            return Result.success(s);
         }catch (Exception e){
-            return Result.fail(400, String.valueOf(e));
+            return Result.fail(400,String.valueOf(e));
         }
     }
 

--
Gitblit v1.8.0