1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package com.stellvoy.customer.controller;
- import com.stellvoy.api.client.user.UserClient;
- import com.stellvoy.api.dto.user.NewUserDTO;
- import com.stellvoy.customer.entity.sessionEntity;
- import com.stellvoy.customer.service.sessionService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.ResponseEntity;
- import org.springframework.web.bind.annotation.*;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- @RestController
- @RequestMapping("/customer/session")
- public class sessionController {
- @Autowired
- private sessionService sessionService;
- @Autowired
- private UserClient userClient;
- /**
- * 根据用户ID获取会话信息。
- *
- * @param userId 用户ID
- * @return 包含会话信息和消息的Map
- */
- @GetMapping("/getSessionsWithMessages/{userId}")
- public Map<String, Object> getSessionsWithMessages(@PathVariable Long userId) {
- if (userId == null) {
- Map<String, Object> response = new HashMap<>();
- response.put("error", "用户ID不能为空");
- return response;
- }
- NewUserDTO user = userClient.queryUserById(userId);
- if (user == null) {
- throw new IllegalArgumentException("用户不存在");
- }
- String userName = user.getUsername();
- return sessionService.getSessionByUserId(userId, userName);
- }
- @PostMapping("/byUserId/{userId}")
- public ResponseEntity<List<sessionEntity>> getAnswerByQuestion(
- @PathVariable Long userId,
- @RequestParam("filePath") String filePath,
- @RequestParam("fileType") Long fileType,
- @RequestParam("fileName") String fileName
- ) {
- List<sessionEntity> result = sessionService.getFileByUserId(userId, filePath, fileType,fileName);
- return ResponseEntity.ok(result);
- }
- }
|