diff --git a/api/service/QuestionQa.go b/api/service/QuestionQa.go index efee227..f85bc31 100644 --- a/api/service/QuestionQa.go +++ b/api/service/QuestionQa.go @@ -205,13 +205,6 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err // 新增问答题库题目列表 questionDao := dao.QuestionDao{} questionQaItemDao := dao.QuestionQaItemDao{} - - // 已入题库题目id - var isInQaQuestionId []int64 - - // 已入题库题目数量 - var isInQaQuestionQuantity int - for _, item := range req.QuestionQaItem { // 验证数量 maps := make(map[string]interface{}) @@ -228,7 +221,7 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err } // 获取随机明细题目 - questions, err := questionDao.GetQuestionNotInListRand(maps, isInQaQuestionId, item.Quantity) + questions, err := questionDao.GetQuestionListRand(maps, item.Quantity) if err != nil { tx.Rollback() return false, err @@ -236,7 +229,7 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err if len(questions) < item.Quantity { tx.Rollback() - return false, errors.New("选题超出可选择题目数量") + return false, errors.New(utils.QuestionType(item.QuestionType) + "数量不足") } // 新增明细题目 @@ -250,22 +243,9 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err tx.Rollback() return false, errors.New("新增失败") } - - // 新增到已入题库题目id - isInQaQuestionId = append(isInQaQuestionId, question.QuestionId) - - // 新增到 - isInQaQuestionQuantity += 1 } } - // 检测题库已增加题目数量-新增 - err = r.CheckAddedQaQuestionQuantity(req, isInQaQuestionQuantity) - if err != nil { - tx.Rollback() - return false, err - } - // 新增计时设置 if req.IsTurnTimer == 1 { questionQaTimerDao := dao.QuestionQaTimerDao{} @@ -806,52 +786,6 @@ func (r *QuestionQaService) CheckAddQaQuestionQuantity(req requests.AddQuestionQ return qaQuantity, nil } -// CheckAddedQaQuestionQuantity 检测题库已增加题目数量-新增 -func (r *QuestionQaService) CheckAddedQaQuestionQuantity(req requests.AddQuestionQa, itemQuantity int) (err error) { - // 题目总数量 - qaQuantity := req.QaQuantity - - // 常规模式 - if req.QaType == 1 { - // 总数量 需大于 选择的明细数量 - if qaQuantity > itemQuantity { - return errors.New("存在重复选题,经计算可选择数量不满足题库所需题目总数量") - } - } - - // 固定套题模式 - if req.QaType == 2 { - // 计算飞花令题目数量 - tokenQuestionQuantity := 0 - for _, content := range req.TokenQuestionContent { - tokenQuestionQuantity = tokenQuestionQuantity + content.Quantity - } - - // 总数量 = 飞花令题目数量 * 飞花令数量 - qaQuantity = tokenQuestionQuantity * *req.TokenNum - if qaQuantity > itemQuantity { - return errors.New("存在重复选题,经计算可选择数量不满足题库所需题目总数量") - } - } - - // 多轮固定题型模式 - if req.QaType == 3 { - // 计算飞花令题目数量 - tokenQuestionQuantity := 0 - for _, content := range req.TokenQuestionContent { - tokenQuestionQuantity = tokenQuestionQuantity + content.Quantity - } - - // 总数量 = 飞花令题目数量 * 飞花令数量 * 轮次 - qaQuantity = tokenQuestionQuantity * *req.TokenNum * *req.RoundNum - if qaQuantity > itemQuantity { - return errors.New("存在重复选题,经计算可选择数量不满足题库所需题目总数量") - } - } - - return nil -} - // CheckPutQaQuestionQuantity 检测题库题目数量-修改 func (r *QuestionQaService) CheckPutQaQuestionQuantity(req requests.PutQuestionQa) (qaQuantity int, err error) { // 题目总数量