12
This commit is contained in:
parent
2fbc7d7e1c
commit
031f5c3b85
@ -74,14 +74,17 @@ func (r *QuestionService) AddQuestion(req requests.AddQuestion) (bool, error) {
|
||||
}
|
||||
|
||||
questionOption := "A.B.C.D.E.F.G.H.I.J.K."
|
||||
for _, s := range req.QuestionOption {
|
||||
if s == "" {
|
||||
for _, option := range req.QuestionOption {
|
||||
if option == "" {
|
||||
return false, errors.New("存在为空的选项")
|
||||
}
|
||||
|
||||
// 取出首字母
|
||||
s := option[0:1]
|
||||
|
||||
// 判断是否为正常选项
|
||||
if !strings.Contains(questionOption, s) {
|
||||
return false, errors.New("选项存在错误标识")
|
||||
return false, errors.New("请正确输入选项序号")
|
||||
}
|
||||
|
||||
// 判断答案是否在选项中
|
||||
@ -404,7 +407,6 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion
|
||||
}
|
||||
|
||||
// 验证一级标签
|
||||
|
||||
firstLabelId, err := strconv.ParseInt(req.FirstLabelId, 10, 64)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -461,13 +463,43 @@ func (r *QuestionService) PutQuestion(questionId int64, req requests.PutQuestion
|
||||
}
|
||||
|
||||
// 答案
|
||||
if len(req.QuestionAnswer) > 0 {
|
||||
result := make([]string, len(req.QuestionAnswer))
|
||||
for i, v := range req.QuestionAnswer {
|
||||
result[i] = v
|
||||
result := make([]string, len(req.QuestionAnswer))
|
||||
for i, v := range req.QuestionAnswer {
|
||||
result[i] = v
|
||||
}
|
||||
|
||||
questionAnswer := strings.Join(result, ",")
|
||||
questionData["question_answer"] = questionAnswer
|
||||
|
||||
// 判断选项
|
||||
if req.QuestionType == 1 || req.QuestionType == 2 {
|
||||
if len(req.QuestionOption) == 0 {
|
||||
tx.Rollback()
|
||||
return false, errors.New("请填入选项")
|
||||
}
|
||||
|
||||
questionData["question_answer"] = strings.Join(result, ",")
|
||||
questionOption := "ABCDEFGHIJK"
|
||||
for _, option := range req.QuestionOption {
|
||||
if option == "" {
|
||||
tx.Rollback()
|
||||
return false, errors.New("存在为空的选项")
|
||||
}
|
||||
|
||||
// 取出首字母
|
||||
s := option[0:1]
|
||||
|
||||
// 判断是否为正常选项
|
||||
if !strings.Contains(questionOption, s) {
|
||||
tx.Rollback()
|
||||
return false, errors.New("请正确输入选项序号")
|
||||
}
|
||||
|
||||
// 判断答案是否在选项中
|
||||
if !strings.Contains(questionAnswer, s) {
|
||||
tx.Rollback()
|
||||
return false, errors.New("答案不在选项中,请重新填写")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 验证重复
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user