cycle_create.go 1.3 KB
package command

import (
	"github.com/beego/beego/v2/core/validation"
	"time"
)

type CreateCycleCommand struct {
	CompanyId   int64      `cname:"公司ID" json:"companyId"`
	CreatorId   int64      `cname:"创建人ID" json:"creatorId"`
	Name        string     `cname:"周期名称" json:"name" valid:"Required"`
	TimeStart   *time.Time `cname:"起始时间" json:"timeStart"`
	TimeEnd     *time.Time `cname:"截至时间" json:"timeEnd"`
	KpiCycle    int        `cname:"考核周期" json:"kpiCycle" valid:"Required"`
	TemplateIds []string   `cname:"周期使用模板ID" json:"templateIds"`
}

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
	}
	if len(in.Name) > 40 {
		validation.SetError("name", "角色名称最大长度40个字符")
		return
	}
	if in.TimeStart == nil {
		validation.SetError("timeStart", "请选择考核周期的开始时间")
		return
	}
	if in.TimeEnd == nil {
		validation.SetError("timeEnd", "请选择考核周期的结束时间")
		return
	}
	if len(in.TemplateIds) == 0 {
		validation.SetError("templates", "请选择周期内使用的评估模板")
		return
	}
}