作者 庄敏学

模板导入权重精度

@@ -5,6 +5,7 @@ import ( @@ -5,6 +5,7 @@ import (
5 "github.com/beego/beego/v2/core/validation" 5 "github.com/beego/beego/v2/core/validation"
6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" 6 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils" 7 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
  8 + "math"
8 ) 9 )
9 10
10 type UpdateTemplateCommand struct { 11 type UpdateTemplateCommand struct {
@@ -34,6 +35,7 @@ func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) { @@ -34,6 +35,7 @@ func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
34 for i2 := range linkNode.NodeContents { 35 for i2 := range linkNode.NodeContents {
35 weightTotal += linkNode.NodeContents[i2].Weight 36 weightTotal += linkNode.NodeContents[i2].Weight
36 } 37 }
  38 + weightTotal = math.Round(weightTotal*100) / 100
37 if weightTotal != 100 { 39 if weightTotal != 100 {
38 formatWeightTotal := utils.FormatFloatDecimal(weightTotal, 2) 40 formatWeightTotal := utils.FormatFloatDecimal(weightTotal, 2)
39 validation.SetError("linkNodes", fmt.Sprintf("总权重值错误,当前%s的总权重值为:%s%%(必须等于100%%)", linkNode.Name, formatWeightTotal)) 41 validation.SetError("linkNodes", fmt.Sprintf("总权重值错误,当前%s的总权重值为:%s%%(必须等于100%%)", linkNode.Name, formatWeightTotal))