sessionController.java 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package com.stellvoy.customer.controller;
  2. import com.stellvoy.api.client.user.UserClient;
  3. import com.stellvoy.api.dto.user.NewUserDTO;
  4. import com.stellvoy.customer.entity.sessionEntity;
  5. import com.stellvoy.customer.service.sessionService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.http.ResponseEntity;
  8. import org.springframework.web.bind.annotation.*;
  9. import java.util.HashMap;
  10. import java.util.List;
  11. import java.util.Map;
  12. @RestController
  13. @RequestMapping("/customer/session")
  14. public class sessionController {
  15. @Autowired
  16. private sessionService sessionService;
  17. @Autowired
  18. private UserClient userClient;
  19. /**
  20. * 根据用户ID获取会话信息。
  21. *
  22. * @param userId 用户ID
  23. * @return 包含会话信息和消息的Map
  24. */
  25. @GetMapping("/getSessionsWithMessages/{userId}")
  26. public Map<String, Object> getSessionsWithMessages(@PathVariable Long userId) {
  27. if (userId == null) {
  28. Map<String, Object> response = new HashMap<>();
  29. response.put("error", "用户ID不能为空");
  30. return response;
  31. }
  32. NewUserDTO user = userClient.queryUserById(userId);
  33. if (user == null) {
  34. throw new IllegalArgumentException("用户不存在");
  35. }
  36. String userName = user.getUsername();
  37. return sessionService.getSessionByUserId(userId, userName);
  38. }
  39. @PostMapping("/byUserId/{userId}")
  40. public ResponseEntity<List<sessionEntity>> getAnswerByQuestion(
  41. @PathVariable Long userId,
  42. @RequestParam("filePath") String filePath,
  43. @RequestParam("fileType") Long fileType,
  44. @RequestParam("fileName") String fileName
  45. ) {
  46. List<sessionEntity> result = sessionService.getFileByUserId(userId, filePath, fileType,fileName);
  47. return ResponseEntity.ok(result);
  48. }
  49. }