新增了 检测题目关联的题库数量是否充足-减去对应数量后
This commit is contained in:
@@ -872,6 +872,14 @@ func (r *QuestionService) DeleteQuestion(req requests.DeleteQuestion) (bool, err
|
||||
return false, errors.New("题目不存在")
|
||||
}
|
||||
|
||||
// 检测题目关联的题库数量是否充足-减去对应数量后
|
||||
questionQaService := QuestionQaService{}
|
||||
res, err := questionQaService.CheckQuestionRelationQaQuantitySub(questionId, 1)
|
||||
if res == false {
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 删除选项
|
||||
err = questionOptionDao.DeleteQuestionOptionByQuestionId(tx, questionId)
|
||||
if err != nil {
|
||||
|
||||
@@ -1323,3 +1323,34 @@ func (r *QuestionQaService) CheckQuestionQaItemRepeat(items []*requests.Question
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// CheckQuestionRelationQaQuantitySub 检测题目关联的题库数量是否充足-减去对应数量后
|
||||
func (r *QuestionQaService) CheckQuestionRelationQaQuantitySub(questionId int64, num int) (bool, error) {
|
||||
// 获取关联题库id
|
||||
questionQaItemDao := dao.QuestionQaItemDao{}
|
||||
questionQaItems, err := questionQaItemDao.GetQuestionQaItemListByQuestionIdDistinctQaId(questionId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
questionQaDao := dao.QuestionQaDao{}
|
||||
for _, item := range questionQaItems {
|
||||
// 获取题库数据
|
||||
questionQa, err := questionQaDao.GetQuestionQaById(item.QaId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 获取明细数据
|
||||
questionQaItems, err = questionQaItemDao.GetQuestionQaItemListByQaId(item.QaId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if (len(questionQaItems) - num) < questionQa.QaQuantity {
|
||||
return false, errors.New("关联题库:" + questionQa.QaName + " 题目数量不足")
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user