12111
This commit is contained in:
parent
031f5c3b85
commit
89907acaee
@ -86,9 +86,18 @@ func (r *QuestionService) AddQuestion(req requests.AddQuestion) (bool, error) {
|
|||||||
if !strings.Contains(questionOption, s) {
|
if !strings.Contains(questionOption, s) {
|
||||||
return false, errors.New("请正确输入选项序号")
|
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("答案不在选项中,请重新填写")
|
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 {
|
for i, v := range req.QuestionAnswer {
|
||||||
result[i] = v
|
questionAnswer[i] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
questionAnswer := strings.Join(result, ",")
|
questionData["question_answer"] = strings.Join(questionAnswer, ",")
|
||||||
questionData["question_answer"] = questionAnswer
|
|
||||||
|
|
||||||
// 判断选项
|
// 判断选项
|
||||||
if req.QuestionType == 1 || req.QuestionType == 2 {
|
if req.QuestionType == 1 || req.QuestionType == 2 {
|
||||||
@ -485,7 +493,12 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion
|
|||||||
return false, errors.New("存在为空的选项")
|
return false, errors.New("存在为空的选项")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 取出首字母
|
if option == "," {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New("存在为空的选项")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取出选项首字母
|
||||||
s := option[0:1]
|
s := option[0:1]
|
||||||
|
|
||||||
// 判断是否为正常选项
|
// 判断是否为正常选项
|
||||||
@ -493,9 +506,18 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion
|
|||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return false, errors.New("请正确输入选项序号")
|
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()
|
tx.Rollback()
|
||||||
return false, errors.New("答案不在选项中,请重新填写")
|
return false, errors.New("答案不在选项中,请重新填写")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user