|
|
@@ -1,16 +1,26 @@
|
|
|
package com.seec.bok.web.controller;
|
|
|
|
|
|
|
|
|
+import com.seec.bok.back.entity.Question;
|
|
|
import com.seec.bok.back.entity.Record;
|
|
|
+import com.seec.bok.service.QuestionService;
|
|
|
import com.seec.bok.service.RecordService;
|
|
|
+import com.seec.bok.web.dto.PageDTO;
|
|
|
import com.seec.bok.web.dto.RecordDTO;
|
|
|
import com.seec.bok.web.util.FakeRecordData;
|
|
|
+import com.seec.bok.web.vo.PageVO;
|
|
|
+import com.seec.bok.web.vo.PageableQuestionListVO;
|
|
|
+import com.seec.bok.web.vo.QuestionVO;
|
|
|
import com.seec.bok.web.vo.RecordVO;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -24,6 +34,8 @@ import java.util.stream.Collectors;
|
|
|
public class RecordController {
|
|
|
@Autowired
|
|
|
private RecordService recordService;
|
|
|
+ @Autowired
|
|
|
+ private QuestionService questionService;
|
|
|
@PostMapping("")
|
|
|
@Operation(description = "新增用户的做题记录")
|
|
|
public List<RecordVO> createUserRecord(@RequestBody List<RecordDTO> records) {
|
|
|
@@ -33,14 +45,44 @@ public class RecordController {
|
|
|
|
|
|
@GetMapping("")
|
|
|
@Operation(description = "获得用户做题记录")
|
|
|
- public List<RecordVO> getUserRecord(
|
|
|
+ public Page<RecordVO> getUserRecord(
|
|
|
@RequestParam(value = "userId", required = false) @Parameter(description = "用户id")
|
|
|
List<String> userIdList,
|
|
|
@RequestParam(value = "questionId", required = false) @Parameter(description = "题目id")
|
|
|
List<String> questionIdList,
|
|
|
@RequestParam(value = "recordId", required = false) @Parameter(description = "记录id")
|
|
|
- List<String> recordIdList) {
|
|
|
- final List<Record> records1 =recordService.findRecordByUidAndQidAndRidIn(userIdList,questionIdList,recordIdList);
|
|
|
- return records1.stream().map(RecordVO::fromEntity).collect(Collectors.toList());
|
|
|
+ List<String> recordIdList,
|
|
|
+ PageDTO pageDTO) {
|
|
|
+ final Page<Record> records1 =recordService.findRecordByUidAndQidAndRidIn(userIdList,questionIdList,recordIdList,PageDTO.of(pageDTO));
|
|
|
+ return records1.map(RecordVO::fromEntity);
|
|
|
+ }
|
|
|
+ @GetMapping("/{userId}/question")
|
|
|
+ @Operation(description = "获得某用户做的题目以及数据")
|
|
|
+ public HashMap getUserRecordQuestions(
|
|
|
+ @PathVariable String userId,
|
|
|
+ PageDTO pageDTO
|
|
|
+ ) {
|
|
|
+ HashMap<String,Object> body=new HashMap<>();
|
|
|
+
|
|
|
+ Page<Record> recordPage=recordService.getUserRecordQuestions(userId,PageDTO.of(pageDTO));
|
|
|
+ List<String> ids = recordPage.getContent().stream()
|
|
|
+ .map(Record::getQuestionId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ final List<QuestionVO> questionVOS = questionService.findAllByIdIn(ids).stream()
|
|
|
+ .map(QuestionVO::of)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ final List<RecordVO> recordVOS=recordPage.getContent().stream()
|
|
|
+ .map(RecordVO::fromEntity)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ final PageVO page=PageVO.builder()
|
|
|
+ .size(recordPage.getSize())
|
|
|
+ .totalPages(recordPage.getTotalPages())
|
|
|
+ .totalElements(recordPage.getTotalElements())
|
|
|
+ .number(recordPage.getNumber())
|
|
|
+ .build();
|
|
|
+ body.put("page",page);
|
|
|
+ body.put("questions",questionVOS);
|
|
|
+ body.put("records",recordVOS);
|
|
|
+ return body;
|
|
|
}
|
|
|
}
|