package rule import ( "encoding/json" "git.sxidc.com/go-framework/baize/framework/core/domain" "git.sxidc.com/go-framework/baize/framework/core/domain/entity" "git.sxidc.com/go-framework/baize/framework/core/tag/check" "github.com/pkg/errors" ) const ( FieldScope = "Scope" FieldDomainName = "DomainName" FieldRule = "Rule" FieldEnabled = "Enabled" ) var ( ColumnScope = domain.ColumnName(FieldScope) ColumnDomainName = domain.ColumnName(FieldDomainName) ColumnRule = domain.ColumnName(FieldRule) ColumnEnabled = domain.ColumnName(FieldEnabled) ) var fieldMap = map[string]string{ FieldScope: "范围", FieldDomainName: "领域名", FieldRule: "规则", } type Entity struct { entity.Base Scope string `sqlmapping:"column:scope;notUpdate;" sqlresult:"column:scope;" check:"required,lte=256"` DomainName string `sqlmapping:"column:domain_name;notUpdate;" sqlresult:"column:domain_name;" check:"required,lte=256"` Rule string `sqlmapping:"column:rule;notUpdate;" sqlresult:"column:rule;" check:"required"` Enabled bool `sqlresult:"column:enabled;" sqlresult:"column:enabled;"` } func (e *Entity) DomainCNName() string { return "查询规则" } func (e *Entity) DomainCamelName() string { return "QueryRule" } func (e *Entity) ForCreate() error { checkResult := check.Struct(e, fieldMap) err := entity.CheckFieldIDResult(checkResult) if err != nil { return err } err = domain.CheckField(checkResult, e.DomainCNName(), FieldScope) if err != nil { return err } err = domain.CheckField(checkResult, e.DomainCNName(), FieldDomainName) if err != nil { return err } err = domain.CheckField(checkResult, e.DomainCNName(), FieldRule) if err != nil { return err } err = e.lintRule() if err != nil { return err } return nil } func (e *Entity) ForDelete() error { checkResult := check.Struct(e, fieldMap) err := entity.CheckFieldIDResult(checkResult) if err != nil { return err } return nil } func (e *Entity) ForUpdate() error { return nil } func (e *Entity) lintRule() error { r := new(Rule) err := json.Unmarshal([]byte(e.Rule), r) if err != nil { return errors.New(err.Error()) } return r.check() }