package role import ( "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" "git.sxidc.com/go-tools/utils/strutils" "github.com/pkg/errors" ) const ( FieldName = "Name" FieldDescription = "Description" ) var ( ColumnName = domain.ColumnName(FieldName) ColumnDescription = domain.ColumnName(FieldDescription) ) var fieldMap = map[string]string{ FieldName: "角色名称", FieldDescription: "角色描述", } type Entity struct { entity.Base Name string `sqlmapping:"column:name" sqlresult:"column:name" check:"required,lte=256"` Description string `sqlmapping:"column:description;updateClear" sqlresult:"column:description"` UserIDs []string `sqlmapping:"-" sqlresult:"-"` PermissionIDs []string `sqlmapping:"-" sqlresult:"-"` entity.UserIDFields entity.TimeFields } func (e *Entity) DomainCNName() string { return "角色" } func (e *Entity) DomainCamelName() string { return "Role" } 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(), FieldName) if err != nil { return err } err = entity.CheckFieldCreateUserIDResult(checkResult) if err != nil { return err } e.LastUpdateUserID = e.CreateUserID 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 { checkResult := check.Struct(e, fieldMap) err := entity.CheckFieldIDResult(checkResult) if err != nil { return err } err = entity.CheckFieldLastUpdateUserIDResult(checkResult) if err != nil { return err } err = e.checkUpdateFields(checkResult) if err != nil { return err } return nil } func (e *Entity) checkUpdateFields(checkResult check.Result) error { if strutils.AllBlank(e.Name) { return errors.New(e.DomainCNName() + "没有传递需要更新的字段") } if strutils.IsStringNotEmpty(e.Name) { err := domain.CheckField(checkResult, e.DomainCNName(), FieldName) if err != nil { return err } } return nil }