This commit is contained in:
2024-09-27 10:58:05 +08:00
parent 65f3511ecb
commit ba6dbcc2c7
5 changed files with 85 additions and 14 deletions
+2 -2
View File
@@ -45,7 +45,7 @@ func (r *QuestionQa) GetQuestionQaPage(c *gin.Context) {
}
// 处理返回值
GetQuestionQaPageResponses := dto.GetQuestionQaListDto(questionQa)
g := dto.GetQuestionQaListDto(questionQa)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
@@ -55,7 +55,7 @@ func (r *QuestionQa) GetQuestionQaPage(c *gin.Context) {
result["page"] = req.Page
result["page_size"] = req.PageSize
result["total"] = total
result["data"] = GetQuestionQaPageResponses
result["data"] = g
responses.OkWithData(result, c)
}
+78 -5
View File
@@ -2,21 +2,94 @@ package controller
import (
"github.com/gin-gonic/gin"
"knowledge/api/dao"
"knowledge/api/dto"
"knowledge/api/responses"
"knowledge/api/service"
)
type Static struct{}
// GetStatic 获取统计数据
func (r *Static) GetStatic(c *gin.Context) {
// 业务处理
staticService := service.StaticService{}
getStaticResponses, err := staticService.GetStatic()
questionDao := dao.QuestionDao{}
// 处理返回值
var g []*dto.StaticDto
// 获取每个题目类型题目数量
maps := make(map[string]interface{})
maps["question_type"] = 1
maps["question_status"] = 1
maps["question_source"] = 1
total, err := questionDao.GetQuestionCount(maps)
response := &dto.StaticDto{
Name: "单选题",
Total: int(total),
}
g = append(g, response)
// 获取每个题目类型题目数量
maps = make(map[string]interface{})
maps["question_type"] = 2
maps["question_status"] = 1
maps["question_source"] = 1
total, err = questionDao.GetQuestionCount(maps)
response = &dto.StaticDto{
Name: "多选题",
Total: int(total),
}
g = append(g, response)
// 获取每个题目类型题目数量
maps = make(map[string]interface{})
maps["question_type"] = 3
maps["question_status"] = 1
maps["question_source"] = 1
total, err = questionDao.GetQuestionCount(maps)
response = &dto.StaticDto{
Name: "问答题",
Total: int(total),
}
g = append(g, response)
// 获取每个题目类型题目数量
maps = make(map[string]interface{})
maps["question_type"] = 4
maps["question_status"] = 1
maps["question_source"] = 1
total, err = questionDao.GetQuestionCount(maps)
response = &dto.StaticDto{
Name: "判断题",
Total: int(total),
}
g = append(g, response)
// 获取每个一级标签题目数量
labelDao := dao.LabelDao{}
maps = make(map[string]interface{})
maps["parent_id"] = 0
maps["label_level"] = 1
labels, err := labelDao.GetLabelList(maps)
if err != nil {
responses.FailWithMessage(err.Error(), c)
return
}
responses.OkWithData(getStaticResponses, c)
for _, label := range labels {
maps = make(map[string]interface{})
maps["question_status"] = 1
maps["question_source"] = 1
maps["first_label_id"] = label.LabelId
total, err = questionDao.GetQuestionCount(maps)
response = &dto.StaticDto{
Name: label.LabelName,
Total: int(total),
}
g = append(g, response)
}
responses.OkWithData(g, c)
}