优化题库代码

This commit is contained in:
2025-11-18 17:11:18 +08:00
parent ff9a181c99
commit 5fddba8a30
13 changed files with 138 additions and 116 deletions
+11 -1
View File
@@ -13,6 +13,7 @@ type QuestionListParams struct {
TenantId int
Keyword string
QuestionType *int8
BankId int64
Page int
PageSize int
}
@@ -42,6 +43,9 @@ func GetExamQuestions(params QuestionListParams) ([]*models.ExamQuestion, int64,
if params.QuestionType != nil {
qs = qs.Filter("question_type", *params.QuestionType)
}
if params.BankId > 0 {
qs = qs.Filter("bank_id", params.BankId)
}
total, err := qs.Count()
if err != nil {
return nil, 0, err
@@ -121,7 +125,13 @@ func UpdateExamQuestion(tenantId int, id int64, q *models.ExamQuestion, options
existing.QuestionTitle = q.QuestionTitle
existing.QuestionAnalysis = q.QuestionAnalysis
existing.Score = q.Score
if _, err := o.Update(&existing, "QuestionType", "QuestionTitle", "QuestionAnalysis", "Score"); err != nil {
// 可选更新题库归属
fields := []string{"QuestionType", "QuestionTitle", "QuestionAnalysis", "Score"}
if q.BankId > 0 {
existing.BankId = q.BankId
fields = append(fields, "BankId")
}
if _, err := o.Update(&existing, fields...); err != nil {
return err
}
// soft delete old options and answer