|
|
@@ -1,5 +1,7 @@
|
|
|
package cn.seecoder.judgement.service.impl;
|
|
|
|
|
|
+import cn.seecoder.bok.client.SeecoderBokClient;
|
|
|
+import cn.seecoder.bok.common.vo.RecordVO;
|
|
|
import cn.seecoder.judgement.dto.StudentAnswerDTO;
|
|
|
import cn.seecoder.judgement.service.JudgementService;
|
|
|
import cn.seecoder.judgement.service.QuestionService;
|
|
|
@@ -7,10 +9,7 @@ import cn.seecoder.judgement.vo.JudgedAnswersVO;
|
|
|
import cn.seecoder.judgement.vo.question.BaseQuestionVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
|
@@ -26,12 +25,21 @@ public class JudgementServiceImpl implements JudgementService {
|
|
|
}
|
|
|
@Override
|
|
|
public JudgedAnswersVO submitQuestionsStudentAnswer(StudentAnswerDTO studentAnswerDTO) {
|
|
|
+ System.out.println(new Date());
|
|
|
+ System.out.println("start judging, students'answers are:");
|
|
|
+ System.out.println(studentAnswerDTO);
|
|
|
+
|
|
|
+ String userId = studentAnswerDTO.getUserId();
|
|
|
Map<String, StudentAnswerDTO.AnswerRecordDTO> records = studentAnswerDTO.getRecords();
|
|
|
List<String> questionIds = new ArrayList<>(records.keySet());
|
|
|
List<BaseQuestionVO> questionVOList = questionService.getQuestionsByIds(questionIds);
|
|
|
+ System.out.println("questions from bok are as follows:");
|
|
|
+ System.out.println(questionVOList);
|
|
|
|
|
|
AtomicInteger correct = new AtomicInteger();
|
|
|
|
|
|
+ List<RecordVO> judgedAnswerRecords = new ArrayList<>();
|
|
|
+
|
|
|
Map<String, JudgedAnswersVO.QuestionStudentAnswerInfo> judgedAnswers = new HashMap<>();
|
|
|
questionVOList.forEach(baseQuestionVO -> {
|
|
|
String questionId = baseQuestionVO.getId();
|
|
|
@@ -41,8 +49,26 @@ public class JudgementServiceImpl implements JudgementService {
|
|
|
correct.getAndIncrement();
|
|
|
}
|
|
|
judgedAnswers.put(questionId, JudgedAnswersVO.QuestionStudentAnswerInfo.of(questionId, answer, isTrue));
|
|
|
+
|
|
|
+ //保存做题数据
|
|
|
+ StudentAnswerDTO.AnswerRecordDTO answerRecordDTO = records.get(questionId);
|
|
|
+ RecordVO record = new RecordVO();
|
|
|
+ record.setUserId(userId);
|
|
|
+ record.setQuestionId(questionId);
|
|
|
+ record.setPass(isTrue);
|
|
|
+ record.setStudentAnswer(String.valueOf(answer));
|
|
|
+ record.setStartAt(answerRecordDTO.getStartAt());
|
|
|
+ record.setFinishAt(answerRecordDTO.getEndAt());
|
|
|
+
|
|
|
+ judgedAnswerRecords.add(record);
|
|
|
});
|
|
|
+ JudgedAnswersVO res = new JudgedAnswersVO(judgedAnswers);
|
|
|
+
|
|
|
+ SeecoderBokClient seecoderBokClient = new SeecoderBokClient("http://bok.seecoder.cn", 0);
|
|
|
+ List<RecordVO> recordVOS = seecoderBokClient.createUserRecord(judgedAnswerRecords);
|
|
|
|
|
|
- return new JudgedAnswersVO(judgedAnswers);
|
|
|
+ System.out.println("results are as follows:");
|
|
|
+ System.out.println(res);
|
|
|
+ return res;
|
|
|
}
|
|
|
}
|