123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- 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
- }
|