entity.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package rule
  2. import (
  3. "encoding/json"
  4. "git.sxidc.com/go-framework/baize/framework/core/domain"
  5. "git.sxidc.com/go-framework/baize/framework/core/domain/entity"
  6. "github.com/pkg/errors"
  7. )
  8. const (
  9. FieldScope = "Scope"
  10. FieldDomainName = "DomainName"
  11. FieldRule = "Rule"
  12. FieldEnabled = "Enabled"
  13. )
  14. var (
  15. ColumnScope = domain.ColumnName(FieldScope)
  16. ColumnDomainName = domain.ColumnName(FieldDomainName)
  17. ColumnRule = domain.ColumnName(FieldRule)
  18. ColumnEnabled = domain.ColumnName(FieldEnabled)
  19. )
  20. var fieldMap = map[string]string{
  21. FieldScope: "范围",
  22. FieldDomainName: "领域名",
  23. FieldRule: "规则",
  24. }
  25. type Entity struct {
  26. entity.Base
  27. Scope string `sqlmapping:"column:scope;notUpdate;" sqlresult:"column:scope;" check:"required,lte=256,when=create"`
  28. DomainName string `sqlmapping:"column:domain_name;notUpdate;" sqlresult:"column:domain_name;" check:"required,lte=256,when=create"`
  29. Rule string `sqlmapping:"column:rule;notUpdate;" sqlresult:"column:rule;" check:"required,when=create"`
  30. Enabled bool `sqlresult:"column:enabled;" sqlresult:"column:enabled;"`
  31. }
  32. func (e *Entity) DomainCNName() string {
  33. return "查询规则"
  34. }
  35. func (e *Entity) DomainCamelName() string {
  36. return "QueryRule"
  37. }
  38. func (e *Entity) GetFieldMap() map[string]string {
  39. return fieldMap
  40. }
  41. func (e *Entity) LintRule() error {
  42. r := new(Rule)
  43. err := json.Unmarshal([]byte(e.Rule), r)
  44. if err != nil {
  45. return errors.New(err.Error())
  46. }
  47. return r.check()
  48. }