修改了增加题库时,数量计算的问题
This commit is contained in:
parent
1649c59dab
commit
c9af7ff13c
@ -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) + "数量不足")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 "未知"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user