|
|
@ -3,6 +3,7 @@ package com.tz.platform.pc;
|
|
|
|
import com.tz.platform.common.core.base.BaseController;
|
|
|
|
import com.tz.platform.common.core.base.BaseController;
|
|
|
|
import com.tz.platform.common.core.base.Result;
|
|
|
|
import com.tz.platform.common.core.base.Result;
|
|
|
|
import com.tz.platform.common.core.enmus.QuestionTypeEnum;
|
|
|
|
import com.tz.platform.common.core.enmus.QuestionTypeEnum;
|
|
|
|
|
|
|
|
import com.tz.platform.entity.Question;
|
|
|
|
import com.tz.platform.exam.pc.dto.QuestionContDTO;
|
|
|
|
import com.tz.platform.exam.pc.dto.QuestionContDTO;
|
|
|
|
import com.tz.platform.pc.biz.PCQuestionBiz;
|
|
|
|
import com.tz.platform.pc.biz.PCQuestionBiz;
|
|
|
|
import com.tz.platform.pc.dto.ListQuestionDTO;
|
|
|
|
import com.tz.platform.pc.dto.ListQuestionDTO;
|
|
|
@ -13,6 +14,11 @@ import com.tz.platform.repository.QuestionDao;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@RequestMapping(value = "/pc/question")
|
|
|
|
@RequestMapping(value = "/pc/question")
|
|
|
|
public class PCQuestionController extends BaseController {
|
|
|
|
public class PCQuestionController extends BaseController {
|
|
|
@ -21,6 +27,7 @@ public class PCQuestionController extends BaseController {
|
|
|
|
private PCQuestionBiz questionBiz;
|
|
|
|
private PCQuestionBiz questionBiz;
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private QuestionDao questionDao;
|
|
|
|
private QuestionDao questionDao;
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping(value = "list")
|
|
|
|
@PostMapping(value = "list")
|
|
|
|
public Result<PageQuestionDTO> list(@RequestBody PageQuestionVO questionVO) {
|
|
|
|
public Result<PageQuestionDTO> list(@RequestBody PageQuestionVO questionVO) {
|
|
|
|
return questionBiz.list(questionVO);
|
|
|
|
return questionBiz.list(questionVO);
|
|
|
@ -75,11 +82,66 @@ public class PCQuestionController extends BaseController {
|
|
|
|
return Result.success(dto);
|
|
|
|
return Result.success(dto);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//todo 随机抽取逻辑
|
|
|
|
@GetMapping(value = "getCourseList")
|
|
|
|
//1、展示所有课程信息,供选择使用。已有 使用下拉框
|
|
|
|
public List<CourseDTO> getCourseList() {
|
|
|
|
|
|
|
|
return questionDao.getCourseList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//2、根据选择的一个或多个课程ID查出总共的题型数量 改造完成 getCount
|
|
|
|
@PostMapping(value = "getIdsByCount")
|
|
|
|
|
|
|
|
public List<Long> getIdsByCount(@RequestBody GetIdsVo vo) {
|
|
|
|
|
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Long> courseIds = vo.getCourseIds();
|
|
|
|
|
|
|
|
int judgeCount = vo.getJudgeCount();
|
|
|
|
|
|
|
|
int singleCount = vo.getSingleCount();
|
|
|
|
|
|
|
|
int gapFillingCount = vo.getGapFillingCount();
|
|
|
|
|
|
|
|
int multyCount = vo.getMultyCount();
|
|
|
|
|
|
|
|
|
|
|
|
//3、根据用户设置的各个题型的数量组成考试,这一步应该是前端完成
|
|
|
|
// 随机抽取题目ID
|
|
|
|
|
|
|
|
if (judgeCount > 0) {
|
|
|
|
|
|
|
|
List<Question> judgeIds = questionDao.findAllByQuestionTypeAndCourseIdIn(3, courseIds);
|
|
|
|
|
|
|
|
List<Long> collect = judgeIds.stream().map(Question::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
ids.addAll(randomSelect(collect, judgeCount));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (singleCount > 0) {
|
|
|
|
|
|
|
|
List<Question> singleIds = questionDao.findAllByQuestionTypeAndCourseIdIn(1, courseIds);
|
|
|
|
|
|
|
|
List<Long> collect = singleIds.stream().map(Question::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
ids.addAll(randomSelect(collect, singleCount));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gapFillingCount > 0) {
|
|
|
|
|
|
|
|
List<Question> gapFillingIds = questionDao.findAllByQuestionTypeAndCourseIdIn(4, courseIds);
|
|
|
|
|
|
|
|
List<Long> collect = gapFillingIds.stream().map(Question::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
ids.addAll(randomSelect(collect, gapFillingCount));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (multyCount > 0) {
|
|
|
|
|
|
|
|
List<Question> multyIds= questionDao.findAllByQuestionTypeAndCourseIdIn(2, courseIds);
|
|
|
|
|
|
|
|
List<Long> collect = multyIds.stream().map(Question::getId).collect(Collectors.toList());
|
|
|
|
|
|
|
|
ids.addAll(randomSelect(collect, multyCount));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 从给定的题目ID列表中随机抽取指定数量的题目ID
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param ids 题目ID列表
|
|
|
|
|
|
|
|
* @param count 需要抽取的题目数量
|
|
|
|
|
|
|
|
* @return 抽取的题目ID列表
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private List<Long> randomSelect(List<Long> ids, int count) {
|
|
|
|
|
|
|
|
if (count > ids.size()) {
|
|
|
|
|
|
|
|
throw new IllegalArgumentException("请求的题目数量超过可用题目数量");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Collections.shuffle(ids);
|
|
|
|
|
|
|
|
return ids.subList(0, count);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//todo 随机抽取逻辑
|
|
|
|
|
|
|
|
//1、展示所有课程信息,供选择使用。已有 使用下拉框
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//2、根据选择的一个或多个课程ID查出总共的题型数量 改造完成 getCount
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//3、根据用户设置的各个题型的数量组成考试,这一步应该是前端完成
|
|
|
|
|
|
|
|
|
|
|
|