| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package configuration
- import (
- "git.sxidc.com/go-framework/baize/framework/core/domain/value_object"
- "git.sxidc.com/go-tools/utils/strutils"
- "github.com/pkg/errors"
- )
- const (
- ColumnScope = "scope"
- ColumnGroup = "group"
- ColumnValue = "value"
- )
- const (
- fieldScopeMaxLen = 256
- fieldGroupMaxLen = 256
- fieldValueMaxLen = 256
- )
- type Entity struct {
- value_object.Base
- Scope string `sqlmapping:"column:scope;key;notUpdate;" sqlresult:"column:group;"`
- Group string `sqlmapping:"column:group;key;notUpdate;" sqlresult:"column:group;"`
- Value string `sqlmapping:"column:value;notUpdate;" sqlresult:"column:value;"`
- }
- func (e *Entity) DomainCNName() string {
- return "配置"
- }
- func (e *Entity) DomainCamelName() string {
- return "Configuration"
- }
- func (e *Entity) CheckKeyFields() error {
- err := e.checkFieldScope()
- if err != nil {
- return err
- }
- err = e.checkFieldGroup()
- if err != nil {
- return err
- }
- return nil
- }
- func (e *Entity) ForCreate() error {
- err := e.checkFieldScope()
- if err != nil {
- return err
- }
- err = e.checkFieldGroup()
- if err != nil {
- return err
- }
- err = e.checkFieldValue()
- if err != nil {
- return err
- }
- return nil
- }
- func (e *Entity) checkFieldScope() error {
- if strutils.IsStringEmpty(e.Scope) {
- return errors.New(e.DomainCNName() + "范围为空")
- }
- if len(e.Scope) > fieldScopeMaxLen {
- return errors.New(e.DomainCNName() + "范围超出限定长度")
- }
- return nil
- }
- func (e *Entity) checkFieldGroup() error {
- if strutils.IsStringEmpty(e.Group) {
- return errors.New(e.DomainCNName() + "组为空")
- }
- if len(e.Group) > fieldGroupMaxLen {
- return errors.New(e.DomainCNName() + "组超出限定长度")
- }
- return nil
- }
- func (e *Entity) checkFieldValue() error {
- if strutils.IsStringEmpty(e.Value) {
- return errors.New(e.DomainCNName() + "值为空")
- }
- if len(e.Value) > fieldValueMaxLen {
- return errors.New(e.DomainCNName() + "值超出限定长度")
- }
- return nil
- }
|