package controller import ( "github.com/gin-gonic/gin" "knowledge/api/dao" "knowledge/api/dto" "knowledge/api/responses" ) type Static struct{} // GetStatic 获取统计数据 func (r *Static) GetStatic(c *gin.Context) { 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 } 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) }