|
@@ -6,6 +6,7 @@ import cn.hutool.poi.excel.ExcelReader;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ynfy.buss.exam.question.dto.QuestionConditionDTO;
|
|
|
import com.ynfy.buss.exam.question.dto.QuestionDTO;
|
|
@@ -17,6 +18,7 @@ import com.ynfy.buss.exam.questionanswer.entity.QuestionAnswer;
|
|
|
import com.ynfy.buss.exam.questionanswer.service.IQuestionAnswerService;
|
|
|
import com.ynfy.buss.exam.repository.entity.Repository;
|
|
|
import com.ynfy.buss.exam.repository.service.IRepositoryService;
|
|
|
+import com.ynfy.buss.practice.userpractice.enums.PracticeMode;
|
|
|
import com.ynfy.common.utils.CharUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -555,4 +557,48 @@ public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, Question> i
|
|
|
public List<QuestionDTO> countQuestionNumByType(String repositoryId) {
|
|
|
return questionMapper.countQuestionNumByType(repositoryId);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<Question> listQuestionByPracticeMode(Integer pageNo, Integer pageSize, String repositoryId,
|
|
|
+ Integer questionType, Integer mode) {
|
|
|
+ Page<Question> page = new Page<Question>(pageNo, pageSize);
|
|
|
+ LambdaQueryWrapper<Question> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(Question::getRepositoryId, repositoryId);
|
|
|
+
|
|
|
+ IPage<Question> pageList = null;
|
|
|
+ switch (PracticeMode.getByCode(mode)) {
|
|
|
+ case SX://顺序练习
|
|
|
+ pageList = page(page, queryWrapper);
|
|
|
+ break;
|
|
|
+ case SJ://随机练习
|
|
|
+ pageList = page(page, queryWrapper);
|
|
|
+ if (!CollectionUtils.isEmpty(pageList.getRecords())) {
|
|
|
+ Collections.shuffle(pageList.getRecords());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case TX://题型练习
|
|
|
+ if (Objects.isNull(questionType)) {
|
|
|
+ throw new JeecgBootException("题型缺失异常");
|
|
|
+ }
|
|
|
+ queryWrapper.eq(Question::getType, questionType);
|
|
|
+ pageList = page(page, queryWrapper);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ List<String> questionIds = pageList.getRecords().stream().map(Question::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //获取题目答案
|
|
|
+ List<QuestionAnswer> answerList = questionAnswerService.listAnswerByQuestionIds(questionIds);
|
|
|
+ if (!CollectionUtils.isEmpty(answerList)) {
|
|
|
+ Map<String, List<QuestionAnswer>> answerMap = answerList.stream().collect(Collectors
|
|
|
+ .groupingBy(QuestionAnswer::getQuestionId, Collectors.toList()));
|
|
|
+ pageList.getRecords().forEach(item -> {
|
|
|
+ List<QuestionAnswer> answers = answerMap.get(item.getId());
|
|
|
+ if (!CollectionUtils.isEmpty(answers)) {
|
|
|
+ //答案排序
|
|
|
+ item.setAnswerList(answers.stream().sorted(Comparator.comparing(QuestionAnswer::getSort)).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return pageList;
|
|
|
+ }
|
|
|
}
|