新增了删除时检测剩余题目数量是否满足使用
This commit is contained in:
parent
ddd8411ac8
commit
f36b3173af
@ -30,6 +30,7 @@ type GetQuestionQaItemPageOrder struct {
|
||||
// DeleteQuestionQaItem 删除问答题库明细
|
||||
type DeleteQuestionQaItem struct {
|
||||
ItemId []string `json:"item_id" form:"item_id" validate:"required" label:"明细id"`
|
||||
QaId string `json:"qa_id" form:"qa_id" label:"题库id" validate:"required"`
|
||||
}
|
||||
|
||||
// PutQuestionQaItemMust 修改必选
|
||||
|
||||
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user