fix(question): 修复判断题答案验证逻辑

dev
zhaokai 2026-03-07 09:20:12 +08:00
parent 5dd81cd81c
commit 498f5d681b
1 changed files with 29 additions and 29 deletions

View File

@ -116,38 +116,38 @@ public class QuestionE extends BaseE {
for (int i = 0; i < videoChoiceList.size(); i++) {
QuestionVideoChoiceExcelImportEntity entity = videoChoiceList.get(i);
if (entity == null) {
errList.add("单选题第" + (i + 2) + "行数据为空");
errList.add("单选题第" + (i + 3) + "行数据为空");
continue;
}
if (StringUtils.isEmpty(entity.getQuestionDry())) {
errList.add("单选题第" + (i + 2) + "行单选题目不能为空");
errList.add("单选题第" + (i + 3) + "行单选题目不能为空");
}
if (StringUtils.isEmpty(entity.getOptionA())) {
errList.add("单选题第" + (i + 2) + "行单选选项A不能为空");
errList.add("单选题第" + (i + 3) + "行单选选项A不能为空");
}
if (StringUtils.isEmpty(entity.getOptionB())) {
errList.add("单选题第" + (i + 2) + "行单选选项B不能为空");
errList.add("单选题第" + (i + 3) + "行单选选项B不能为空");
}
if (StringUtils.isEmpty(entity.getOptionC())) {
errList.add("单选题第" + (i + 2) + "行单选选项C不能为空");
errList.add("单选题第" + (i + 3) + "行单选选项C不能为空");
}
if (StringUtils.isEmpty(entity.getOptionD())) {
errList.add("单选题第" + (i + 2) + "行单选选项D不能为空");
errList.add("单选题第" + (i + 3) + "行单选选项D不能为空");
}
if (StringUtils.isEmpty(entity.getAnswer())) {
errList.add("单选题第" + (i + 2) + "行单选答案不能为空");
errList.add("单选题第" + (i + 3) + "行单选答案不能为空");
}
if (StringUtils.isEmpty(entity.getDescr())) {
errList.add("单选题第" + (i + 2) + "行答案解析不能为空");
errList.add("单选题第" + (i + 3) + "行答案解析不能为空");
}
if(CoursewareTypeEnum.EXAM_QUESTION.getCode().equals(coursewareType)){
if (StringUtils.isEmpty(entity.getScore())) {
errList.add("单选题第" + (i + 2) + "行分值不能为空");
errList.add("单选题第" + (i + 3) + "行分值不能为空");
}
}
//单选题答案只能是ABCD四个中的一个不能多个
if (!entity.getAnswer().matches("[A-D]") ||entity.getAnswer().length()>1) {
errList.add("单选题第" + (i + 2) + "行答案错误");
errList.add("单选题第" + (i + 3) + "行答案错误");
}
}
}
@ -155,39 +155,39 @@ public class QuestionE extends BaseE {
for (int i = 0; i < videoMultiselectList.size(); i++) {
QuestionVideoMultiselectExcelImportEntity entity = videoMultiselectList.get(i);
if (entity == null) {
errList.add("多选题第" + (i + 2) + "行数据为空");
errList.add("多选题第" + (i + 3) + "行数据为空");
continue;
}
if (StringUtils.isEmpty(entity.getQuestionDry())) {
errList.add("多选题第" + (i + 2) + "行多选题目不能为空");
errList.add("多选题第" + (i + 3) + "行多选题目不能为空");
}
if (StringUtils.isEmpty(entity.getOptionA())) {
errList.add("多选题第" + (i + 2) + "行多选选项A不能为空");
errList.add("多选题第" + (i + 3) + "行多选选项A不能为空");
}
if (StringUtils.isEmpty(entity.getOptionB())) {
errList.add("多选题第" + (i + 2) + "行多选选项B不能为空");
errList.add("多选题第" + (i + 3) + "行多选选项B不能为空");
}
if (StringUtils.isEmpty(entity.getOptionC())) {
errList.add("多选题第" + (i + 2) + "行多选选项C不能为空");
errList.add("多选题第" + (i + 3) + "行多选选项C不能为空");
}
if (StringUtils.isEmpty(entity.getOptionD())) {
errList.add("多选题第" + (i + 2) + "行多选选项D不能为空");
errList.add("多选题第" + (i + 3) + "行多选选项D不能为空");
}
if (StringUtils.isEmpty(entity.getAnswer())) {
errList.add("多选题第" + (i + 2) + "行多选答案不能为空");
errList.add("多选题第" + (i + 3) + "行多选答案不能为空");
}
if (StringUtils.isEmpty(entity.getDescr())) {
errList.add("多选题第" + (i + 2) + "行答案解析不能为空");
errList.add("多选题第" + (i + 3) + "行答案解析不能为空");
}
if(CoursewareTypeEnum.EXAM_QUESTION.getCode().equals(coursewareType)){
if (StringUtils.isEmpty(entity.getScore())) {
errList.add("多选题第" + (i + 2) + "行分值不能为空");
errList.add("多选题第" + (i + 3) + "行分值不能为空");
}
}
String answer = entity.getAnswer().toUpperCase().trim();
//多选题答案只能是选题答案只能是ABCD四个中的值可以多个
if (answer.matches("^[A-D]{2,4}$") && ! hasDuplicateChars(answer)) {
errList.add("多选题第" + (i + 2) + "行答案错误");
if (!answer.matches("^[A-D]{2,4}$") || hasDuplicateChars(answer)) {
errList.add("多选题第" + (i + 3) + "行答案错误");
}
}
@ -196,37 +196,37 @@ public class QuestionE extends BaseE {
for (int i = 0; i < videoJudgeList.size(); i++) {
QuestionVideoJudgeExcelImportEntity entity = videoJudgeList.get(i);
if (entity == null) {
errList.add("判断题第" + (i + 2) + "行数据为空");
errList.add("判断题第" + (i + 3) + "行数据为空");
continue;
}
if (StringUtils.isEmpty(entity.getQuestionDry())) {
errList.add("判断题第" + (i + 2) + "行判断题目不能为空");
errList.add("判断题第" + (i + 3) + "行判断题目不能为空");
}
if (StringUtils.isEmpty(entity.getAnswer())) {
errList.add("判断题第" + (i + 2) + "行判断答案不能为空");
errList.add("判断题第" + (i + 3) + "行判断答案不能为空");
}
if (StringUtils.isEmpty(entity.getDescr())) {
errList.add("判断题第" + (i + 2) + "行答案解析不能为空");
errList.add("判断题第" + (i + 3) + "行答案解析不能为空");
}
if(CoursewareTypeEnum.EXAM_QUESTION.getCode().equals(coursewareType)){
if (StringUtils.isEmpty(entity.getScore())) {
errList.add("判断题第" + (i + 2) + "行分值不能为空");
errList.add("判断题第" + (i + 3) + "行分值不能为空");
}else{
//不为空的话判断是否是T F
if(!QuestionJudgeAnswerTypeEnum.isTrueOrFalse(entity.getAnswer())){
errList.add("判断题第" + (i + 2) + "行答案格式错误");
errList.add("判断题第" + (i + 3) + "行答案格式错误");
}
}
}
//判断题答案只能是AB中的一个
if (!entity.getAnswer().matches("[F-T]") ||entity.getAnswer().length()>1) {
errList.add("判断题第" + (i + 2) + "行答案错误");
errList.add("判断题第" + (i + 3) + "行答案错误");
}
}
}
if (CollUtil.isNotEmpty(errList)) {
throw new BizException("导入信息有误,请检查后重新导入。错误信息:" + String.join("", errList));
throw new BizException("导入信息有误,请检查后重新导入。错误信息:" + String.join(",", errList));
}
// 赋值