|
|
@@ -1,11 +1,15 @@
|
|
|
package nju.seec.helper.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
-import nju.seec.helper.api.bok.*;
|
|
|
+import nju.seec.helper.api.bok.QuestionApi;
|
|
|
+import nju.seec.helper.api.bok.QuestionQueryApi;
|
|
|
+import nju.seec.helper.api.bok.RecordApi;
|
|
|
+import nju.seec.helper.api.bok.UserInteractiveApi;
|
|
|
import nju.seec.helper.api.bok.dto.CollectDTO;
|
|
|
import nju.seec.helper.api.bok.dto.RateDTO;
|
|
|
import nju.seec.helper.api.bok.vo.QuestionVO;
|
|
|
import nju.seec.helper.aspect.auth.LoginUser;
|
|
|
+import nju.seec.helper.dao.ChooseDAO;
|
|
|
import nju.seec.helper.dao.QuestionRecordDAO;
|
|
|
import nju.seec.helper.dao.QuizDAO;
|
|
|
import nju.seec.helper.dao.UserDAO;
|
|
|
@@ -25,6 +29,7 @@ import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -39,25 +44,31 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
private final QuizDAO quizDAO;
|
|
|
private final UserDAO userDAO;
|
|
|
private final QuestionRecordDAO questionRecordDAO;
|
|
|
+ private final ChooseDAO chooseDAO;
|
|
|
|
|
|
private final QuestionApi questionApi;
|
|
|
private final QuestionQueryApi questionQueryApi;
|
|
|
private final UserInteractiveApi userInteractiveApi;
|
|
|
+ private final RecordApi recordApi;
|
|
|
|
|
|
@Autowired
|
|
|
public QuestionServiceImpl(QuizDAO quizDAO
|
|
|
, UserDAO userDAO
|
|
|
, QuestionRecordDAO questionRecordDAO
|
|
|
+ , ChooseDAO chooseDAO
|
|
|
, QuestionApi questionApi
|
|
|
, QuestionQueryApi questionQueryApi
|
|
|
, UserInteractiveApi userInteractiveApi
|
|
|
+ , RecordApi recordApi
|
|
|
) {
|
|
|
this.quizDAO = quizDAO;
|
|
|
this.userDAO = userDAO;
|
|
|
this.questionRecordDAO = questionRecordDAO;
|
|
|
+ this.chooseDAO = chooseDAO;
|
|
|
this.questionApi = questionApi;
|
|
|
this.questionQueryApi = questionQueryApi;
|
|
|
this.userInteractiveApi = userInteractiveApi;
|
|
|
+ this.recordApi = recordApi;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -156,4 +167,26 @@ public class QuestionServiceImpl implements QuestionService {
|
|
|
public void rateQuestion(LoginUser user, String questionId, RateDTO rateDTO) {
|
|
|
userInteractiveApi.rateQuestion(String.valueOf(user.getPid()), questionId, rateDTO);
|
|
|
}
|
|
|
+
|
|
|
+ @Transactional(readOnly = true)
|
|
|
+ @Override
|
|
|
+ public Page<BaseQuestionVO> getCollectAndRateQuestions(LoginUser user, Boolean collect, Boolean rate, Pageable pageable) {
|
|
|
+ return convert(user, userInteractiveApi.getCollectAndRateQuestions(String.valueOf(user.getPid()), collect, rate, pageable));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(readOnly = true)
|
|
|
+ @Override
|
|
|
+ public Page<BaseQuestionVO> getCompletedQuestions(LoginUser user, Pageable pageable) {
|
|
|
+ return convert(user, recordApi.getCompletedQuestions(String.valueOf(user.getPid()), pageable));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static final Set<QuizState> HIDE_QUESTION_ANSWER_STATES = Collections.singleton(QuizState.ONGOING);
|
|
|
+
|
|
|
+ private Page<BaseQuestionVO> convert(LoginUser user, Page<QuestionVO> questionVOList) {
|
|
|
+ List<String> hideQuestionIds = quizDAO.findByCourseIdInAndStateIn(chooseDAO.findCourseIdsByStudentId(user.getId()), HIDE_QUESTION_ANSWER_STATES)
|
|
|
+ .stream()
|
|
|
+ .flatMap(quiz -> quiz.getQuestions().stream())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return questionVOList.map(questionVO -> BaseQuestionVO.convertBokQuestionToVO(questionVO, !hideQuestionIds.contains(questionVO.getId())));
|
|
|
+ }
|
|
|
}
|