题库增加题目数量展示

This commit is contained in:
李志强 2025-11-19 17:14:31 +08:00
parent 7664821d88
commit aae2fe1e14
3 changed files with 71 additions and 45 deletions

View File

@ -22,6 +22,7 @@
<el-table-column prop="id" label="ID" width="80" align="center" />
<el-table-column prop="bank_name" label="题库名称" min-width="200" show-overflow-tooltip />
<el-table-column prop="bank_desc" label="描述" min-width="200" show-overflow-tooltip />
<el-table-column prop="total_count" label="题目数量" min-width="60" align="center" />
<el-table-column label="操作" width="200" fixed="right" align="center">
<template #default="{ row }">
<el-button link type="primary" size="small" @click="handleEdit(row)">编辑</el-button>

View File

@ -2,9 +2,9 @@ package controllers
import (
"encoding/json"
"regexp"
"strconv"
"strings"
"regexp"
"server/models"
"server/services"
@ -421,7 +421,7 @@ func (c *ExamQuestionBankController) GetBankList() {
tenantId, _ := c.Ctx.Input.GetData("tenantId").(int)
keyword := c.GetString("keyword")
page, _ := c.GetInt("page", 1)
pageSize, _ := c.GetInt("pageSize", 10)
pageSize, _ := c.GetInt("pageSize", 20)
list, total, err := services.GetExamQuestionBanks(services.BankListParams{
TenantId: tenantId,
Keyword: keyword,
@ -433,7 +433,22 @@ func (c *ExamQuestionBankController) GetBankList() {
c.ServeJSON()
return
}
c.Data["json"] = map[string]interface{}{"code": 0, "message": "ok", "data": map[string]interface{}{"list": list, "total": total}}
// enrich with total_count per bank
items := make([]map[string]interface{}, 0, len(list))
for _, b := range list {
if b == nil {
continue
}
cnt, _ := services.CountQuestionsInBank(tenantId, b.Id)
items = append(items, map[string]interface{}{
"id": b.Id,
"tenant_id": b.TenantId,
"bank_name": b.BankName,
"bank_desc": b.BankDesc,
"total_count": cnt,
})
}
c.Data["json"] = map[string]interface{}{"code": 0, "message": "ok", "data": map[string]interface{}{"list": items, "total": total}}
c.ServeJSON()
}

View File

@ -18,6 +18,16 @@ type QuestionListParams struct {
PageSize int
}
// CountQuestionsInBank 统计指定题库下的题目数量(仅统计未删除且启用的题目)
func CountQuestionsInBank(tenantId int, bankId int64) (int64, error) {
o := orm.NewOrm()
qs := o.QueryTable(new(models.ExamQuestion)).Filter("delete_time__isnull", true).Filter("status", 1).Filter("bank_id", bankId)
if tenantId > 0 {
qs = qs.Filter("tenant_id", tenantId)
}
return qs.Count()
}
type QuestionWithMeta struct {
Question *models.ExamQuestion
Options []*models.ExamQuestionOption