新增了 检测题目关联的题库数量是否充足-减去对应数量后
This commit is contained in:
parent
4f2bbf2bce
commit
1ecc54ef24
@ -240,6 +240,16 @@ func (b *Question) PutQuestionStatus(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.QuestionStatus == 2 {
|
||||
// 检测题目关联的题库数量是否充足-减去对应数量后
|
||||
questionQaService := service.QuestionQaService{}
|
||||
res, err := questionQaService.CheckQuestionRelationQaQuantitySub(question.QuestionId, 1)
|
||||
if res == false {
|
||||
responses.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 开始事务
|
||||
tx := global.Db.Begin()
|
||||
defer func() {
|
||||
@ -257,7 +267,7 @@ func (b *Question) PutQuestionStatus(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
tx.Commit()
|
||||
//tx.Commit()
|
||||
responses.Ok(c)
|
||||
}
|
||||
|
||||
|
||||
@ -329,6 +329,15 @@ func (r *QuestionQaItemDao) GetQuestionQaItemNotInListRand(maps interface{}, que
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetQuestionQaItemListByQuestionIdDistinctQaId 获取数据-QuestionId-去重复(QaId)
|
||||
func (r *QuestionQaItemDao) GetQuestionQaItemListByQuestionIdDistinctQaId(questionId int64) (m []*model.QuestionQaItem, err error) {
|
||||
err = global.Db.Where("question_id = ?", questionId).Distinct("qa_id").Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
//subQuery := global.Db.Model(&model.Question{}).
|
||||
//Where("kb_question.question_id = kb_question_qa_item.question_id").
|
||||
//Where("question_status = ?", 1).
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user