94 lines
2.1 KiB
Go
94 lines
2.1 KiB
Go
package service
|
|
|
|
import (
|
|
"knowledge/api/dao"
|
|
"knowledge/api/dto"
|
|
)
|
|
|
|
type StaticService struct {
|
|
}
|
|
|
|
func (r *StaticService) GetStatic() (g []*dto.StaticDto, err error) {
|
|
questionDao := dao.QuestionDao{}
|
|
// 处理返回值
|
|
var responses []*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),
|
|
}
|
|
|
|
responses = append(responses, 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),
|
|
}
|
|
|
|
responses = append(responses, 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),
|
|
}
|
|
|
|
responses = append(responses, 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),
|
|
}
|
|
|
|
responses = append(responses, 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 {
|
|
return nil, err
|
|
}
|
|
|
|
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),
|
|
}
|
|
|
|
responses = append(responses, response)
|
|
}
|
|
|
|
return responses, nil
|
|
}
|