ChatController.java 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package com.backendsys.modules.ai.chat.controller;
  2. import com.backendsys.modules.ai.chat.entity.Chat;
  3. import com.backendsys.modules.ai.chat.service.ChatService;
  4. import com.backendsys.modules.common.utils.Result;
  5. import io.swagger.v3.oas.annotations.Operation;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.security.access.prepost.PreAuthorize;
  8. import org.springframework.validation.annotation.Validated;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RestController;
  13. @Validated
  14. @RestController
  15. public class ChatController {
  16. @Autowired
  17. private ChatService chatService;
  18. @Operation(summary = "发起对话")
  19. @PreAuthorize("@sr.hasPermission('31')")
  20. @PostMapping("/api/ai/chat/sendChat")
  21. public Result sendChat(@Validated(Chat.Create.class) @RequestBody Chat chat) {
  22. return Result.success().put("data", chatService.sendChat(chat));
  23. }
  24. @Operation(summary = "获取我的对话")
  25. @PreAuthorize("@sr.hasPermission('31')")
  26. @GetMapping("/api/ai/chat/getChatList")
  27. public Result getChatList(@Validated(Chat.Detail.class) Chat chat) {
  28. return Result.success().put("data", chatService.selectChatList(chat.getHistory_code()));
  29. }
  30. }