修改了增加题库时,数量计算的问题
This commit is contained in:
+33
-19
@@ -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) + "数量不足")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user