template_update.go 1.6 KB
package command

import (
	"fmt"
	"github.com/beego/beego/v2/core/validation"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
)

type UpdateTemplateCommand struct {
	Id           int64              `cname:"模板ID" json:"id,string" valid:"Required"`
	CompanyId    int64              `cname:"公司ID" json:"companyId"`
	Name         string             `cname:"模板名称" json:"name" valid:"Required"`
	Describe     string             `cname:"模板描述" json:"describe"`
	LinkNodes    []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
	FinishConfig int                `cname:"配置" json:"finishConfig"`
}

func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
	if in.CompanyId == 0 {
		validation.SetError("companyId", "公司ID无效")
		return
	}

	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 {
					formatWeightTotal := utils.FormatFloatDecimal(weightTotal, 2)
					validation.SetError("linkNodes", fmt.Sprintf("权重错误,当前%s的总权重值为:%s%%(必须等于100%%)", linkNode.Name, formatWeightTotal))
					return
				}
			}
		}
	}

}