|
|
@@ -1,6 +1,7 @@
|
|
|
package nju.seec.helper.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import nju.seec.helper.aspect.auth.LoginUser;
|
|
|
import nju.seec.helper.dao.ChooseDAO;
|
|
|
import nju.seec.helper.dao.QuestionRecordDAO;
|
|
|
@@ -21,10 +22,12 @@ import nju.seec.helper.sys.bok.api.RecordApi;
|
|
|
import nju.seec.helper.sys.bok.api.UserInteractiveApi;
|
|
|
import nju.seec.helper.sys.bok.dto.CollectDTO;
|
|
|
import nju.seec.helper.sys.bok.dto.RateDTO;
|
|
|
+import nju.seec.helper.sys.bok.dto.RecordDTO;
|
|
|
import nju.seec.helper.sys.bok.vo.InteractiveVO;
|
|
|
import nju.seec.helper.sys.bok.vo.QuestionVO;
|
|
|
import nju.seec.helper.sys.bok.vo.RecordQuestionVO;
|
|
|
import nju.seec.helper.sys.dataanalysis.api.ExerciseApi;
|
|
|
+import nju.seec.helper.sys.dataanalysis.model.ExerciseRecord;
|
|
|
import nju.seec.helper.sys.ml.api.RecommendationApi;
|
|
|
import nju.seec.helper.vo.question.BaseQuestionVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -36,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -198,39 +202,41 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
public List<BaseQuestionVO> getRecommendationQuestions(LoginUser user, List<String> knowledgeId, Integer questionNum) {
|
|
|
return questionQueryApi.getQuestionListById(recommendationApi.getRecommendResult(String.valueOf(user.getPid()), knowledgeId, questionNum))
|
|
|
.stream()
|
|
|
- .map(questionVO -> BaseQuestionVO.convertBokQuestionToVO(questionVO, false))
|
|
|
+ .map(questionVO -> BaseQuestionVO.convertBokQuestionToVO(questionVO, true))
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void record(LoginUser user, StudentAnswerDTO studentAnswerDTO) {
|
|
|
- System.out.println(studentAnswerDTO);
|
|
|
-// // 获取已有信息
|
|
|
-// String userId = String.valueOf(user.getPid());
|
|
|
-//
|
|
|
-// Map<String, StudentAnswerDTO.AnswerRecordDTO> recordMap = studentAnswerDTO.getRecords();
|
|
|
-// List<BaseQuestionVO> baseQuestionVOList = questionQueryApi.getQuestionListById(Lists.newArrayList(recordMap.keySet()))
|
|
|
-// .stream()
|
|
|
-// .map(questionVO -> BaseQuestionVO.convertBokQuestionToVO(questionVO, true))
|
|
|
-// .collect(Collectors.toList());
|
|
|
-//
|
|
|
-// // 创建两个列表
|
|
|
-// int size = recordMap.size();
|
|
|
-// List<ExerciseRecord> exerciseRecords = Lists.newArrayListWithExpectedSize(size);
|
|
|
-// List<RecordDTO> records = Lists.newArrayListWithExpectedSize(size);
|
|
|
-//
|
|
|
-// // 填充列表
|
|
|
-// baseQuestionVOList.forEach(baseQuestionVO -> {
|
|
|
-// String questionId = baseQuestionVO.getId();
|
|
|
-// StudentAnswerDTO.AnswerRecordDTO answerRecord = recordMap.get(questionId);
|
|
|
-// Object answer = answerRecord.getAnswer();
|
|
|
-// Boolean pass = baseQuestionVO.pass(answer);
|
|
|
-// exerciseRecords.add(exerciseApi.createExerciseRecordDTO(userId, questionId, answerRecord.getStartAt(), answerRecord.getEndAt(), pass));
|
|
|
-// records.add(recordApi.createRecordDTO(userId, questionId, answer, pass, answerRecord.getStartAt(), answerRecord.getEndAt()));
|
|
|
-// });
|
|
|
-//
|
|
|
-// exerciseApi.reportExercise(exerciseRecords);
|
|
|
-// recordApi.reportUserRecord(records);
|
|
|
+ if (studentAnswerDTO.getRecords() == null || studentAnswerDTO.getRecords().isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 获取已有信息
|
|
|
+ String userId = String.valueOf(user.getPid());
|
|
|
+
|
|
|
+ Map<String, StudentAnswerDTO.AnswerRecordDTO> recordMap = studentAnswerDTO.getRecords();
|
|
|
+ List<BaseQuestionVO> baseQuestionVOList = questionQueryApi.getQuestionListById(Lists.newArrayList(recordMap.keySet()))
|
|
|
+ .stream()
|
|
|
+ .map(questionVO -> BaseQuestionVO.convertBokQuestionToVO(questionVO, true))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 创建两个列表
|
|
|
+ int size = recordMap.size();
|
|
|
+ List<ExerciseRecord> exerciseRecords = Lists.newArrayListWithExpectedSize(size);
|
|
|
+ List<RecordDTO> records = Lists.newArrayListWithExpectedSize(size);
|
|
|
+
|
|
|
+ // 填充列表
|
|
|
+ baseQuestionVOList.forEach(baseQuestionVO -> {
|
|
|
+ String questionId = baseQuestionVO.getId();
|
|
|
+ StudentAnswerDTO.AnswerRecordDTO answerRecord = recordMap.get(questionId);
|
|
|
+ Object answer = answerRecord.getAnswer();
|
|
|
+ Boolean pass = baseQuestionVO.pass(answer);
|
|
|
+ exerciseRecords.add(exerciseApi.createExerciseRecordDTO(userId, questionId, answerRecord.getStartAt(), answerRecord.getEndAt(), pass));
|
|
|
+ records.add(recordApi.createRecordDTO(userId, questionId, answer, pass, answerRecord.getStartAt(), answerRecord.getEndAt()));
|
|
|
+ });
|
|
|
+
|
|
|
+ exerciseApi.reportExercise(exerciseRecords);
|
|
|
+ recordApi.reportUserRecord(records);
|
|
|
}
|
|
|
|
|
|
private static final Set<QuizState> HIDE_QUESTION_ANSWER_STATES = Collections.singleton(QuizState.ONGOING);
|