新增了删除时检测剩余题目数量是否满足使用
This commit is contained in:
@@ -15,6 +15,29 @@ type QuestionQaItemService struct {
|
||||
func (r *QuestionQaItemService) DeleteQuestionQaItem(req requests.DeleteQuestionQaItem) (bool, error) {
|
||||
questionQaItemDao := dao.QuestionQaItemDao{}
|
||||
|
||||
qaId, err := strconv.ParseInt(req.QaId, 10, 64)
|
||||
if err != nil {
|
||||
return false, errors.New("删除失败")
|
||||
}
|
||||
|
||||
// 获取题库数据
|
||||
questionQaDao := dao.QuestionQaDao{}
|
||||
questionQa, err := questionQaDao.GetQuestionQaById(qaId)
|
||||
if err != nil {
|
||||
return false, errors.New("题库错误")
|
||||
}
|
||||
|
||||
// 获取题库明细数据
|
||||
questionQaItems, err := questionQaItemDao.GetQuestionQaItemListByQaId(qaId)
|
||||
if err != nil {
|
||||
return false, errors.New("题库错误")
|
||||
}
|
||||
|
||||
// 检测剩余题目数量是否满足使用
|
||||
if questionQa.QaQuantity > (len(questionQaItems) - len(req.ItemId)) {
|
||||
return false, errors.New("删除后剩余题目不满足题库使用")
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user