package command import ( "github.com/beego/beego/v2/core/validation" "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain" "unicode/utf8" ) type CreateTemplateCommand struct { CompanyId int64 `cname:"公司ID" json:"companyId"` CreatorId int64 `cname:"创建人ID" json:"creatorId"` Name string `cname:"模板名称" json:"name" valid:"Required"` Describe string `cname:"模板描述" json:"describe"` NodeContents []*domain.NodeContent `cname:"环节-评估内容" json:"nodeContents"` State int `cname:"状态(0待完成配置、1待启用、2启用、3停用)"` } func (in *CreateTemplateCommand) Valid(validation *validation.Validation) { if in.CompanyId == 0 { validation.SetError("companyId", "公司ID无效") return } if in.CreatorId == 0 { validation.SetError("creatorId", "创建人ID无效") return } // 这个才是真正计算字符串文字长度的 utf8.RuneCountInString(in.Name) if utf8.RuneCountInString(in.Name) > 40 { validation.SetError("name", "模板名称最大长度40个字符") return } if utf8.RuneCountInString(in.Describe) > 100 { validation.SetError("describe", "备注最大长度100个字符") return } }