From ef680987c807e1995ce6b6368828f4629c3c2766 Mon Sep 17 00:00:00 2001 From: zhaokai Date: Mon, 2 Mar 2026 16:48:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(question):=20=E4=BF=AE=E5=A4=8D=E9=A2=98?= =?UTF-8?q?=E7=9B=AE=E7=AD=94=E6=A1=88=E9=AA=8C=E8=AF=81=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edu/domain/model/resource/QuestionE.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/web-domain/src/main/java/com/zcloud/edu/domain/model/resource/QuestionE.java b/web-domain/src/main/java/com/zcloud/edu/domain/model/resource/QuestionE.java index fe5d8f5..6ced59e 100644 --- a/web-domain/src/main/java/com/zcloud/edu/domain/model/resource/QuestionE.java +++ b/web-domain/src/main/java/com/zcloud/edu/domain/model/resource/QuestionE.java @@ -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; + } }