修改了增加题库时,数量计算的问题

This commit is contained in:
wucongxing8150 2024-11-04 18:15:41 +08:00
parent 1649c59dab
commit c9af7ff13c
2 changed files with 35 additions and 21 deletions

View File

@ -48,7 +48,7 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err
return false, errors.New("明细题目错误") return false, errors.New("明细题目错误")
} }
// 选择的明细数量 += QuestionQaItem.Quantity // 选择的明细数量 += QuestionQaItem.Quantity
itemQuantity := 0 itemQuantity := 0
for _, item := range req.QuestionQaItem { for _, item := range req.QuestionQaItem {
itemQuantity = itemQuantity + item.Quantity itemQuantity = itemQuantity + item.Quantity
@ -81,14 +81,18 @@ func (r *QuestionQaService) AddQuestionQa(req requests.AddQuestionQa) (bool, err
// 单个类型总数量 = 单一题目类型数量 * 飞花令数量 // 单个类型总数量 = 单一题目类型数量 * 飞花令数量
for _, content := range req.TokenQuestionContent { for _, content := range req.TokenQuestionContent {
itemQuantity = 0
for _, item := range req.QuestionQaItem { for _, item := range req.QuestionQaItem {
if content.QuestionType == item.QuestionType { if content.QuestionType == item.QuestionType {
quantity := content.Quantity * *req.TokenNum itemQuantity = item.Quantity
if quantity > item.Quantity {
return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足")
}
} }
} }
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 { for _, content := range req.TokenQuestionContent {
itemQuantity = 0
for _, item := range req.QuestionQaItem { for _, item := range req.QuestionQaItem {
if content.QuestionType == item.QuestionType { if content.QuestionType == item.QuestionType {
quantity := content.Quantity * *req.TokenNum * *req.RoundNum itemQuantity = item.Quantity
if quantity > item.Quantity {
return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足")
}
} }
} }
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 { for _, content := range req.TokenQuestionContent {
itemQuantity = 0
for _, item := range req.QuestionQaItem { for _, item := range req.QuestionQaItem {
if content.QuestionType == item.QuestionType { if content.QuestionType == item.QuestionType {
quantity := content.Quantity * *req.TokenNum itemQuantity = item.Quantity
if quantity > item.Quantity {
tx.Rollback()
return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足")
}
} }
} }
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 { for _, content := range req.TokenQuestionContent {
itemQuantity = 0
for _, item := range req.QuestionQaItem { for _, item := range req.QuestionQaItem {
if content.QuestionType == item.QuestionType { if content.QuestionType == item.QuestionType {
quantity := content.Quantity * *req.TokenNum * *req.RoundNum itemQuantity = item.Quantity
if quantity > item.Quantity {
tx.Rollback()
return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足")
}
} }
} }
quantity := content.Quantity * *req.TokenNum * *req.RoundNum
if quantity > itemQuantity {
return false, errors.New(utils.QuestionType(content.QuestionType) + "数量不足")
}
} }
} }

View File

@ -6,9 +6,9 @@ func QuestionType(t int) string {
return "单选题" return "单选题"
} else if t == 2 { } else if t == 2 {
return "多选题" return "多选题"
} else if t == 2 { } else if t == 3 {
return "问答题" return "问答题"
} else if t == 2 { } else if t == 4 {
return "判断题" return "判断题"
} else { } else {
return "未知" return "未知"