增加了获取题库时,非必选题目的规则,增加了题目的状态判断
This commit is contained in:
parent
b26c58f9fb
commit
066b3fd7a2
@ -91,24 +91,6 @@ func (r *QuestionQaItemDao) GetQuestionQaItemPreloadList(maps interface{}) (m []
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetQuestionQaItemPreloadListRand 获取列表-加载全部关联-随机
|
||||
func (r *QuestionQaItemDao) GetQuestionQaItemPreloadListRand(maps interface{}) (m []*model.QuestionQaItem, err error) {
|
||||
err = global.Db.Preload(clause.Associations).Where(maps).Order("rand()").Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetQuestionQaItemListRand 获取列表-随机
|
||||
func (r *QuestionQaItemDao) GetQuestionQaItemListRand(maps interface{}, limit int) (m []*model.QuestionQaItem, err error) {
|
||||
err = global.Db.Where(maps).Limit(limit).Order("rand()").Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// AddQuestionQaItem 新增
|
||||
func (r *QuestionQaItemDao) AddQuestionQaItem(tx *gorm.DB, model *model.QuestionQaItem) (*model.QuestionQaItem, error) {
|
||||
if err := tx.Create(model).Error; err != nil {
|
||||
@ -232,8 +214,8 @@ func (r *QuestionQaItemDao) GetQuestionQaItemPageSearch(req requests.GetQuestion
|
||||
return m, totalRecords, nil
|
||||
}
|
||||
|
||||
// GetQuestionQaItemWhereListRand 获取列表-随机
|
||||
func (r *QuestionQaItemDao) GetQuestionQaItemWhereListRand(maps interface{}, limit int) (m []*model.QuestionQaItem, err error) {
|
||||
// GetQuestionQaItemWhereList 获取列表
|
||||
func (r *QuestionQaItemDao) GetQuestionQaItemWhereList(maps interface{}) (m []*model.QuestionQaItem, err error) {
|
||||
query := global.Db.Model(&model.QuestionQaItem{})
|
||||
query = query.Where(maps)
|
||||
|
||||
@ -243,11 +225,64 @@ func (r *QuestionQaItemDao) GetQuestionQaItemWhereListRand(maps interface{}, lim
|
||||
query = query.Preload("Question.QuestionOption")
|
||||
|
||||
subQuery := global.Db.Model(&model.Question{}).
|
||||
Select("question_id").
|
||||
Where("kb_question.question_id = kb_question_qa_item.question_id").
|
||||
Where("question_status = ?", 1).
|
||||
Where("is_delete = ?", 0)
|
||||
Where("is_delete = ?", 0).
|
||||
Select("1")
|
||||
|
||||
query = query.Where(gorm.Expr("question_id IN (?)", subQuery))
|
||||
query = query.Where("EXISTS (?)", subQuery)
|
||||
|
||||
err = query.Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetQuestionQaItemWhereListRand 获取列表-随机
|
||||
func (r *QuestionQaItemDao) GetQuestionQaItemWhereListRand(maps interface{}) (m []*model.QuestionQaItem, err error) {
|
||||
query := global.Db.Model(&model.QuestionQaItem{})
|
||||
query = query.Where(maps)
|
||||
|
||||
query = query.Preload("Question")
|
||||
|
||||
// 选项
|
||||
query = query.Preload("Question.QuestionOption")
|
||||
|
||||
subQuery := global.Db.Model(&model.Question{}).
|
||||
Where("kb_question.question_id = kb_question_qa_item.question_id").
|
||||
Where("question_status = ?", 1).
|
||||
Where("is_delete = ?", 0).
|
||||
Select("1")
|
||||
|
||||
query = query.Where("EXISTS (?)", subQuery)
|
||||
|
||||
query = query.Order("rand()")
|
||||
|
||||
err = query.Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetQuestionQaItemWhereListRandLimit 获取列表-随机-限制数量
|
||||
func (r *QuestionQaItemDao) GetQuestionQaItemWhereListRandLimit(maps interface{}, limit int) (m []*model.QuestionQaItem, err error) {
|
||||
query := global.Db.Model(&model.QuestionQaItem{})
|
||||
query = query.Where(maps)
|
||||
|
||||
query = query.Preload("Question")
|
||||
|
||||
// 选项
|
||||
query = query.Preload("Question.QuestionOption")
|
||||
|
||||
subQuery := global.Db.Model(&model.Question{}).
|
||||
Where("kb_question.question_id = kb_question_qa_item.question_id").
|
||||
Where("question_status = ?", 1).
|
||||
Where("is_delete = ?", 0).
|
||||
Select("1")
|
||||
|
||||
query = query.Where("EXISTS (?)", subQuery)
|
||||
|
||||
query = query.Limit(limit).Order("rand()")
|
||||
|
||||
|
||||
@ -873,7 +873,7 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeOne(questionQa *model.Quest
|
||||
maps = make(map[string]interface{})
|
||||
maps["qa_id"] = questionQa.QaId
|
||||
maps["is_must_select"] = 0
|
||||
questionQaItems, err = questionQaItemDao.GetQuestionQaItemWhereListRand(maps, remainingQuantity)
|
||||
questionQaItems, err = questionQaItemDao.GetQuestionQaItemWhereListRandLimit(maps, remainingQuantity)
|
||||
if err == nil && len(questionQaItems) > 0 {
|
||||
for _, item := range questionQaItems {
|
||||
questions = append(questions, item.Question)
|
||||
@ -882,19 +882,11 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeOne(questionQa *model.Quest
|
||||
}
|
||||
|
||||
for _, v := range questions {
|
||||
questionOptionDao := dao.QuestionOptionDao{}
|
||||
maps = make(map[string]interface{})
|
||||
maps["question_id"] = v.QuestionId
|
||||
questionOption, err := questionOptionDao.GetQuestionOptionList(maps)
|
||||
if err != nil {
|
||||
return g, errors.New("内部错误")
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
questionDto := dto.GetShareQuestionDto(v)
|
||||
|
||||
// 加载选项
|
||||
questionDto.LoadQuestionOptionSimplify(questionOption)
|
||||
questionDto.LoadQuestionOptionSimplify(v.QuestionOption)
|
||||
|
||||
// 加载图片
|
||||
questionDto.LoadQuestionImage(v.QuestionImage)
|
||||
@ -937,13 +929,13 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeTwo(questionQa *model.Quest
|
||||
maps := make(map[string]interface{})
|
||||
maps["qa_id"] = questionQa.QaId
|
||||
maps["is_must_select"] = 1
|
||||
mustQuestions, err := questionQaItemDao.GetQuestionQaItemPreloadList(maps)
|
||||
mustQuestions, err := questionQaItemDao.GetQuestionQaItemWhereList(maps)
|
||||
|
||||
// 题目数据-未比被选中
|
||||
maps = make(map[string]interface{})
|
||||
maps["qa_id"] = questionQa.QaId
|
||||
maps["is_must_select"] = 0
|
||||
notMustQuestions, err := questionQaItemDao.GetQuestionQaItemPreloadListRand(maps)
|
||||
notMustQuestions, err := questionQaItemDao.GetQuestionQaItemWhereListRand(maps)
|
||||
|
||||
// json转结构体-飞花令题目数量规则
|
||||
var tokenQuestionContents []tokenQuestionContent
|
||||
@ -972,7 +964,7 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeTwo(questionQa *model.Quest
|
||||
for _, v2 := range tokenQuestionContents {
|
||||
// 必选数据
|
||||
for _, v3 := range mustQuestions {
|
||||
// 此处标识已用过
|
||||
// 判断此题目是否已被选中
|
||||
if utils.IsInSlice(v3.QuestionId, isUseQuestionId) {
|
||||
continue
|
||||
}
|
||||
@ -996,7 +988,7 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeTwo(questionQa *model.Quest
|
||||
if remainingQuantity > 0 {
|
||||
// 非必选数据
|
||||
for _, v3 := range notMustQuestions {
|
||||
// 此处标识已用过
|
||||
// 判断此题目是否已被选中
|
||||
if utils.IsInSlice(v3.QuestionId, isUseQuestionId) {
|
||||
continue
|
||||
}
|
||||
@ -1022,19 +1014,11 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeTwo(questionQa *model.Quest
|
||||
|
||||
// 处理数据
|
||||
for i2, v2 := range questions {
|
||||
questionOptionDao := dao.QuestionOptionDao{}
|
||||
maps = make(map[string]interface{})
|
||||
maps["question_id"] = v2.QuestionId
|
||||
questionOption, err := questionOptionDao.GetQuestionOptionList(maps)
|
||||
if err != nil {
|
||||
return g, errors.New("内部错误")
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
questionDto := dto.GetShareQuestionDto(v2)
|
||||
|
||||
// 加载选项
|
||||
questionDto.LoadQuestionOptionSimplify(questionOption)
|
||||
questionDto.LoadQuestionOptionSimplify(v2.QuestionOption)
|
||||
|
||||
// 加载图片
|
||||
questionDto.LoadQuestionImage(v2.QuestionImage)
|
||||
@ -1072,7 +1056,7 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeThree(questionQa *model.Que
|
||||
maps = make(map[string]interface{})
|
||||
maps["qa_id"] = questionQa.QaId
|
||||
maps["is_must_select"] = 0
|
||||
notMustQuestions, err := questionQaItemDao.GetQuestionQaItemPreloadListRand(maps)
|
||||
notMustQuestions, err := questionQaItemDao.GetQuestionQaItemWhereListRand(maps)
|
||||
|
||||
// json转结构体-飞花令题目数量规则
|
||||
var tokenQuestionContents []tokenQuestionContent
|
||||
@ -1115,7 +1099,7 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeThree(questionQa *model.Que
|
||||
|
||||
// 必选数据
|
||||
for _, v3 := range mustQuestions {
|
||||
// 此处标识已用过
|
||||
// 判断此题目是否已被选中
|
||||
if utils.IsInSlice(v3.QuestionId, isUseQuestionId) {
|
||||
continue
|
||||
}
|
||||
@ -1139,7 +1123,7 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeThree(questionQa *model.Que
|
||||
if remainingQuantity > 0 {
|
||||
// 非必选数据
|
||||
for _, v3 := range notMustQuestions {
|
||||
// 此处标识已用过
|
||||
// 判断此题目是否已被选中
|
||||
if utils.IsInSlice(v3.QuestionId, isUseQuestionId) {
|
||||
continue
|
||||
}
|
||||
@ -1164,19 +1148,11 @@ func (r *QuestionQaService) GetShareQuestionQaForTypeThree(questionQa *model.Que
|
||||
|
||||
// 处理数据
|
||||
for _, v3 := range questions {
|
||||
questionOptionDao := dao.QuestionOptionDao{}
|
||||
maps = make(map[string]interface{})
|
||||
maps["question_id"] = v3.QuestionId
|
||||
questionOption, err := questionOptionDao.GetQuestionOptionList(maps)
|
||||
if err != nil {
|
||||
return g, errors.New("内部错误1")
|
||||
}
|
||||
|
||||
// 处理返回值
|
||||
questionDto := dto.GetShareQuestionDto(v3)
|
||||
|
||||
// 加载选项
|
||||
questionDto.LoadQuestionOptionSimplify(questionOption)
|
||||
questionDto.LoadQuestionOptionSimplify(v3.QuestionOption)
|
||||
|
||||
// 加载图片
|
||||
questionDto.LoadQuestionImage(v3.QuestionImage)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user