审查视图

pkg/application/evaluation_cycle/command/cycle_create.go 1.4 KB
郑周 authored
1 2 3 4
package command

import (
	"github.com/beego/beego/v2/core/validation"
郑周 authored
5
	"unicode/utf8"
郑周 authored
6 7 8
)

type CreateCycleCommand struct {
郑周 authored
9 10 11 12 13 14 15
	CompanyId   int64    `cname:"公司ID" json:"companyId"`
	CreatorId   int64    `cname:"创建人ID" json:"creatorId"`
	Name        string   `cname:"周期名称" json:"name" valid:"Required"`
	TimeStart   string   `cname:"起始时间" json:"timeStart"`
	TimeEnd     string   `cname:"截至时间" json:"timeEnd"`
	KpiCycle    int      `cname:"考核周期" json:"kpiCycle" valid:"Required"`
	TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
郑周 authored
16 17 18 19 20 21 22 23 24 25 26
}

func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
	if in.CompanyId == 0 {
		validation.SetError("companyId", "公司ID无效")
		return
	}
	if in.CreatorId == 0 {
		validation.SetError("creatorId", "创建人ID无效")
		return
	}
郑周 authored
27
	if utf8.RuneCountInString(in.Name) > 40 {
郑周 authored
28
		validation.SetError("name", "名称最大长度40个字符")
郑周 authored
29 30
		return
	}
郑周 authored
31 32 33 34 35
	if in.KpiCycle == 0 {
		validation.SetError("kpiCycle", "请选择考核周期")
		return
	}
郑周 authored
36
	if len(in.TimeStart) == 0 {
郑周 authored
37 38 39
		validation.SetError("timeStart", "请选择考核周期的开始时间")
		return
	}
郑周 authored
40
	if len(in.TimeEnd) == 0 {
郑周 authored
41 42 43 44
		validation.SetError("timeEnd", "请选择考核周期的结束时间")
		return
	}
	if len(in.TemplateIds) == 0 {
郑周 authored
45
		validation.SetError("templates", "请添加评估模板")
郑周 authored
46 47 48
		return
	}
}