|
|
@@ -1,6 +1,8 @@
|
|
|
package com.nju.edu.eval.service.serviceImpl;
|
|
|
|
|
|
+import com.nju.edu.eval.data.dao.ExamDao;
|
|
|
import com.nju.edu.eval.data.dao.RecordDao;
|
|
|
+import com.nju.edu.eval.data.entity.Exam;
|
|
|
import com.nju.edu.eval.data.entity.QuestionRecord;
|
|
|
import com.nju.edu.eval.model.vo.record.QuestionRecordVO;
|
|
|
import com.nju.edu.eval.service.RecordService;
|
|
|
@@ -8,8 +10,10 @@ import com.nju.edu.eval.service.convertor.RecordConvertor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.stream.Collector;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -18,9 +22,13 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class RecordServiceImpl implements RecordService {
|
|
|
private final RecordDao recordDao;
|
|
|
+
|
|
|
+ private final ExamDao examDao;
|
|
|
+
|
|
|
@Autowired
|
|
|
- public RecordServiceImpl(RecordDao recordDao) {
|
|
|
+ public RecordServiceImpl(RecordDao recordDao, ExamDao examDao) {
|
|
|
this.recordDao = recordDao;
|
|
|
+ this.examDao = examDao;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -31,8 +39,18 @@ public class RecordServiceImpl implements RecordService {
|
|
|
|
|
|
@Override
|
|
|
public List<QuestionRecordVO> getQuestionRecordsOfExamByUserId(Integer userId, Integer examId){
|
|
|
- return recordDao.findAllByUserIdAndExamId(userId, examId)
|
|
|
- .stream().map(RecordConvertor::convertToVO).collect(Collectors.toList());
|
|
|
+ //获取到对应考试的所有题目信息
|
|
|
+ Map<String, Double> questionAndScore = Objects.requireNonNull(examDao.findById(examId).orElse(null)).getQuestionAndScore();
|
|
|
+ //questionRecords为按时间逆序排列的学生做题记录
|
|
|
+ List<QuestionRecord> questionRecords = recordDao.findAllByUserIdAndExamId(userId, examId);
|
|
|
+ List<QuestionRecord> filterRecords = new ArrayList<>();
|
|
|
+ for(QuestionRecord record:questionRecords){
|
|
|
+ filterRecords.add(record);
|
|
|
+ if(filterRecords.size()>=questionAndScore.size()){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return filterRecords.stream().map(RecordConvertor::convertToVO).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@Override
|