|
@@ -1,6 +1,9 @@
|
|
|
package entity_crud
|
|
package entity_crud
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "reflect"
|
|
|
|
|
+ "strings"
|
|
|
|
|
+
|
|
|
"git.sxidc.com/go-framework/baize/framework/binding"
|
|
"git.sxidc.com/go-framework/baize/framework/binding"
|
|
|
"git.sxidc.com/go-framework/baize/framework/core/api"
|
|
"git.sxidc.com/go-framework/baize/framework/core/api"
|
|
|
"git.sxidc.com/go-framework/baize/framework/core/api/request"
|
|
"git.sxidc.com/go-framework/baize/framework/core/api/request"
|
|
@@ -13,8 +16,6 @@ import (
|
|
|
"git.sxidc.com/go-framework/baize/framework/core/tag/sql/sql_mapping"
|
|
"git.sxidc.com/go-framework/baize/framework/core/tag/sql/sql_mapping"
|
|
|
"git.sxidc.com/go-tools/utils/reflectutils"
|
|
"git.sxidc.com/go-tools/utils/reflectutils"
|
|
|
"github.com/pkg/errors"
|
|
"github.com/pkg/errors"
|
|
|
- "reflect"
|
|
|
|
|
- "strings"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func Create(tableName string, needCreateUserID bool, callbacks *CreateCallbacks, needTx bool) binding.ServiceFunc[string] {
|
|
func Create(tableName string, needCreateUserID bool, callbacks *CreateCallbacks, needTx bool) binding.ServiceFunc[string] {
|
|
@@ -117,7 +118,7 @@ func Create(tableName string, needCreateUserID bool, callbacks *CreateCallbacks,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func Delete(tableName string, callbacks *DeleteCallbacks, needTx bool) binding.ServiceFunc[any] {
|
|
|
|
|
|
|
+func Delete(tableName string, callbacks *DeleteCallbacks, needTx bool, scopeFields ...string) binding.ServiceFunc[any] {
|
|
|
return func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
|
|
return func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
|
|
|
object := objects[0]
|
|
object := objects[0]
|
|
|
if object == nil {
|
|
if object == nil {
|
|
@@ -148,7 +149,7 @@ func Delete(tableName string, callbacks *DeleteCallbacks, needTx bool) binding.S
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- err = database.DeleteEntity(tx, tableName, e)
|
|
|
|
|
|
|
+ err = database.DeleteEntityWithScope(tx, tableName, e, scopeFields...)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
@@ -169,7 +170,7 @@ func Delete(tableName string, callbacks *DeleteCallbacks, needTx bool) binding.S
|
|
|
return nil, callbackOnDeleteErrorReturn(callbacks, c, params, e, prepared, err, i)
|
|
return nil, callbackOnDeleteErrorReturn(callbacks, c, params, e, prepared, err, i)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- err = database.DeleteEntity(dbExecutor, tableName, e)
|
|
|
|
|
|
|
+ err = database.DeleteEntityWithScope(dbExecutor, tableName, e, scopeFields...)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, callbackOnDeleteErrorReturn(callbacks, c, params, e, prepared, err, i)
|
|
return nil, callbackOnDeleteErrorReturn(callbacks, c, params, e, prepared, err, i)
|
|
|
}
|
|
}
|
|
@@ -184,7 +185,7 @@ func Delete(tableName string, callbacks *DeleteCallbacks, needTx bool) binding.S
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func Update(tableName string, needLastUpdateUserID bool, callbacks *UpdateCallbacks, needTx bool) binding.ServiceFunc[any] {
|
|
|
|
|
|
|
+func Update(tableName string, needLastUpdateUserID bool, callbacks *UpdateCallbacks, needTx bool, scopeFields ...string) binding.ServiceFunc[any] {
|
|
|
return func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
|
|
return func(c *api.Context, params request.Params, objects []domain.Object, i *infrastructure.Infrastructure) (any, error) {
|
|
|
object := objects[0]
|
|
object := objects[0]
|
|
|
if object == nil {
|
|
if object == nil {
|
|
@@ -236,7 +237,7 @@ func Update(tableName string, needLastUpdateUserID bool, callbacks *UpdateCallba
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- err = database.UpdateEntity(tx, tableName, e)
|
|
|
|
|
|
|
+ err = database.UpdateEntityWithScope(tx, tableName, e, scopeFields...)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return err
|
|
return err
|
|
|
}
|
|
}
|
|
@@ -257,7 +258,7 @@ func Update(tableName string, needLastUpdateUserID bool, callbacks *UpdateCallba
|
|
|
return nil, callbackOnUpdateErrorReturn(callbacks, c, params, e, prepared, err, i)
|
|
return nil, callbackOnUpdateErrorReturn(callbacks, c, params, e, prepared, err, i)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- err = database.UpdateEntity(dbExecutor, tableName, e)
|
|
|
|
|
|
|
+ err = database.UpdateEntityWithScope(dbExecutor, tableName, e, scopeFields...)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return nil, callbackOnUpdateErrorReturn(callbacks, c, params, e, prepared, err, i)
|
|
return nil, callbackOnUpdateErrorReturn(callbacks, c, params, e, prepared, err, i)
|
|
|
}
|
|
}
|