value_object.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package configuration
  2. import (
  3. "git.sxidc.com/go-framework/baize/framework/core/domain"
  4. "git.sxidc.com/go-framework/baize/framework/core/domain/value_object"
  5. "git.sxidc.com/go-framework/baize/framework/core/tag/check"
  6. )
  7. const (
  8. FieldScope = "Scope"
  9. FieldGroup = "Group"
  10. FieldValue = "Value"
  11. )
  12. var (
  13. ColumnScope = domain.ColumnName(FieldScope)
  14. ColumnGroup = domain.ColumnName(FieldGroup)
  15. ColumnValue = domain.ColumnName(FieldValue)
  16. )
  17. var fieldMap = map[string]string{
  18. FieldScope: "范围",
  19. FieldGroup: "组",
  20. FieldValue: "值",
  21. }
  22. type ValueObject struct {
  23. value_object.Base
  24. Scope string `sqlmapping:"column:scope;key;notUpdate;" sqlresult:"column:scope;" check:"required,lte=256"`
  25. Group string `sqlmapping:"column:group;key;notUpdate;" sqlresult:"column:group;" check:"required,lte=256"`
  26. Value string `sqlmapping:"column:value;notUpdate;" sqlresult:"column:value;" check:"required,lte=256"`
  27. }
  28. func (valueObject *ValueObject) DomainCNName() string {
  29. return "配置"
  30. }
  31. func (valueObject *ValueObject) DomainCamelName() string {
  32. return "Configuration"
  33. }
  34. func (valueObject *ValueObject) CheckKeyFields() error {
  35. checkResult := check.Struct(valueObject, fieldMap)
  36. err := domain.CheckField(checkResult, valueObject.DomainCNName(), FieldScope)
  37. if err != nil {
  38. return err
  39. }
  40. err = domain.CheckField(checkResult, valueObject.DomainCNName(), FieldGroup)
  41. if err != nil {
  42. return err
  43. }
  44. return nil
  45. }
  46. func (valueObject *ValueObject) ForCreate() error {
  47. checkResult := check.Struct(valueObject, fieldMap)
  48. err := domain.CheckField(checkResult, valueObject.DomainCNName(), FieldScope)
  49. if err != nil {
  50. return err
  51. }
  52. err = domain.CheckField(checkResult, valueObject.DomainCNName(), FieldGroup)
  53. if err != nil {
  54. return err
  55. }
  56. err = domain.CheckField(checkResult, valueObject.DomainCNName(), FieldValue)
  57. if err != nil {
  58. return err
  59. }
  60. return nil
  61. }