|
@@ -124,11 +124,18 @@ public class ExamServiceImpl implements ExamService {
|
|
|
|
|
|
@Override
|
|
|
public List<String> startExam(Exam exam, User user) {
|
|
|
- ExamHistory examHistory = new ExamHistory();
|
|
|
- examHistory.setExamId(exam.getId());
|
|
|
- examHistory.setStartTime(LocalDateTime.now(CHINA_ZONE));
|
|
|
- examHistory.setUserId(user.getUserName());
|
|
|
- examHistoryRepository.insert(examHistory);
|
|
|
+ ExamHistory examHistoryInDb = examHistoryRepository.findByUserIdAndExamId(user.getUserName(), exam.getId());
|
|
|
+ if (examHistoryInDb != null) {
|
|
|
+ if (examHistoryInDb.getEndTime() != null) {
|
|
|
+ return null; // exam has been finished.
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ExamHistory examHistory = new ExamHistory();
|
|
|
+ examHistory.setExamId(exam.getId());
|
|
|
+ examHistory.setStartTime(LocalDateTime.now(CHINA_ZONE));
|
|
|
+ examHistory.setUserId(user.getUserName());
|
|
|
+ examHistoryRepository.insert(examHistory);
|
|
|
+ }
|
|
|
return examToQuestionRepository
|
|
|
.findAllByExamId(exam.getId()).stream()
|
|
|
.map(x -> x.getQuestionId())
|