Parcourir la source

fix(培训考试): 去掉题库批量上传判断题的空选项、允许使用小写字母答案

liuyaqi il y a 3 ans
Parent
commit
398d344acc
1 fichiers modifiés avec 17 ajouts et 10 suppressions
  1. 17 10
      service/learning/question.go

+ 17 - 10
service/learning/question.go

@@ -339,7 +339,7 @@ func ParseQuestionExcel(skillId int, operateBy string, b []byte) ([]learning.Lea
 			return nil, fmt.Errorf("excel 格式错误:不合法的题型 '%s' %d", typeStr, rown)
 		}
 
-		answerStr := strings.TrimSpace(row[7])
+		answerStr := strings.ToUpper(strings.TrimSpace(row[7]))
 		answer := strings.Split(answerStr, " ")
 		for i := range answer {
 			pass := false
@@ -354,27 +354,34 @@ func ParseQuestionExcel(skillId int, operateBy string, b []byte) ([]learning.Lea
 			}
 		}
 
-		options := []learning.LearningQuestionOption{
-			{
+		options := []learning.LearningQuestionOption{}
+		if a != "" {
+			options = append(options, learning.LearningQuestionOption{
 				Name:      "A",
 				Content:   a,
 				IsCorrect: strings.Contains(answerStr, "A"),
-			},
-			{
+			})
+		}
+		if b != "" {
+			options = append(options, learning.LearningQuestionOption{
 				Name:      "B",
 				Content:   b,
 				IsCorrect: strings.Contains(answerStr, "B"),
-			},
-			{
+			})
+		}
+		if c != "" {
+			options = append(options, learning.LearningQuestionOption{
 				Name:      "C",
 				Content:   c,
 				IsCorrect: strings.Contains(answerStr, "C"),
-			},
-			{
+			})
+		}
+		if d != "" {
+			options = append(options, learning.LearningQuestionOption{
 				Name:      "D",
 				Content:   d,
 				IsCorrect: strings.Contains(answerStr, "D"),
-			},
+			})
 		}
 		correctCount := 0
 		for _, o := range options {