作者 郑周

1. 添加评估内容-填写自评反馈-评估内容的所有权重值相加和必须等于100,否则错误提示

package adapter
type DepartmentAdapter struct {
Id int64 `comment:"部门ID" json:"id"`
Id int64 `comment:"部门ID" json:"id,string"`
Name string `comment:"部门名称" json:"name"`
CompanyId int64 `comment:"公司ID" json:"companyId"`
ParentId int64 `comment:"父级ID" json:"parentId"`
CompanyId int64 `comment:"公司ID" json:"companyId,string"`
ParentId int64 `comment:"父级ID" json:"parentId,string"`
Departments []*DepartmentAdapter `comment:"子部门" json:"departments"`
UserTotal int `comment:"部门用户总数量(包含子部门)" json:"userTotal"`
}
... ...
package command
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
... ... @@ -33,6 +34,21 @@ func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
if len(in.LinkNodes) == 0 {
validation.SetError("linkNodes", "评估模板流程不能为空")
return
} else {
for i := range in.LinkNodes {
linkNode := in.LinkNodes[i]
// 填写自评反馈,如果有评估内容时,内容权重相加 = 100%
if linkNode.Type == domain.LinkNodeSelfAssessment && len(linkNode.NodeContents) > 0 {
weightTotal := 0.0
for i2 := range linkNode.NodeContents {
weightTotal += linkNode.NodeContents[i2].Weight
}
if weightTotal != 100 {
validation.SetError("linkNodes", fmt.Sprintf("权重错误,当前%s的总权重值为:%f(必须等于100)", linkNode.Name, weightTotal))
return
}
}
}
}
}
... ...