修改标签
This commit is contained in:
parent
44818c206b
commit
34c9bb3215
@ -45,13 +45,39 @@ func (r *Question) GetQuestionPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理返回值
|
// 处理返回值
|
||||||
GetQuestionPageResponses := dto.GetQuestionListDto(question)
|
g := dto.GetQuestionListDto(question)
|
||||||
|
|
||||||
|
for _, v := range g {
|
||||||
|
// 加载一级标签
|
||||||
|
if v.FirstLabelId != nil {
|
||||||
|
labelDao := dao.LabelDao{}
|
||||||
|
firstLabel, err := labelDao.GetLabelFirstById(*v.FirstLabelId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
v.LoadFirstLabel(firstLabel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载二级标签
|
||||||
|
if v.SecondLabelId != nil {
|
||||||
|
labelDao := dao.LabelDao{}
|
||||||
|
secondLabel, err := labelDao.GetLabelFirstById(*v.SecondLabelId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
v.LoadSecondLabel(secondLabel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
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"] = GetQuestionPageResponses
|
result["data"] = g
|
||||||
responses.OkWithData(result, c)
|
responses.OkWithData(result, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,13 +98,13 @@ func (r *Question) GetQuestion(c *gin.Context) {
|
|||||||
|
|
||||||
// 业务处理
|
// 业务处理
|
||||||
questionService := service.QuestionService{}
|
questionService := service.QuestionService{}
|
||||||
getQuestionResponses, err := questionService.GetQuestion(questionId)
|
g, err := questionService.GetQuestion(questionId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
responses.OkWithData(getQuestionResponses, c)
|
responses.OkWithData(g, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddQuestion 新增题目
|
// AddQuestion 新增题目
|
||||||
|
|||||||
@ -45,17 +45,39 @@ func (r *QuestionQaItem) GetQuestionQaItemPage(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 处理返回值
|
// 处理返回值
|
||||||
questionQaItemPageResponses := dto.GetQuestionQaItemListDto(questionQaItem)
|
g := dto.GetQuestionQaItemListDto(questionQaItem)
|
||||||
|
|
||||||
|
for _, v := range g {
|
||||||
|
// 加载一级标签
|
||||||
|
if v.Question.FirstLabelId != nil {
|
||||||
|
labelDao := dao.LabelDao{}
|
||||||
|
firstLabel, err := labelDao.GetLabelFirstById(*v.Question.FirstLabelId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
responses.FailWithMessage(err.Error(), c)
|
responses.FailWithMessage(err.Error(), c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v.LoadFirstLabel(firstLabel)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 加载二级标签
|
||||||
|
if v.Question.SecondLabelId != nil {
|
||||||
|
labelDao := dao.LabelDao{}
|
||||||
|
secondLabel, err := labelDao.GetLabelFirstById(*v.Question.SecondLabelId)
|
||||||
|
if err != nil {
|
||||||
|
responses.FailWithMessage(err.Error(), c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
v.LoadSecondLabel(secondLabel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result := make(map[string]interface{})
|
result := make(map[string]interface{})
|
||||||
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"] = questionQaItemPageResponses
|
result["data"] = g
|
||||||
responses.OkWithData(result, c)
|
responses.OkWithData(result, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -118,16 +118,6 @@ func (r *QuestionDao) GetQuestionPageSearch(req requests.GetQuestionPage, page,
|
|||||||
// 构建查询条件
|
// 构建查询条件
|
||||||
query := global.Db.Model(&model.Question{})
|
query := global.Db.Model(&model.Question{})
|
||||||
|
|
||||||
// 一级标签
|
|
||||||
query = query.Preload("FirstLabel", func(db *gorm.DB) *gorm.DB {
|
|
||||||
return db.Select("label_id", "label_name")
|
|
||||||
})
|
|
||||||
|
|
||||||
// 二级标签
|
|
||||||
query = query.Preload("SecondLabel", func(db *gorm.DB) *gorm.DB {
|
|
||||||
return db.Select("label_id", "label_name")
|
|
||||||
})
|
|
||||||
|
|
||||||
// 主键id
|
// 主键id
|
||||||
if req.QuestionId != "" {
|
if req.QuestionId != "" {
|
||||||
query = query.Where("question_id = ?", req.QuestionId)
|
query = query.Where("question_id = ?", req.QuestionId)
|
||||||
|
|||||||
@ -129,16 +129,6 @@ func (r *QuestionQaItemDao) GetQuestionQaItemPageSearch(req requests.GetQuestion
|
|||||||
return db.Select("question_id", "question_name", "question_type", "question_source", "difficulty", "first_label_id", "second_label_id")
|
return db.Select("question_id", "question_name", "question_type", "question_source", "difficulty", "first_label_id", "second_label_id")
|
||||||
})
|
})
|
||||||
|
|
||||||
// 一级标签
|
|
||||||
query = query.Preload("Question.FirstLabel", func(db *gorm.DB) *gorm.DB {
|
|
||||||
return db.Select("label_id", "label_name")
|
|
||||||
})
|
|
||||||
|
|
||||||
// 二级标签
|
|
||||||
query = query.Preload("Question.SecondLabel", func(db *gorm.DB) *gorm.DB {
|
|
||||||
return db.Select("label_id", "label_name")
|
|
||||||
})
|
|
||||||
|
|
||||||
// 题库id
|
// 题库id
|
||||||
query = query.Where("qa_id = ?", req.QaId)
|
query = query.Where("qa_id = ?", req.QaId)
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,8 @@ type QuestionDto struct {
|
|||||||
QuestionAnswer []string `json:"question_answer"` // 答案
|
QuestionAnswer []string `json:"question_answer"` // 答案
|
||||||
QuestionAnalysis string `json:"question_analysis"` // 解析
|
QuestionAnalysis string `json:"question_analysis"` // 解析
|
||||||
Difficulty int `json:"difficulty"` // 难度(0:未知 1:低 2:中 3:高)
|
Difficulty int `json:"difficulty"` // 难度(0:未知 1:低 2:中 3:高)
|
||||||
|
FirstLabelId *int64 `json:"first_label_id"` // 一级标签id
|
||||||
|
SecondLabelId *int64 `json:"second_label_id"` // 二级标签id
|
||||||
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
CreatedAt model.LocalTime `json:"created_at"` // 创建时间
|
||||||
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
|
||||||
FirstLabel *LabelDto `json:"first_label"` // 一级标签
|
FirstLabel *LabelDto `json:"first_label"` // 一级标签
|
||||||
@ -39,6 +41,8 @@ func GetQuestionDto(m *model.Question) *QuestionDto {
|
|||||||
QuestionAnswer: []string{},
|
QuestionAnswer: []string{},
|
||||||
QuestionAnalysis: m.QuestionAnalysis,
|
QuestionAnalysis: m.QuestionAnalysis,
|
||||||
Difficulty: m.Difficulty,
|
Difficulty: m.Difficulty,
|
||||||
|
FirstLabelId: m.FirstLabelId,
|
||||||
|
SecondLabelId: m.SecondLabelId,
|
||||||
CreatedAt: m.CreatedAt,
|
CreatedAt: m.CreatedAt,
|
||||||
UpdatedAt: m.UpdatedAt,
|
UpdatedAt: m.UpdatedAt,
|
||||||
}
|
}
|
||||||
@ -62,20 +66,12 @@ func GetQuestionListDto(m []*model.Question) []*QuestionDto {
|
|||||||
QuestionAnswer: []string{},
|
QuestionAnswer: []string{},
|
||||||
QuestionAnalysis: v.QuestionAnalysis,
|
QuestionAnalysis: v.QuestionAnalysis,
|
||||||
Difficulty: v.Difficulty,
|
Difficulty: v.Difficulty,
|
||||||
|
FirstLabelId: v.FirstLabelId,
|
||||||
|
SecondLabelId: v.SecondLabelId,
|
||||||
CreatedAt: v.CreatedAt,
|
CreatedAt: v.CreatedAt,
|
||||||
UpdatedAt: v.UpdatedAt,
|
UpdatedAt: v.UpdatedAt,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载一级标签
|
|
||||||
if v.FirstLabel != nil {
|
|
||||||
response = response.LoadFirstLabel(v.FirstLabel)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载二级标签
|
|
||||||
if v.SecondLabel != nil {
|
|
||||||
response = response.LoadSecondLabel(v.SecondLabel)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载图片
|
// 加载图片
|
||||||
if v.QuestionImage != "" {
|
if v.QuestionImage != "" {
|
||||||
response = response.LoadQuestionImage(v.QuestionImage)
|
response = response.LoadQuestionImage(v.QuestionImage)
|
||||||
|
|||||||
@ -51,15 +51,15 @@ func GetQuestionQaItemListDto(m []*model.QuestionQaItem) []*QuestionQaItemDto {
|
|||||||
response = response.LoadQuestion(v.Question)
|
response = response.LoadQuestion(v.Question)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载一级标签
|
//// 加载一级标签
|
||||||
if v.Question.FirstLabel != nil {
|
//if v.Question.FirstLabel != nil {
|
||||||
response = response.LoadFirstLabel(v.Question.FirstLabel)
|
// response = response.LoadFirstLabel(v.Question.FirstLabel)
|
||||||
}
|
//}
|
||||||
|
//
|
||||||
// 加载二级标签
|
//// 加载二级标签
|
||||||
if v.Question.SecondLabel != nil {
|
//if v.Question.SecondLabel != nil {
|
||||||
response = response.LoadSecondLabel(v.Question.SecondLabel)
|
// response = response.LoadSecondLabel(v.Question.SecondLabel)
|
||||||
}
|
//}
|
||||||
|
|
||||||
// 将转换后的结构体添加到新切片中
|
// 将转换后的结构体添加到新切片中
|
||||||
responses[i] = response
|
responses[i] = response
|
||||||
|
|||||||
@ -21,8 +21,6 @@ type Question struct {
|
|||||||
FirstLabelId *int64 `gorm:"column:first_label_id;type:bigint(19);comment:一级标签id" json:"first_label_id"`
|
FirstLabelId *int64 `gorm:"column:first_label_id;type:bigint(19);comment:一级标签id" json:"first_label_id"`
|
||||||
SecondLabelId *int64 `gorm:"column:second_label_id;type:bigint(19);comment:二级标签id" json:"second_label_id"`
|
SecondLabelId *int64 `gorm:"column:second_label_id;type:bigint(19);comment:二级标签id" json:"second_label_id"`
|
||||||
Model
|
Model
|
||||||
FirstLabel *Label `gorm:"foreignKey:FirstLabelId;references:label_id" json:"first_label"`
|
|
||||||
SecondLabel *Label `gorm:"foreignKey:SecondLabelId;references:label_id" json:"second_label"`
|
|
||||||
QuestionOption []*QuestionOption `gorm:"foreignKey:QuestionId;references:question_id" json:"question_option"`
|
QuestionOption []*QuestionOption `gorm:"foreignKey:QuestionId;references:question_id" json:"question_option"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -807,10 +807,26 @@ func (r *QuestionService) GetQuestion(questionId int64) (g *dto.QuestionDto, err
|
|||||||
g = dto.GetQuestionDto(question)
|
g = dto.GetQuestionDto(question)
|
||||||
|
|
||||||
// 加载一级标签
|
// 加载一级标签
|
||||||
g.LoadFirstLabel(question.FirstLabel)
|
if question.FirstLabelId != nil {
|
||||||
|
labelDao := dao.LabelDao{}
|
||||||
|
firstLabel, err := labelDao.GetLabelFirstById(*question.FirstLabelId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("题目标签存在错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
g.LoadFirstLabel(firstLabel)
|
||||||
|
}
|
||||||
|
|
||||||
// 加载二级标签
|
// 加载二级标签
|
||||||
g.LoadSecondLabel(question.SecondLabel)
|
if question.SecondLabelId != nil {
|
||||||
|
labelDao := dao.LabelDao{}
|
||||||
|
secondLabel, err := labelDao.GetLabelFirstById(*question.SecondLabelId)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.New("题目标签存在错误")
|
||||||
|
}
|
||||||
|
|
||||||
|
g.LoadSecondLabel(secondLabel)
|
||||||
|
}
|
||||||
|
|
||||||
// 加载选项
|
// 加载选项
|
||||||
g.LoadQuestionOption(question.QuestionOption)
|
g.LoadQuestionOption(question.QuestionOption)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user