增加了题库不允许重复的业务逻辑
This commit is contained in:
@@ -212,9 +212,22 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err
|
||||
return false, errors.New("新增失败")
|
||||
}
|
||||
|
||||
// 新增问答题库题目列表
|
||||
questionDao := dao.QuestionDao{}
|
||||
questionQaItemDao := dao.QuestionQaItemDao{}
|
||||
|
||||
var notQuestionIds []int64 // 处理需排除的题目id
|
||||
if req.IsRepeat == 1 {
|
||||
// 获取正常题库的明细列表
|
||||
maps := make(map[string]interface{})
|
||||
questionQaItems, _ := questionQaItemDao.GetAllNormalQuestionQaItemWhereList(maps)
|
||||
if len(questionQaItems) > 0 {
|
||||
for _, item := range questionQaItems {
|
||||
notQuestionIds = append(notQuestionIds, item.QuestionId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 新增问答题库题目列表
|
||||
for _, item := range req.QuestionQaItem {
|
||||
// 验证数量
|
||||
maps := make(map[string]interface{})
|
||||
@@ -231,7 +244,7 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err
|
||||
}
|
||||
|
||||
// 获取随机明细题目
|
||||
questions, err := questionDao.GetQuestionListRand(maps, item.Quantity)
|
||||
questions, err := questionDao.GetQuestionNotInListRand(maps, notQuestionIds, item.Quantity)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
@@ -404,6 +417,18 @@ func (r *QuestionQaService) PutQuestionQa(qaId int64, req requests.PutQuestionQa
|
||||
return false, err
|
||||
}
|
||||
|
||||
var notQuestionIds []int64 // 处理需排除的题目id
|
||||
if req.IsRepeat == 1 {
|
||||
// 获取正常题库的明细列表
|
||||
maps := make(map[string]interface{})
|
||||
questionQaItems, _ := questionQaItemDao.GetAllNormalQuestionQaItemWhereList(maps)
|
||||
if len(questionQaItems) > 0 {
|
||||
for _, item := range questionQaItems {
|
||||
notQuestionIds = append(notQuestionIds, item.QuestionId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, item := range req.QuestionQaItem {
|
||||
// 验证数量
|
||||
maps := make(map[string]interface{})
|
||||
@@ -420,7 +445,8 @@ func (r *QuestionQaService) PutQuestionQa(qaId int64, req requests.PutQuestionQa
|
||||
}
|
||||
|
||||
// 获取随机明细题目
|
||||
questions, err := questionDao.GetQuestionListRand(maps, item.Quantity)
|
||||
//questions, err := questionDao.GetQuestionListRand(maps, item.Quantity)
|
||||
questions, err := questionDao.GetQuestionNotInListRand(maps, notQuestionIds, item.Quantity)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
|
||||
Reference in New Issue
Block a user