fix(question): 修复题目答案验证逻辑
parent
89c4693002
commit
ef680987c8
|
|
@ -145,6 +145,10 @@ public class QuestionE extends BaseE {
|
|||
errList.add("单选题第" + (i + 2) + "行分值不能为空");
|
||||
}
|
||||
}
|
||||
//单选题答案只能是ABCD四个中的一个,不能多个
|
||||
if (!entity.getAnswer().matches("[A-D]") ||entity.getAnswer().length()>1) {
|
||||
errList.add("单选题第" + (i + 2) + "行答案错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(videoMultiselectList)) {
|
||||
|
|
@ -180,6 +184,12 @@ public class QuestionE extends BaseE {
|
|||
errList.add("多选题第" + (i + 2) + "行分值不能为空");
|
||||
}
|
||||
}
|
||||
String answer = entity.getAnswer().toUpperCase().trim();
|
||||
//多选题答案只能是选题答案只能是ABCD四个中的值,可以多个
|
||||
if (answer.matches("^[A-D]{2,4}$") && ! hasDuplicateChars(answer)) {
|
||||
errList.add("多选题第" + (i + 2) + "行答案错误");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(videoJudgeList)) {
|
||||
|
|
@ -208,6 +218,10 @@ public class QuestionE extends BaseE {
|
|||
}
|
||||
}
|
||||
}
|
||||
//判断题答案只能是AB中的一个
|
||||
if (!entity.getAnswer().matches("[A-B]") ||entity.getAnswer().length()>1) {
|
||||
errList.add("单选题第" + (i + 2) + "行答案错误");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -289,5 +303,18 @@ public class QuestionE extends BaseE {
|
|||
return questionEList;
|
||||
|
||||
}
|
||||
public static boolean hasDuplicateChars(String str) {
|
||||
if (str == null || str.length() <= 1) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < str.length(); i++) {
|
||||
for (int j = i + 1; j < str.length(); j++) {
|
||||
if (str.charAt(i) == str.charAt(j)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue