随机组卷
This commit is contained in:
parent
97419396f6
commit
69d2a464cb
@ -1,5 +1,7 @@
|
||||
package org.jeecg.modules.biz.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
@ -19,6 +21,7 @@ import org.jeecg.modules.gen.paper.service.IPaperService;
|
||||
import org.jeecg.modules.gen.paperquestion.entity.PaperQuestion;
|
||||
import org.jeecg.modules.gen.paperquestion.service.IPaperQuestionService;
|
||||
import org.jeecg.modules.gen.question.entity.Question;
|
||||
import org.jeecg.modules.gen.question.entity.QuestionRequest;
|
||||
import org.jeecg.modules.gen.question.service.IQuestionService;
|
||||
import org.jeecg.modules.gen.questionrepo.entity.QuestionRepo;
|
||||
import org.jeecg.modules.gen.questionrepo.service.IQuestionRepoService;
|
||||
@ -67,9 +70,8 @@ public class ExamBizController {
|
||||
new LambdaQueryWrapper<QuestionRepo>().
|
||||
eq(QuestionRepo::getRepoId, paper.getRepoId())
|
||||
);
|
||||
questionIds = list.stream()
|
||||
.map(QuestionRepo::getQuestionId)
|
||||
.collect(Collectors.toList());
|
||||
//筛选试卷
|
||||
questionIds = random(list, paper.getRules());
|
||||
}else {
|
||||
//固定组卷
|
||||
// 获取试卷中的试题关联信息
|
||||
@ -194,6 +196,41 @@ public class ExamBizController {
|
||||
return examRecordService.update(updateWrapper) ? Result.OK() : Result.error("提交考试失败");
|
||||
}
|
||||
|
||||
//根据考试规则随机组卷
|
||||
public List<String> random(List<QuestionRepo> list, String rules) {
|
||||
JSONObject ruleJson = JSON.parseObject(rules);
|
||||
|
||||
// 根据规则筛选和随机抽取题目
|
||||
Map<Integer, List<String>> typeQuestions = new HashMap<>();
|
||||
|
||||
// 先按题目类型分组
|
||||
list.forEach(qr -> {
|
||||
Question question = questionService.getById(qr.getQuestionId());
|
||||
if (!typeQuestions.containsKey(question.getType())) {
|
||||
typeQuestions.put(question.getType(), new ArrayList<>());
|
||||
}
|
||||
typeQuestions.get(question.getType()).add(question.getId());
|
||||
});
|
||||
|
||||
// 根据规则随机抽取题目
|
||||
List<String> questionIds = new ArrayList<>();
|
||||
for (Integer type : typeQuestions.keySet()) {
|
||||
int count = ruleJson.getInteger("type"+type + "_count"); // 例如:single_choice_count
|
||||
List<String> typeQuestionIds = typeQuestions.get(type);
|
||||
|
||||
// 随机抽取指定数量的题目
|
||||
if (typeQuestionIds.size() <= count) {
|
||||
questionIds.addAll(typeQuestionIds);
|
||||
} else {
|
||||
// 打乱顺序后取前count个
|
||||
Collections.shuffle(typeQuestionIds);
|
||||
questionIds.addAll(typeQuestionIds.subList(0, count));
|
||||
}
|
||||
}
|
||||
return questionIds;
|
||||
}
|
||||
|
||||
//获取ip信息
|
||||
public String getClientIp(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
|
||||
@ -219,6 +256,7 @@ public class ExamBizController {
|
||||
return ip;
|
||||
}
|
||||
|
||||
//获取设备信息
|
||||
public String getDeviceInfo(HttpServletRequest request) {
|
||||
// 获取User-Agent
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
@ -226,7 +264,6 @@ public class ExamBizController {
|
||||
String deviceInfo = parseDeviceInfo(userAgent);
|
||||
return deviceInfo;
|
||||
}
|
||||
|
||||
private String parseDeviceInfo(String userAgent) {
|
||||
if (userAgent == null) {
|
||||
return "Unknown";
|
||||
|
Loading…
x
Reference in New Issue
Block a user