增加了选题规则的判断

This commit is contained in:
2024-11-21 11:25:27 +08:00
parent 4e529ecb7f
commit 60a74297b3
2 changed files with 85 additions and 20 deletions
+18 -19
View File
@@ -252,22 +252,21 @@ func (r *QuestionDao) GetQuestionCountSearch(req requests.GetQuestionCount) (tot
return totalRecords, nil
}
//
//// GetQuestionNotInListRand 获取列表-随机-排除
//func (r *QuestionDao) GetQuestionNotInListRand(maps interface{}, notQuestionId []int64, limit int) (m []*model.Question, err error) {
// query := global.Db.Model(&model.Question{})
// query = query.Where(maps)
//
// // 排除选项
// if len(notQuestionId) > 0 {
// query = query.Where("question_id not in (?)", notQuestionId)
// }
//
// query = query.Limit(limit).Order("rand()")
//
// err = query.Find(&m).Error
// if err != nil {
// return nil, err
// }
// return m, nil
//}
// GetQuestionNotInListRand 获取列表-随机-排除
func (r *QuestionDao) GetQuestionNotInListRand(maps interface{}, notQuestionId []int64, limit int) (m []*model.Question, err error) {
query := global.Db.Model(&model.Question{})
query = query.Where(maps)
// 排除选项
if len(notQuestionId) > 0 {
query = query.Where("question_id not in (?)", notQuestionId)
}
query = query.Limit(limit).Order("rand()")
err = query.Find(&m).Error
if err != nil {
return nil, err
}
return m, nil
}