diff --git a/api/controller/questionQa.go b/api/controller/questionQa.go index b305d26..d822eb0 100644 --- a/api/controller/questionQa.go +++ b/api/controller/questionQa.go @@ -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) } diff --git a/api/controller/static.go b/api/controller/static.go index 100585b..37dd466 100644 --- a/api/controller/static.go +++ b/api/controller/static.go @@ -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) } diff --git a/api/crontab/questionQaExpire.go b/api/crontab/questionQaExpire.go index b226a6e..d18dda5 100644 --- a/api/crontab/questionQaExpire.go +++ b/api/crontab/questionQaExpire.go @@ -16,19 +16,17 @@ func HandleQuestionQaExpire() { maps := make(map[string]interface{}) maps["qa_status"] = 1 - now := time.Now() // 当前时间 + now := time.Now() endTime := now.Format("2006-01-02 15:04") // 今天开始时间 year, month, day := now.Date() location := now.Location() startTime := time.Date(year, month, day, 00, 00, 00, 0, location).Format("2006-01-02 15:04") - questionQas, err := questionQaDao.GetQuestionQaListByQaExpireTime(maps, startTime, endTime) if err == nil && len(questionQas) > 0 { for _, qa := range questionQas { - // 检测状态 if qa.QaStatus == 2 { continue diff --git a/api/dto/QuestionQa.go b/api/dto/QuestionQa.go index 4435adc..80ca6d4 100644 --- a/api/dto/QuestionQa.go +++ b/api/dto/QuestionQa.go @@ -15,7 +15,7 @@ type QuestionQaDto struct { QaStatus int `json:"qa_status"` // 状态(1:正常 2:无效) QaRuleContent string `json:"qa_rule_content"` // 规则解释 QaDisplayType int `json:"qa_display_type"` // 展示类型(1:常规 2:飞花令) - QaExpireTime model.LocalTime `json:"qa_expire_time"` // 过期时间 + QaExpireTime *model.LocalTime `json:"qa_expire_time"` // 过期时间 QaShareId string `json:"qa_share_id"` // 分享标识 QaPassword string `json:"qa_password"` // 分享密码 OpenNumber int `json:"open_number"` // 打开的次数 @@ -48,7 +48,7 @@ func GetQuestionQaListDto(m []*model.QuestionQa) []*QuestionQaDto { QaStatus: v.QaStatus, QaRuleContent: v.QaRuleContent, QaDisplayType: v.QaDisplayType, - QaExpireTime: v.QaExpireTime, + QaExpireTime: &v.QaExpireTime, QaShareId: utils.AddDomain(v.QaShareId), Image: utils.AddOssDomain(v.Image), OpenNumber: v.OpenNumber, @@ -73,7 +73,7 @@ func GetQuestionQaDto(m *model.QuestionQa) *QuestionQaDto { QaStatus: m.QaStatus, QaRuleContent: m.QaRuleContent, QaDisplayType: m.QaDisplayType, - QaExpireTime: m.QaExpireTime, + QaExpireTime: &m.QaExpireTime, QaShareId: utils.AddDomain(m.QaShareId), OpenNumber: m.OpenNumber, Image: utils.AddOssDomain(m.Image), diff --git a/api/dto/Static.go b/api/dto/Static.go index 5ce55f2..ec7a426 100644 --- a/api/dto/Static.go +++ b/api/dto/Static.go @@ -25,7 +25,7 @@ func GetStaticListDto(m []*model.QuestionQa) []*QuestionQaDto { QaStatus: v.QaStatus, QaRuleContent: v.QaRuleContent, QaDisplayType: v.QaDisplayType, - QaExpireTime: v.QaExpireTime, + QaExpireTime: &v.QaExpireTime, QaShareId: utils.AddDomain(v.QaShareId), Image: utils.AddOssDomain(v.Image), OpenNumber: v.OpenNumber,