Browse Source

修改bug

yjp 1 year ago
parent
commit
4bc77118e7

+ 14 - 5
convenient/domain/auth/permission/api.go

@@ -7,7 +7,6 @@ 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/infrastructure"
-	"git.sxidc.com/go-framework/baize/framework/core/infrastructure/database"
 )
 
 // Simple Bind参数
@@ -30,14 +29,24 @@ func (simple *Simple) Bind(binder *binding.Binder) {
 		GetByIDQueryParams: &GetPermissionQueryParams{},
 	}, entity_crud.WithGlobalMiddlewares(simple.AuthMiddleware),
 		entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{
-			Before: func(c *api.Context, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
+			Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
 				userInfo := c.GetUserInfo()
-				return domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				err := domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				if err != nil {
+					return nil, err
+				}
+
+				return nil, err
 			},
 		}), entity_crud.WithUpdateCallbacks(&entity_crud.UpdateCallbacks{
-			Before: func(c *api.Context, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
+			Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
 				userInfo := c.GetUserInfo()
-				return domain.SetField(e, entity.FieldLastUpdateUserID, userInfo.GetID())
+				err := domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				if err != nil {
+					return nil, err
+				}
+
+				return nil, err
 			},
 		}))
 }

+ 14 - 5
convenient/domain/auth/permission_group/api.go

@@ -7,7 +7,6 @@ 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/infrastructure"
-	"git.sxidc.com/go-framework/baize/framework/core/infrastructure/database"
 )
 
 // Simple Bind参数
@@ -30,14 +29,24 @@ func (simple *Simple) Bind(binder *binding.Binder) {
 		GetByIDQueryParams: &GetPermissionGroupQueryParams{},
 	}, entity_crud.WithGlobalMiddlewares(simple.AuthMiddleware),
 		entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{
-			Before: func(c *api.Context, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
+			Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
 				userInfo := c.GetUserInfo()
-				return domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				err := domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				if err != nil {
+					return nil, err
+				}
+
+				return nil, err
 			},
 		}), entity_crud.WithUpdateCallbacks(&entity_crud.UpdateCallbacks{
-			Before: func(c *api.Context, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
+			Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
 				userInfo := c.GetUserInfo()
-				return domain.SetField(e, entity.FieldLastUpdateUserID, userInfo.GetID())
+				err := domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				if err != nil {
+					return nil, err
+				}
+
+				return nil, err
 			},
 		}))
 }

+ 14 - 5
convenient/domain/auth/role/api.go

@@ -7,7 +7,6 @@ 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/infrastructure"
-	"git.sxidc.com/go-framework/baize/framework/core/infrastructure/database"
 )
 
 // Simple Bind参数
@@ -30,14 +29,24 @@ func (simple *Simple) Bind(binder *binding.Binder) {
 		GetByIDQueryParams: &GetRoleQueryParams{},
 	}, entity_crud.WithGlobalMiddlewares(simple.AuthMiddleware),
 		entity_crud.WithCreateCallbacks(&entity_crud.CreateCallbacks{
-			Before: func(c *api.Context, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
+			Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
 				userInfo := c.GetUserInfo()
-				return domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				err := domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				if err != nil {
+					return nil, err
+				}
+
+				return nil, err
 			},
 		}), entity_crud.WithUpdateCallbacks(&entity_crud.UpdateCallbacks{
-			Before: func(c *api.Context, e entity.Entity, prepared map[string]any, i *infrastructure.Infrastructure, tx database.Executor) error {
+			Prepare: func(c *api.Context, e entity.Entity, i *infrastructure.Infrastructure) (map[string]any, error) {
 				userInfo := c.GetUserInfo()
-				return domain.SetField(e, entity.FieldLastUpdateUserID, userInfo.GetID())
+				err := domain.SetField(e, entity.FieldCreateUserID, userInfo.GetID())
+				if err != nil {
+					return nil, err
+				}
+
+				return nil, err
 			},
 		}))
 }

+ 18 - 18
convenient/entity_crud/service.go

@@ -35,12 +35,12 @@ func Create(tableName string, callbacks *CreateCallbacks) binding.ServiceFunc[st
 			return callbackOnCreateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
 
-		err = e.ForCreate()
+		prepared, err := callbackPrepareCreate(callbacks, c, e, i)
 		if err != nil {
 			return callbackOnCreateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
 
-		prepared, err := callbackPrepareCreate(callbacks, c, e, i)
+		err = e.ForCreate()
 		if err != nil {
 			return callbackOnCreateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
@@ -82,12 +82,12 @@ func Delete(tableName string, callbacks *DeleteCallbacks) binding.ServiceFunc[an
 			return nil, errors.New("需要传递领域对象应该为实体")
 		}
 
-		err := e.ForDelete()
+		prepared, err := callbackPrepareDelete(callbacks, c, e, i)
 		if err != nil {
 			return nil, callbackOnDeleteErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
 
-		prepared, err := callbackPrepareDelete(callbacks, c, e, i)
+		err = e.ForDelete()
 		if err != nil {
 			return nil, callbackOnDeleteErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
@@ -125,11 +125,6 @@ func Update(tableName string, callbacks *UpdateCallbacks) binding.ServiceFunc[an
 			return nil, errors.New("需要传递领域对象应该为实体")
 		}
 
-		err := e.ForUpdate()
-		if err != nil {
-			return nil, callbackOnUpdateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
-		}
-
 		exist, err := database.CheckExist(dbExecutor, &sql.CheckExistExecuteParams{
 			TableName:  tableName,
 			Conditions: sql.NewConditions().Equal(entity.ColumnID, e.GetID()),
@@ -148,6 +143,11 @@ func Update(tableName string, callbacks *UpdateCallbacks) binding.ServiceFunc[an
 			return nil, callbackOnUpdateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
 
+		err = e.ForUpdate()
+		if err != nil {
+			return nil, callbackOnUpdateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
+		}
+
 		err = callbackBeforeUpdate(callbacks, c, e, prepared, i, nil)
 		if err != nil {
 			return nil, callbackOnUpdateErrorReturn(callbacks, c, e, prepared, err, i)
@@ -328,12 +328,12 @@ func CreateTx(tableName string, callbacks *CreateCallbacks) binding.ServiceFunc[
 			return callbackOnCreateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
 
-		err = e.ForCreate()
+		prepared, err := callbackPrepareCreate(callbacks, c, e, i)
 		if err != nil {
 			return callbackOnCreateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
 
-		prepared, err := callbackPrepareCreate(callbacks, c, e, i)
+		err = e.ForCreate()
 		if err != nil {
 			return callbackOnCreateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
@@ -382,12 +382,12 @@ func DeleteTx(tableName string, callbacks *DeleteCallbacks) binding.ServiceFunc[
 			return nil, errors.New("需要传递领域对象应该为实体")
 		}
 
-		err := e.ForDelete()
+		prepared, err := callbackPrepareDelete(callbacks, c, e, i)
 		if err != nil {
 			return nil, callbackOnDeleteErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
 
-		prepared, err := callbackPrepareDelete(callbacks, c, e, i)
+		err = e.ForDelete()
 		if err != nil {
 			return nil, callbackOnDeleteErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
@@ -432,11 +432,6 @@ func UpdateTx(tableName string, callbacks *UpdateCallbacks) binding.ServiceFunc[
 			return nil, errors.New("需要传递领域对象应该为实体")
 		}
 
-		err := e.ForUpdate()
-		if err != nil {
-			return nil, callbackOnUpdateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
-		}
-
 		exist, err := database.CheckExist(dbExecutor, &sql.CheckExistExecuteParams{
 			TableName:  tableName,
 			Conditions: sql.NewConditions().Equal(entity.ColumnID, e.GetID()),
@@ -454,6 +449,11 @@ func UpdateTx(tableName string, callbacks *UpdateCallbacks) binding.ServiceFunc[
 			return nil, callbackOnUpdateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
 		}
 
+		err = e.ForUpdate()
+		if err != nil {
+			return nil, callbackOnUpdateErrorReturn(callbacks, c, e, make(map[string]any), err, i)
+		}
+
 		err = database.Transaction(dbExecutor, func(tx database.Executor) error {
 			err = callbackBeforeUpdate(callbacks, c, e, prepared, i, tx)
 			if err != nil {

+ 11 - 6
convenient/value_object_crud/service.go

@@ -29,12 +29,12 @@ func Create(tableName string, callbacks *CreateCallbacks) binding.ServiceFunc[an
 			return nil, errors.New("需要传递领域对象应该为值对象")
 		}
 
-		err := valueObject.ForCreate()
+		prepared, err := callbackPrepareCreate(callbacks, c, valueObject, i)
 		if err != nil {
 			return nil, callbackOnCreateErrorReturn(callbacks, c, valueObject, make(map[string]any), err, i)
 		}
 
-		prepared, err := callbackPrepareCreate(callbacks, c, valueObject, i)
+		err = valueObject.ForCreate()
 		if err != nil {
 			return nil, callbackOnCreateErrorReturn(callbacks, c, valueObject, make(map[string]any), err, i)
 		}
@@ -76,12 +76,12 @@ func Delete(tableName string, callbacks *DeleteCallbacks) binding.ServiceFunc[an
 			return nil, errors.New("需要传递领域对象应该为值对象")
 		}
 
-		err := valueObject.CheckKeyFields()
+		prepared, err := callbackPrepareDelete(callbacks, c, valueObject, i)
 		if err != nil {
 			return nil, callbackOnDeleteErrorReturn(callbacks, c, valueObject, make(map[string]any), err, i)
 		}
 
-		prepared, err := callbackPrepareDelete(callbacks, c, valueObject, i)
+		err = valueObject.CheckKeyFields()
 		if err != nil {
 			return nil, callbackOnDeleteErrorReturn(callbacks, c, valueObject, make(map[string]any), err, i)
 		}
@@ -213,6 +213,11 @@ func CreateTx(tableName string, callbacks *CreateCallbacks) binding.ServiceFunc[
 			return nil, callbackOnCreateErrorReturn(callbacks, c, valueObject, make(map[string]any), err, i)
 		}
 
+		err = valueObject.ForCreate()
+		if err != nil {
+			return nil, callbackOnCreateErrorReturn(callbacks, c, valueObject, make(map[string]any), err, i)
+		}
+
 		err = database.Transaction(dbExecutor, func(tx database.Executor) error {
 			err := callbackBeforeCreate(callbacks, c, valueObject, prepared, i, tx)
 			if err != nil {
@@ -257,12 +262,12 @@ func DeleteTx(tableName string, callbacks *DeleteCallbacks) binding.ServiceFunc[
 			return nil, errors.New("需要传递领域对象应该为值对象")
 		}
 
-		err := valueObject.CheckKeyFields()
+		prepared, err := callbackPrepareDelete(callbacks, c, valueObject, i)
 		if err != nil {
 			return nil, callbackOnDeleteErrorReturn(callbacks, c, valueObject, make(map[string]any), err, i)
 		}
 
-		prepared, err := callbackPrepareDelete(callbacks, c, valueObject, i)
+		err = valueObject.CheckKeyFields()
 		if err != nil {
 			return nil, callbackOnDeleteErrorReturn(callbacks, c, valueObject, make(map[string]any), err, i)
 		}