增加了选题规则的判断
This commit is contained in:
@@ -205,6 +205,13 @@ 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{})
|
||||
@@ -221,7 +228,7 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err
|
||||
}
|
||||
|
||||
// 获取随机明细题目
|
||||
questions, err := questionDao.GetQuestionListRand(maps, item.Quantity)
|
||||
questions, err := questionDao.GetQuestionNotInListRand(maps, isInQaQuestionId, item.Quantity)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
@@ -243,9 +250,22 @@ 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{}
|
||||
@@ -786,6 +806,52 @@ 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) {
|
||||
// 题目总数量
|
||||
|
||||
Reference in New Issue
Block a user