rule_update.go 1.3 KB
package command

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

type UpdateRuleCommand struct {
	Id        int64          `cname:"规则ID" json:"id,string" valid:"Required"`
	CompanyId int64          `cname:"公司ID" json:"companyId"`
	CreatorId int64          `cname:"创建人ID" json:"creatorId"`
	Name      string         `cname:"规则名称" json:"name" valid:"Required"`
	Remark    string         `cname:"规则备注" json:"remark"`
	Type      int            `cname:"评估方式" json:"type"`
	Rating    *domain.Rating `cname:"评级" json:"rating"`
	Score     *domain.Score  `cname:"评分" json:"score"`
}

func (in *UpdateRuleCommand) 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.Type == domain.EvaluationTypeRating {
		if nil == in.Rating || len(in.Rating.Levels) == 0 {
			validation.SetError("rating", "评级内容不能为空")
			return
		}
	}

	if in.Type == domain.EvaluationTypeScore {
		if nil == in.Score {
			validation.SetError("rating", "评分内容不能为空")
			return
		}
	}
}