|
|
@@ -3,11 +3,14 @@ package com.etotem.num.controller;
|
|
|
import com.etotem.num.common.Result;
|
|
|
import com.etotem.num.entity.ChatMessage;
|
|
|
import com.etotem.num.service.ChatService;
|
|
|
+import com.etotem.num.service.UploadService;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
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.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
@@ -18,9 +21,11 @@ import java.util.Map;
|
|
|
public class ChatController {
|
|
|
|
|
|
private final ChatService chatService;
|
|
|
+ private final UploadService uploadService;
|
|
|
|
|
|
- public ChatController(ChatService chatService) {
|
|
|
+ public ChatController(ChatService chatService, UploadService uploadService) {
|
|
|
this.chatService = chatService;
|
|
|
+ this.uploadService = uploadService;
|
|
|
}
|
|
|
|
|
|
@PostMapping("/send")
|
|
|
@@ -29,8 +34,9 @@ public class ChatController {
|
|
|
Long userId = (Long) request.getAttribute("userId");
|
|
|
Long chartRecordId = ((Number) body.get("chartRecordId")).longValue();
|
|
|
String query = (String) body.get("query");
|
|
|
+ String audioUrl = (String) body.get("audioUrl");
|
|
|
|
|
|
- String reply = chatService.sendMessage(userId, chartRecordId, query);
|
|
|
+ String reply = chatService.sendMessage(userId, chartRecordId, query, audioUrl);
|
|
|
return Result.success(Collections.singletonMap("reply", reply));
|
|
|
}
|
|
|
|
|
|
@@ -39,4 +45,13 @@ public class ChatController {
|
|
|
Long chartRecordId = body.get("chartRecordId");
|
|
|
return Result.success(chatService.getHistory(chartRecordId));
|
|
|
}
|
|
|
+
|
|
|
+ @PostMapping("/voice")
|
|
|
+ public Result<Map<String, String>> uploadVoice(HttpServletRequest request,
|
|
|
+ @RequestParam("file") MultipartFile file,
|
|
|
+ @RequestParam("chartRecordId") Long chartRecordId) {
|
|
|
+ Long userId = (Long) request.getAttribute("userId");
|
|
|
+ String url = uploadService.storeAudio(file, userId);
|
|
|
+ return Result.success(Collections.singletonMap("url", url));
|
|
|
+ }
|
|
|
}
|