题库增加题目数量展示
This commit is contained in:
parent
7664821d88
commit
aae2fe1e14
@ -22,6 +22,7 @@
|
|||||||
<el-table-column prop="id" label="ID" width="80" align="center" />
|
<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_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="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">
|
<el-table-column label="操作" width="200" fixed="right" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-button link type="primary" size="small" @click="handleEdit(row)">编辑</el-button>
|
<el-button link type="primary" size="small" @click="handleEdit(row)">编辑</el-button>
|
||||||
|
|||||||
@ -2,9 +2,9 @@ package controllers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
"server/models"
|
"server/models"
|
||||||
"server/services"
|
"server/services"
|
||||||
@ -421,7 +421,7 @@ func (c *ExamQuestionBankController) GetBankList() {
|
|||||||
tenantId, _ := c.Ctx.Input.GetData("tenantId").(int)
|
tenantId, _ := c.Ctx.Input.GetData("tenantId").(int)
|
||||||
keyword := c.GetString("keyword")
|
keyword := c.GetString("keyword")
|
||||||
page, _ := c.GetInt("page", 1)
|
page, _ := c.GetInt("page", 1)
|
||||||
pageSize, _ := c.GetInt("pageSize", 10)
|
pageSize, _ := c.GetInt("pageSize", 20)
|
||||||
list, total, err := services.GetExamQuestionBanks(services.BankListParams{
|
list, total, err := services.GetExamQuestionBanks(services.BankListParams{
|
||||||
TenantId: tenantId,
|
TenantId: tenantId,
|
||||||
Keyword: keyword,
|
Keyword: keyword,
|
||||||
@ -433,7 +433,22 @@ func (c *ExamQuestionBankController) GetBankList() {
|
|||||||
c.ServeJSON()
|
c.ServeJSON()
|
||||||
return
|
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()
|
c.ServeJSON()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,16 @@ type QuestionListParams struct {
|
|||||||
PageSize int
|
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 {
|
type QuestionWithMeta struct {
|
||||||
Question *models.ExamQuestion
|
Question *models.ExamQuestion
|
||||||
Options []*models.ExamQuestionOption
|
Options []*models.ExamQuestionOption
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user