This commit is contained in:
wucongxing8150 2024-10-29 14:10:20 +08:00
parent 031f5c3b85
commit 89907acaee

View File

@ -86,9 +86,18 @@ func (r *QuestionService) AddQuestion(req requests.AddQuestion) (bool, error) {
if !strings.Contains(questionOption, s) {
return false, errors.New("请正确输入选项序号")
}
}
// 判断答案是否在选项中
if !strings.Contains(questionAnswer, s) {
// 判断答案是否在选项中
for _, s := range req.QuestionAnswer {
isExist := false
for _, s2 := range req.QuestionOption {
if strings.Contains(s2, s) {
isExist = true
}
}
if isExist == false {
return false, errors.New("答案不在选项中,请重新填写")
}
}
@ -463,13 +472,12 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion
}
// 答案
result := make([]string, len(req.QuestionAnswer))
questionAnswer := make([]string, len(req.QuestionAnswer))
for i, v := range req.QuestionAnswer {
result[i] = v
questionAnswer[i] = v
}
questionAnswer := strings.Join(result, ",")
questionData["question_answer"] = questionAnswer
questionData["question_answer"] = strings.Join(questionAnswer, ",")
// 判断选项
if req.QuestionType == 1 || req.QuestionType == 2 {
@ -485,7 +493,12 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion
return false, errors.New("存在为空的选项")
}
// 取出首字母
if option == "," {
tx.Rollback()
return false, errors.New("存在为空的选项")
}
// 取出选项首字母
s := option[0:1]
// 判断是否为正常选项
@ -493,9 +506,18 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion
tx.Rollback()
return false, errors.New("请正确输入选项序号")
}
}
// 判断答案是否在选项中
if !strings.Contains(questionAnswer, s) {
// 判断答案是否在选项中
for _, s := range req.QuestionAnswer {
isExist := false
for _, s2 := range req.QuestionOption {
if strings.Contains(s2, s) {
isExist = true
}
}
if isExist == false {
tx.Rollback()
return false, errors.New("答案不在选项中,请重新填写")
}