作者 郑周

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

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