2222
This commit is contained in:
parent
65f3511ecb
commit
ba6dbcc2c7
@ -45,7 +45,7 @@ func (r *QuestionQa) GetQuestionQaPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理返回值
|
// 处理返回值
|
||||||
GetQuestionQaPageResponses := dto.GetQuestionQaListDto(questionQa)
|
g := dto.GetQuestionQaListDto(questionQa)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
@ -55,7 +55,7 @@ func (r *QuestionQa) GetQuestionQaPage(c *gin.Context) {
|
|||||||
result["page"] = req.Page
|
result["page"] = req.Page
|
||||||
result["page_size"] = req.PageSize
|
result["page_size"] = req.PageSize
|
||||||
result["total"] = total
|
result["total"] = total
|
||||||
result["data"] = GetQuestionQaPageResponses
|
result["data"] = g
|
||||||
responses.OkWithData(result, c)
|
responses.OkWithData(result, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,21 +2,94 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"knowledge/api/dao"
|
||||||
|
"knowledge/api/dto"
|
||||||
"knowledge/api/responses"
|
"knowledge/api/responses"
|
||||||
"knowledge/api/service"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Static struct{}
|
type Static struct{}
|
||||||
|
|
||||||
// GetStatic 获取统计数据
|
// GetStatic 获取统计数据
|
||||||
func (r *Static) GetStatic(c *gin.Context) {
|
func (r *Static) GetStatic(c *gin.Context) {
|
||||||
// 业务处理
|
questionDao := dao.QuestionDao{}
|
||||||
staticService := service.StaticService{}
|
// 处理返回值
|
||||||
getStaticResponses, err := staticService.GetStatic()
|
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 {
|
if err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,19 +16,17 @@ func HandleQuestionQaExpire() {
|
|||||||
maps := make(map[string]interface{})
|
maps := make(map[string]interface{})
|
||||||
maps["qa_status"] = 1
|
maps["qa_status"] = 1
|
||||||
|
|
||||||
now := time.Now()
|
|
||||||
// 当前时间
|
// 当前时间
|
||||||
|
now := time.Now()
|
||||||
endTime := now.Format("2006-01-02 15:04")
|
endTime := now.Format("2006-01-02 15:04")
|
||||||
|
|
||||||
// 今天开始时间
|
// 今天开始时间
|
||||||
year, month, day := now.Date()
|
year, month, day := now.Date()
|
||||||
location := now.Location()
|
location := now.Location()
|
||||||
startTime := time.Date(year, month, day, 00, 00, 00, 0, location).Format("2006-01-02 15:04")
|
startTime := time.Date(year, month, day, 00, 00, 00, 0, location).Format("2006-01-02 15:04")
|
||||||
|
|
||||||
questionQas, err := questionQaDao.GetQuestionQaListByQaExpireTime(maps, startTime, endTime)
|
questionQas, err := questionQaDao.GetQuestionQaListByQaExpireTime(maps, startTime, endTime)
|
||||||
if err == nil && len(questionQas) > 0 {
|
if err == nil && len(questionQas) > 0 {
|
||||||
for _, qa := range questionQas {
|
for _, qa := range questionQas {
|
||||||
|
|
||||||
// 检测状态
|
// 检测状态
|
||||||
if qa.QaStatus == 2 {
|
if qa.QaStatus == 2 {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -15,7 +15,7 @@ type QuestionQaDto struct {
|
|||||||
QaStatus int `json:"qa_status"` // 状态(1:正常 2:无效)
|
QaStatus int `json:"qa_status"` // 状态(1:正常 2:无效)
|
||||||
QaRuleContent string `json:"qa_rule_content"` // 规则解释
|
QaRuleContent string `json:"qa_rule_content"` // 规则解释
|
||||||
QaDisplayType int `json:"qa_display_type"` // 展示类型(1:常规 2:飞花令)
|
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"` // 分享标识
|
QaShareId string `json:"qa_share_id"` // 分享标识
|
||||||
QaPassword string `json:"qa_password"` // 分享密码
|
QaPassword string `json:"qa_password"` // 分享密码
|
||||||
OpenNumber int `json:"open_number"` // 打开的次数
|
OpenNumber int `json:"open_number"` // 打开的次数
|
||||||
@ -48,7 +48,7 @@ func GetQuestionQaListDto(m []*model.QuestionQa) []*QuestionQaDto {
|
|||||||
QaStatus: v.QaStatus,
|
QaStatus: v.QaStatus,
|
||||||
QaRuleContent: v.QaRuleContent,
|
QaRuleContent: v.QaRuleContent,
|
||||||
QaDisplayType: v.QaDisplayType,
|
QaDisplayType: v.QaDisplayType,
|
||||||
QaExpireTime: v.QaExpireTime,
|
QaExpireTime: &v.QaExpireTime,
|
||||||
QaShareId: utils.AddDomain(v.QaShareId),
|
QaShareId: utils.AddDomain(v.QaShareId),
|
||||||
Image: utils.AddOssDomain(v.Image),
|
Image: utils.AddOssDomain(v.Image),
|
||||||
OpenNumber: v.OpenNumber,
|
OpenNumber: v.OpenNumber,
|
||||||
@ -73,7 +73,7 @@ func GetQuestionQaDto(m *model.QuestionQa) *QuestionQaDto {
|
|||||||
QaStatus: m.QaStatus,
|
QaStatus: m.QaStatus,
|
||||||
QaRuleContent: m.QaRuleContent,
|
QaRuleContent: m.QaRuleContent,
|
||||||
QaDisplayType: m.QaDisplayType,
|
QaDisplayType: m.QaDisplayType,
|
||||||
QaExpireTime: m.QaExpireTime,
|
QaExpireTime: &m.QaExpireTime,
|
||||||
QaShareId: utils.AddDomain(m.QaShareId),
|
QaShareId: utils.AddDomain(m.QaShareId),
|
||||||
OpenNumber: m.OpenNumber,
|
OpenNumber: m.OpenNumber,
|
||||||
Image: utils.AddOssDomain(m.Image),
|
Image: utils.AddOssDomain(m.Image),
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func GetStaticListDto(m []*model.QuestionQa) []*QuestionQaDto {
|
|||||||
QaStatus: v.QaStatus,
|
QaStatus: v.QaStatus,
|
||||||
QaRuleContent: v.QaRuleContent,
|
QaRuleContent: v.QaRuleContent,
|
||||||
QaDisplayType: v.QaDisplayType,
|
QaDisplayType: v.QaDisplayType,
|
||||||
QaExpireTime: v.QaExpireTime,
|
QaExpireTime: &v.QaExpireTime,
|
||||||
QaShareId: utils.AddDomain(v.QaShareId),
|
QaShareId: utils.AddDomain(v.QaShareId),
|
||||||
Image: utils.AddOssDomain(v.Image),
|
Image: utils.AddOssDomain(v.Image),
|
||||||
OpenNumber: v.OpenNumber,
|
OpenNumber: v.OpenNumber,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user