From c9af7ff13c923cf2f6d2afc3744dbf49cd72a610 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Mon, 4 Nov 2024 18:15:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E9=A2=98=E5=BA=93=E6=97=B6=EF=BC=8C=E6=95=B0=E9=87=8F=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/service/QuestionQa.go | 52 +++++++++++++++++++++++++-------------- utils/intToString.go | 4 +-- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/api/service/QuestionQa.go b/api/service/QuestionQa.go index e486d69..6cb8f78 100644 --- a/api/service/QuestionQa.go +++ b/api/service/QuestionQa.go @@ -48,7 +48,7 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err return false, errors.New("明细题目错误") } - // 选择的明细数量 += QuestionQaItem.Quantity + // 选择的明细总数量 += QuestionQaItem.Quantity itemQuantity := 0 for _, item := range req.QuestionQaItem { itemQuantity = itemQuantity + item.Quantity @@ -81,14 +81,18 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err // 单个类型总数量 = 单一题目类型数量 * 飞花令数量 for _, content := range req.TokenQuestionContent { + itemQuantity = 0 for _, item := range req.QuestionQaItem { if content.QuestionType == item.QuestionType { - quantity := content.Quantity * *req.TokenNum - if quantity > item.Quantity { - return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足") - } + itemQuantity = item.Quantity } } + + quantity := content.Quantity * *req.TokenNum + + if quantity > itemQuantity { + return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足") + } } } @@ -108,14 +112,18 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err // 单个类型总数量 = 单一题目类型数量 * 飞花令数量 * 轮次 for _, content := range req.TokenQuestionContent { + itemQuantity = 0 for _, item := range req.QuestionQaItem { if content.QuestionType == item.QuestionType { - quantity := content.Quantity * *req.TokenNum * *req.RoundNum - if quantity > item.Quantity { - return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足") - } + itemQuantity = item.Quantity } } + + quantity := content.Quantity * *req.TokenNum * *req.RoundNum + + if quantity > itemQuantity { + return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足") + } } } @@ -380,15 +388,18 @@ func (r *QuestionQaService) PutQuestionQa(qaId int64, req requests.PutQuestionQa // 单个类型总数量 = 单一题目类型数量 * 飞花令数量 for _, content := range req.TokenQuestionContent { + itemQuantity = 0 for _, item := range req.QuestionQaItem { if content.QuestionType == item.QuestionType { - quantity := content.Quantity * *req.TokenNum - if quantity > item.Quantity { - tx.Rollback() - return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足") - } + itemQuantity = item.Quantity } } + + quantity := content.Quantity * *req.TokenNum + + if quantity > itemQuantity { + return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足") + } } } @@ -409,15 +420,18 @@ func (r *QuestionQaService) PutQuestionQa(qaId int64, req requests.PutQuestionQa // 单个类型总数量 = 单一题目类型数量 * 飞花令数量 * 轮次 for _, content := range req.TokenQuestionContent { + itemQuantity = 0 for _, item := range req.QuestionQaItem { if content.QuestionType == item.QuestionType { - quantity := content.Quantity * *req.TokenNum * *req.RoundNum - if quantity > item.Quantity { - tx.Rollback() - return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足") - } + itemQuantity = item.Quantity } } + + quantity := content.Quantity * *req.TokenNum * *req.RoundNum + + if quantity > itemQuantity { + return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足") + } } } diff --git a/utils/intToString.go b/utils/intToString.go index da1ded6..28a00cf 100644 --- a/utils/intToString.go +++ b/utils/intToString.go @@ -6,9 +6,9 @@ func QuestionType(t int) string { return "单选题" } else if t == 2 { return "多选题" - } else if t == 2 { + } else if t == 3 { return "问答题" - } else if t == 2 { + } else if t == 4 { return "判断题" } else { return "未知"