随机选题,bug

This commit is contained in:
yang
2024-10-09 14:57:56 +08:00
parent 9da0eae4c0
commit 85517dcd57

View File

@@ -221,20 +221,19 @@ public class CourseContentServiceImpl implements ICourseContentService {
try {
// 判断试卷类型
if (courseExam.getPaperType() == 1 && StringUtils.isNotBlank(courseExam.getPaperContent()) && randomMode && qnum != null && qnum > 0) {
if (courseExam.getPaperType() == 1 && StringUtils.isNotBlank(courseExam.getPaperContent())) {
paperJson = courseExam.getPaperContent();
JsonNode rootNode = objectMapper.readTree(paperJson);
JsonNode itemsNode = rootNode.path("items");
List<JsonNode> itemsNodes = new ArrayList<>();
itemsNode.forEach(itemsNodes::add);
if (randomMode && qnum != null && qnum > 0 && itemsNodes.size() > qnum) {
if (randomMode && qnum != null && qnum > 0 && randomMode && qnum != null && qnum > 0 && itemsNodes.size() > qnum) {
Collections.shuffle(itemsNodes);
itemsNodes = itemsNodes.subList(0, qnum);
}
return itemsNodes;
} else if (courseExam.getPaperType() == 2 && randomMode && qnum != null && qnum > 0) {
} else if (courseExam.getPaperType() == 2) {
IXaskCache cache = XaskCacheProvider.getCache();
String cacheKey = "course:exam:" + courseExamId + ":" + paperId;
String cacheData = cache.getCacheObject(cacheKey);
@@ -250,7 +249,7 @@ public class CourseContentServiceImpl implements ICourseContentService {
List<TestQuestionVo> eqVoList = objectMapper.readValue(paperJson, new TypeReference<List<TestQuestionVo>>() {
});
if (eqVoList.size() > qnum) {
if (randomMode && qnum != null && qnum > 0 && eqVoList.size() > qnum) {
Collections.shuffle(eqVoList);
eqVoList = eqVoList.subList(0, qnum);
}