yjp 1 år sedan
förälder
incheckning
1eabaf5f2b

+ 62 - 62
convenient/entity_crud/simple.go

@@ -52,88 +52,88 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 	domainPath := domain.RelativeDomainPath(simple.Entity)
 
 	// 创建
-	if !createOptions.disableCreate {
-		if !createOptions.createNeedTx {
+	if !createOptions.disable {
+		if !createOptions.needTx {
 			binding.PostBind[string](binder, &binding.SimpleBindItem[string]{
 				Path:          domainPath + "/create",
 				ResponseFunc:  response.SendIDResponse,
 				RequestParams: simple.CreateJsonBody,
 				Objects:       []domain.Object{simple.Entity},
-				ServiceFunc:   Create(tableName, createOptions.createCallbacks),
-			}, createOptions.createMiddlewares...)
+				ServiceFunc:   Create(tableName, createOptions.callbacks),
+			}, createOptions.middlewares...)
 		} else {
 			binding.PostBind(binder, &binding.SimpleBindItem[string]{
 				Path:          domainPath + "/create",
 				ResponseFunc:  response.SendIDResponse,
 				RequestParams: simple.CreateJsonBody,
 				Objects:       []domain.Object{simple.Entity},
-				ServiceFunc:   CreateTx(tableName, createOptions.createCallbacks),
-			}, createOptions.createMiddlewares...)
+				ServiceFunc:   CreateTx(tableName, createOptions.callbacks),
+			}, createOptions.middlewares...)
 		}
 	}
 
 	// 删除
-	if !deleteOptions.disableDelete {
-		if !deleteOptions.deleteNeedTx {
+	if !deleteOptions.disable {
+		if !deleteOptions.needTx {
 			binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
 				Path:          domainPath + "/delete",
 				ResponseFunc:  response.SendMsgResponse,
 				RequestParams: simple.DeleteQueryParams,
 				Objects:       []domain.Object{simple.Entity},
-				ServiceFunc:   Delete(tableName, deleteOptions.deleteCallbacks),
-			}, deleteOptions.deleteMiddlewares...)
+				ServiceFunc:   Delete(tableName, deleteOptions.callbacks),
+			}, deleteOptions.middlewares...)
 		} else {
 			binding.DeleteBind(binder, &binding.SimpleBindItem[any]{
 				Path:          domainPath + "/delete",
 				ResponseFunc:  response.SendMsgResponse,
 				RequestParams: simple.DeleteQueryParams,
 				Objects:       []domain.Object{simple.Entity},
-				ServiceFunc:   DeleteTx(tableName, deleteOptions.deleteCallbacks),
-			}, deleteOptions.deleteMiddlewares...)
+				ServiceFunc:   DeleteTx(tableName, deleteOptions.callbacks),
+			}, deleteOptions.middlewares...)
 		}
 	}
 
 	// 修改
-	if !updateOptions.disableUpdate {
-		if !updateOptions.updateNeedTx {
+	if !updateOptions.disable {
+		if !updateOptions.needTx {
 			binding.PutBind(binder, &binding.SimpleBindItem[any]{
 				Path:          domainPath + "/update",
 				ResponseFunc:  response.SendMsgResponse,
 				RequestParams: simple.UpdateJsonBody,
 				Objects:       []domain.Object{simple.Entity},
-				ServiceFunc:   Update(tableName, updateOptions.updateCallbacks),
-			}, updateOptions.updateMiddlewares...)
+				ServiceFunc:   Update(tableName, updateOptions.callbacks),
+			}, updateOptions.middlewares...)
 		} else {
 			binding.PutBind(binder, &binding.SimpleBindItem[any]{
 				Path:          domainPath + "/update",
 				ResponseFunc:  response.SendMsgResponse,
 				RequestParams: simple.UpdateJsonBody,
 				Objects:       []domain.Object{simple.Entity},
-				ServiceFunc:   UpdateTx(tableName, updateOptions.updateCallbacks),
-			}, updateOptions.updateMiddlewares...)
+				ServiceFunc:   UpdateTx(tableName, updateOptions.callbacks),
+			}, updateOptions.middlewares...)
 		}
 	}
 
 	// 查询
-	if !queryOptions.disableQuery {
+	if !queryOptions.disable {
 		binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
 			Path:          domainPath + "/query",
 			ResponseFunc:  response.SendInfosResponse[I],
 			RequestParams: simple.QueryQueryParams,
 			Objects:       []domain.Object{simple.Entity},
-			ServiceFunc:   Query[I](tableName, queryOptions.queryCallbacks, queryOptions.queryConditionFieldCallback),
-		}, queryOptions.queryMiddlewares...)
+			ServiceFunc:   Query[I](tableName, queryOptions.callbacks, queryOptions.conditionFieldCallback),
+		}, queryOptions.middlewares...)
 	}
 
 	// 通过ID获取
-	if !getByIDOptions.disableGetByID {
+	if !getByIDOptions.disable {
 		binding.GetBind(binder, &binding.SimpleBindItem[I]{
 			Path:          domainPath + "/get",
 			ResponseFunc:  response.SendInfoResponse[I],
 			RequestParams: simple.GetByIDQueryParams,
 			Objects:       []domain.Object{simple.Entity},
-			ServiceFunc:   GetByID[I](tableName, getByIDOptions.getByIDCallbacks),
-		}, getByIDOptions.getByIDMiddlewares...)
+			ServiceFunc:   GetByID[I](tableName, getByIDOptions.callbacks),
+		}, getByIDOptions.middlewares...)
 	}
 }
 
@@ -178,181 +178,181 @@ type GetByIDOption[I any] func(options *GetByIDOptions[I])
 
 type CreateOptions struct {
 	// 关闭创建
-	disableCreate bool
+	disable bool
 
 	// 创建是否使用事务
-	createNeedTx bool
+	needTx bool
 
 	// 创建回调
-	createCallbacks *CreateCallbacks
+	callbacks *CreateCallbacks
 
 	// 创建中间件
-	createMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 type DeleteOptions struct {
 	// 关闭删除
-	disableDelete bool
+	disable bool
 
 	// 删除是否使用事务
-	deleteNeedTx bool
+	needTx bool
 
 	// 删除回调
-	deleteCallbacks *DeleteCallbacks
+	callbacks *DeleteCallbacks
 
 	// 删除中间件
-	deleteMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 type UpdateOptions struct {
 	// 关闭更新
-	disableUpdate bool
+	disable bool
 
 	// 更新是否使用事务
-	updateNeedTx bool
+	needTx bool
 
 	// 更新回调
-	updateCallbacks *UpdateCallbacks
+	callbacks *UpdateCallbacks
 
 	// 更新中间件
-	updateMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 type QueryOptions[I any] struct {
 	// 关闭查询
-	disableQuery bool
+	disable bool
 
 	// 查询条件构造回调
-	queryConditionFieldCallback ConditionFieldCallback
+	conditionFieldCallback ConditionFieldCallback
 
 	// 查询回调
-	queryCallbacks *QueryCallbacks[I]
+	callbacks *QueryCallbacks[I]
 
 	// 查询中间件
-	queryMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 type GetByIDOptions[I any] struct {
 	// 关闭根据ID查询
-	disableGetByID bool
+	disable bool
 
 	// 根据ID查询回调
-	getByIDCallbacks *GetByIDCallbacks[I]
+	callbacks *GetByIDCallbacks[I]
 
 	// 根据ID查询中间件
-	getByIDMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 func WithDisableCreate() CreateOption {
 	return func(options *CreateOptions) {
-		options.disableCreate = true
+		options.disable = true
 	}
 }
 
 func WithCreateTx() CreateOption {
 	return func(options *CreateOptions) {
-		options.createNeedTx = true
+		options.needTx = true
 	}
 }
 
 func WithCreateCallbacks(callbacks *CreateCallbacks) CreateOption {
 	return func(options *CreateOptions) {
-		options.createCallbacks = callbacks
+		options.callbacks = callbacks
 	}
 }
 
 func WithCreateMiddlewares(middlewares []api.Handler) CreateOption {
 	return func(options *CreateOptions) {
-		options.createMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }
 
 func WithDisableDelete() DeleteOption {
 	return func(options *DeleteOptions) {
-		options.disableDelete = true
+		options.disable = true
 	}
 }
 
 func WithDeleteTx() DeleteOption {
 	return func(options *DeleteOptions) {
-		options.deleteNeedTx = true
+		options.needTx = true
 	}
 }
 
 func WithDeleteCallbacks(callbacks *DeleteCallbacks) DeleteOption {
 	return func(options *DeleteOptions) {
-		options.deleteCallbacks = callbacks
+		options.callbacks = callbacks
 	}
 }
 
 func WithDeleteMiddlewares(middlewares []api.Handler) DeleteOption {
 	return func(options *DeleteOptions) {
-		options.deleteMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }
 
 func WithDisableUpdate() UpdateOption {
 	return func(options *UpdateOptions) {
-		options.disableUpdate = true
+		options.disable = true
 	}
 }
 
 func WithUpdateTx() UpdateOption {
 	return func(options *UpdateOptions) {
-		options.updateNeedTx = true
+		options.needTx = true
 	}
 }
 
 func WithUpdateCallbacks(callbacks *UpdateCallbacks) UpdateOption {
 	return func(options *UpdateOptions) {
-		options.updateCallbacks = callbacks
+		options.callbacks = callbacks
 	}
 }
 
 func WithUpdateMiddlewares(middlewares []api.Handler) UpdateOption {
 	return func(options *UpdateOptions) {
-		options.updateMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }
 
 func WithDisableQuery[I any]() QueryOption[I] {
 	return func(options *QueryOptions[I]) {
-		options.disableQuery = true
+		options.disable = true
 	}
 }
 
 func WithQueryConditionFieldCallback[I any](callback ConditionFieldCallback) QueryOption[I] {
 	return func(options *QueryOptions[I]) {
-		options.queryConditionFieldCallback = callback
+		options.conditionFieldCallback = callback
 	}
 }
 
 func WithQueryCallbacks[I any](callbacks *QueryCallbacks[I]) QueryOption[I] {
 	return func(options *QueryOptions[I]) {
-		options.queryCallbacks = callbacks
+		options.callbacks = callbacks
 	}
 }
 
 func WithQueryMiddlewares[I any](middlewares []api.Handler) QueryOption[I] {
 	return func(options *QueryOptions[I]) {
-		options.queryMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }
 
 func WithDisableGetByID[I any]() GetByIDOption[I] {
 	return func(options *GetByIDOptions[I]) {
-		options.disableGetByID = true
+		options.disable = true
 	}
 }
 
 func WithGetByIDCallbacks[I any](callbacks *GetByIDCallbacks[I]) GetByIDOption[I] {
 	return func(options *GetByIDOptions[I]) {
-		options.getByIDCallbacks = callbacks
+		options.callbacks = callbacks
 	}
 }
 
 func WithGetByIDMiddlewares[I any](middlewares []api.Handler) GetByIDOption[I] {
 	return func(options *GetByIDOptions[I]) {
-		options.getByIDMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }

+ 192 - 50
convenient/gwtools/crud.go

@@ -1,13 +1,18 @@
 package gwtools
 
 import (
+	"encoding/json"
 	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 	"git.sxidc.com/go-tools/utils/template"
+	"git.sxidc.com/service-supports/fserr"
 	"github.com/iancoleman/strcase"
 	"net/http"
 )
 
+type GetTenantIDFunc func(c *api.Context) (string, error)
+type GetUserIDFunc func(c *api.Context) (string, error)
+
 func CRUD(builder *gateway.Builder, params *CRUDParams, opts ...any) {
 	createOptions := new(CreateOptions)
 	deleteOptions := new(DeleteOptions)
@@ -48,12 +53,6 @@ type CRUDParams struct {
 	// 领域名称
 	DomainCamelName string
 
-	CreateMiddlewares  []api.Handler
-	DeleteMiddlewares  []api.Handler
-	UpdateMiddlewares  []api.Handler
-	QueryMiddlewares   []api.Handler
-	GetByIDMiddlewares []api.Handler
-
 	// 可选配置项,通过WithXXX配置
 	createOptions  *CreateOptions
 	deleteOptions  *DeleteOptions
@@ -72,53 +71,59 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
 	domainPath := "/" + strcase.ToLowerCamel(template.Id(params.DomainCamelName))
 
 	// 创建
-	if !createOptions.disableCreate {
+	if !createOptions.disable {
 		builder.
 			Url(http.MethodPost, domainPath+"/create").
 			Post(&gateway.PostRequest{
 				Url: params.ServiceVersionedUrl + domainPath + "/create",
-			}, createOptions.createCallback).
-			Build(createOptions.createMiddlewares...)
+				Body: addBodyTenantIDAndUserID("tenantId", "createUserId",
+					params.createOptions.getTenantIDFunc, params.createOptions.getUserIDFunc),
+			}, createOptions.callback).
+			Build(createOptions.middlewares...)
 	}
 
 	// 删除
-	if !deleteOptions.disableDelete {
+	if !deleteOptions.disable {
 		builder.
 			Url(http.MethodDelete, domainPath+"/delete").
 			Delete(&gateway.DeleteRequest{
 				Url: params.ServiceVersionedUrl + domainPath + "/delete",
-			}, deleteOptions.deleteCallback).
-			Build(deleteOptions.deleteMiddlewares...)
+			}, deleteOptions.callback).
+			Build(deleteOptions.middlewares...)
 	}
 
 	// 修改
-	if !updateOptions.disableUpdate {
+	if !updateOptions.disable {
 		builder.
 			Url(http.MethodPut, domainPath+"/update").
 			Put(&gateway.PutRequest{
 				Url: params.ServiceVersionedUrl + domainPath + "/update",
-			}, updateOptions.updateCallback).
-			Build(updateOptions.updateMiddlewares...)
+				Body: addBodyTenantIDAndUserID("", "updateUserId",
+					nil, params.updateOptions.getUserIDFunc),
+			}, updateOptions.callback).
+			Build(updateOptions.middlewares...)
 	}
 
 	// 查询
-	if !queryOptions.disableQuery {
+	if !queryOptions.disable {
 		builder.
 			Url(http.MethodGet, domainPath+"/query").
 			Get(&gateway.GetRequest{
 				Url: params.ServiceVersionedUrl + domainPath + "/query",
-			}, queryOptions.queryCallback).
-			Build(queryOptions.queryMiddlewares...)
+				QueryParams: addQueryParamsTenantIDAndUserID("tenantId", "",
+					params.queryOptions.getTenantIDFunc, nil),
+			}, queryOptions.callback).
+			Build(queryOptions.middlewares...)
 	}
 
 	// 通过ID获取
-	if !getByIDOptions.disableGetByID {
+	if !getByIDOptions.disable {
 		builder.
 			Url(http.MethodGet, domainPath+"/get").
 			Get(&gateway.GetRequest{
 				Url: params.ServiceVersionedUrl + domainPath + "/get",
-			}, getByIDOptions.getByIDCallback).
-			Build(getByIDOptions.getByIDMiddlewares...)
+			}, getByIDOptions.callback).
+			Build(getByIDOptions.middlewares...)
 	}
 }
 
@@ -130,139 +135,276 @@ type GetByIDOption func(options *GetByIDOptions)
 
 type CreateOptions struct {
 	// 关闭创建
-	disableCreate bool
+	disable bool
 
 	// 创建回调
-	createCallback gateway.RequestCallbackFunc
+	callback gateway.RequestCallbackFunc
 
 	// 创建中间件
-	createMiddlewares []api.Handler
+	middlewares []api.Handler
+
+	// 获取租户ID的接口
+	getTenantIDFunc GetTenantIDFunc
+
+	// 获取用户ID的接口
+	getUserIDFunc GetUserIDFunc
 }
 
 type DeleteOptions struct {
 	// 关闭删除
-	disableDelete bool
+	disable bool
 
 	// 删除回调
-	deleteCallback gateway.RequestCallbackFunc
+	callback gateway.RequestCallbackFunc
 
 	// 删除中间件
-	deleteMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 type UpdateOptions struct {
 	// 关闭更新
-	disableUpdate bool
+	disable bool
 
 	// 更新回调
-	updateCallback gateway.RequestCallbackFunc
+	callback gateway.RequestCallbackFunc
 
 	// 更新中间件
-	updateMiddlewares []api.Handler
+	middlewares []api.Handler
+
+	// 获取用户ID的接口
+	getUserIDFunc GetUserIDFunc
 }
 
 type QueryOptions struct {
 	// 关闭查询
-	disableQuery bool
+	disable bool
 
 	// 查询回调
-	queryCallback gateway.RequestCallbackFunc
+	callback gateway.RequestCallbackFunc
 
 	// 查询中间件
-	queryMiddlewares []api.Handler
+	middlewares []api.Handler
+
+	// 获取租户ID的接口
+	getTenantIDFunc GetTenantIDFunc
 }
 
 type GetByIDOptions struct {
 	// 关闭根据ID查询
-	disableGetByID bool
+	disable bool
 
 	// 根据ID查询回调
-	getByIDCallback gateway.RequestCallbackFunc
+	callback gateway.RequestCallbackFunc
 
 	// 根据ID查询中间件
-	getByIDMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 func WithCreateCallbacks(callbacks gateway.RequestCallbackFunc) CreateOption {
 	return func(options *CreateOptions) {
-		options.createCallback = callbacks
+		options.callback = callbacks
 	}
 }
 
 func WithCreateMiddlewares(middlewares []api.Handler) CreateOption {
 	return func(options *CreateOptions) {
-		options.createMiddlewares = middlewares
+		options.middlewares = middlewares
+	}
+}
+
+func WithCreateGetTenantIDFunc(getTenantIDFunc GetTenantIDFunc) CreateOption {
+	return func(options *CreateOptions) {
+		options.getTenantIDFunc = getTenantIDFunc
+	}
+}
+
+func WithCreateGetUserIDFunc(getUserIDFunc GetUserIDFunc) CreateOption {
+	return func(options *CreateOptions) {
+		options.getUserIDFunc = getUserIDFunc
 	}
 }
 
 func WithDisableDelete() DeleteOption {
 	return func(options *DeleteOptions) {
-		options.disableDelete = true
+		options.disable = true
 	}
 }
 
 func WithDeleteCallbacks(callbacks gateway.RequestCallbackFunc) DeleteOption {
 	return func(options *DeleteOptions) {
-		options.deleteCallback = callbacks
+		options.callback = callbacks
 	}
 }
 
 func WithDeleteMiddlewares(middlewares []api.Handler) DeleteOption {
 	return func(options *DeleteOptions) {
-		options.deleteMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }
 
 func WithDisableUpdate() UpdateOption {
 	return func(options *UpdateOptions) {
-		options.disableUpdate = true
+		options.disable = true
 	}
 }
 
 func WithUpdateCallbacks(callbacks gateway.RequestCallbackFunc) UpdateOption {
 	return func(options *UpdateOptions) {
-		options.updateCallback = callbacks
+		options.callback = callbacks
 	}
 }
 
 func WithUpdateMiddlewares(middlewares []api.Handler) UpdateOption {
 	return func(options *UpdateOptions) {
-		options.updateMiddlewares = middlewares
+		options.middlewares = middlewares
+	}
+}
+
+func WithUpdateGetUserIDFunc(getUserIDFunc GetUserIDFunc) UpdateOption {
+	return func(options *UpdateOptions) {
+		options.getUserIDFunc = getUserIDFunc
 	}
 }
 
 func WithDisableQuery() QueryOption {
 	return func(options *QueryOptions) {
-		options.disableQuery = true
+		options.disable = true
 	}
 }
 
 func WithQueryCallbacks(callbacks gateway.RequestCallbackFunc) QueryOption {
 	return func(options *QueryOptions) {
-		options.queryCallback = callbacks
+		options.callback = callbacks
 	}
 }
 
 func WithQueryMiddlewares(middlewares []api.Handler) QueryOption {
 	return func(options *QueryOptions) {
-		options.queryMiddlewares = middlewares
+		options.middlewares = middlewares
+	}
+}
+
+func WithQueryGetTenantIDFunc(getTenantIDFunc GetTenantIDFunc) QueryOption {
+	return func(options *QueryOptions) {
+		options.getTenantIDFunc = getTenantIDFunc
 	}
 }
 
 func WithDisableGetByID() GetByIDOption {
 	return func(options *GetByIDOptions) {
-		options.disableGetByID = true
+		options.disable = true
 	}
 }
 
 func WithGetByIDCallbacks(callbacks gateway.RequestCallbackFunc) GetByIDOption {
 	return func(options *GetByIDOptions) {
-		options.getByIDCallback = callbacks
+		options.callback = callbacks
 	}
 }
 
 func WithGetByIDMiddlewares(middlewares []api.Handler) GetByIDOption {
 	return func(options *GetByIDOptions) {
-		options.getByIDMiddlewares = middlewares
+		options.middlewares = middlewares
+	}
+}
+
+func addBodyTenantIDAndUserID(tenantIDFieldName string, userIDFieldName string,
+	getTenantIDFunc GetTenantIDFunc, getUserIDFunc GetUserIDFunc) gateway.FormBodyFunc {
+	return func(c *api.Context, historyRequests []gateway.BuilderRequest, customResultMap map[string]any) (any, error) {
+		body, err := gateway.DefaultFormBodyFunc(c, historyRequests, customResultMap)
+		if err != nil {
+			return nil, err
+		}
+
+		if getTenantIDFunc == nil && getUserIDFunc == nil {
+			return body, nil
+		}
+
+		bodyBytes, ok := body.([]byte)
+		if !ok {
+			return nil, fserr.New("body不是json")
+		}
+
+		bodyMap := make(map[string]any)
+		err = json.Unmarshal(bodyBytes, &bodyMap)
+		if err != nil {
+			return nil, err
+		}
+
+		if getTenantIDFunc != nil {
+			_, ok := bodyMap[tenantIDFieldName]
+			if !ok {
+				tenantID, err := getTenantIDFunc(c)
+				if err != nil {
+					return nil, err
+				}
+
+				bodyMap[tenantIDFieldName] = tenantID
+			}
+		}
+
+		if getUserIDFunc != nil {
+			_, ok := bodyMap[userIDFieldName]
+			if !ok {
+				userID, err := getUserIDFunc(c)
+				if err != nil {
+					return nil, err
+				}
+
+				bodyMap[userIDFieldName] = userID
+			}
+		}
+
+		newBody, err := json.Marshal(bodyMap)
+		if err != nil {
+			return nil, err
+		}
+
+		err = c.ReplaceBody(newBody)
+		if err != nil {
+			return nil, err
+		}
+
+		return newBody, nil
+	}
+}
+
+func addQueryParamsTenantIDAndUserID(tenantIDFieldName string, userIDFieldName string,
+	getTenantIDFunc GetTenantIDFunc, getUserIDFunc GetUserIDFunc) gateway.FormQueryParamsFunc {
+	return func(c *api.Context, historyRequests []gateway.BuilderRequest, customResultMap map[string]any) (map[string]string, error) {
+		queryParams, err := gateway.DefaultFormQueryParamsFunc(c, historyRequests, customResultMap)
+		if err != nil {
+			return nil, err
+		}
+
+		if getTenantIDFunc == nil && getUserIDFunc == nil {
+			return queryParams, nil
+		}
+
+		if getTenantIDFunc != nil {
+			_, ok := queryParams[tenantIDFieldName]
+			if !ok {
+				tenantID, err := getTenantIDFunc(c)
+				if err != nil {
+					return nil, err
+				}
+
+				queryParams[tenantIDFieldName] = tenantID
+			}
+		}
+
+		if getUserIDFunc != nil {
+			_, ok := queryParams[userIDFieldName]
+			if !ok {
+				userID, err := getUserIDFunc(c)
+				if err != nil {
+					return nil, err
+				}
+
+				queryParams[userIDFieldName] = userID
+			}
+		}
+
+		return queryParams, nil
 	}
 }

+ 34 - 34
convenient/value_object_crud/simple.go

@@ -42,14 +42,14 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 	domainPath := domain.RelativeDomainPath(simple.ValueObject)
 
 	// 创建
-	if !createOptions.disableCreate {
-		if !createOptions.createNeedTx {
+	if !createOptions.disable {
+		if !createOptions.needTx {
 			binding.PostBind(binder, &binding.SimpleBindItem[any]{
 				Path:          domainPath + "/create",
 				ResponseFunc:  response.SendMsgResponse,
 				RequestParams: simple.CreateJsonBody,
 				Objects:       []domain.Object{simple.ValueObject},
-				ServiceFunc:   Create(tableName, createOptions.createCallbacks),
+				ServiceFunc:   Create(tableName, createOptions.callbacks),
 			})
 		} else {
 			binding.PostBind(binder, &binding.SimpleBindItem[any]{
@@ -57,21 +57,21 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 				ResponseFunc:  response.SendMsgResponse,
 				RequestParams: simple.CreateJsonBody,
 				Objects:       []domain.Object{simple.ValueObject},
-				ServiceFunc:   CreateTx(tableName, createOptions.createCallbacks),
+				ServiceFunc:   CreateTx(tableName, createOptions.callbacks),
 			})
 		}
 	}
 
 	// 删除
-	if !deleteOptions.disableDelete {
-		if !deleteOptions.deleteNeedTx {
+	if !deleteOptions.disable {
+		if !deleteOptions.needTx {
 			binding.PostBind(binder, &binding.SimpleBindItem[any]{
 				Path:                  domainPath + "/delete",
 				ResponseFunc:          response.SendMsgResponse,
 				RequestParams:         simple.DeleteJsonBody,
 				RequestParamsBindFunc: request.JsonBody,
 				Objects:               []domain.Object{simple.ValueObject},
-				ServiceFunc:           Delete(tableName, deleteOptions.deleteCallbacks),
+				ServiceFunc:           Delete(tableName, deleteOptions.callbacks),
 			})
 		} else {
 			binding.PostBind(binder, &binding.SimpleBindItem[any]{
@@ -80,19 +80,19 @@ func (simple *Simple[I]) bind(binder *binding.Binder) {
 				RequestParams:         simple.DeleteJsonBody,
 				RequestParamsBindFunc: request.JsonBody,
 				Objects:               []domain.Object{simple.ValueObject},
-				ServiceFunc:           DeleteTx(tableName, deleteOptions.deleteCallbacks),
+				ServiceFunc:           DeleteTx(tableName, deleteOptions.callbacks),
 			})
 		}
 	}
 
 	// 查询
-	if !queryOptions.disableQuery {
+	if !queryOptions.disable {
 		binding.GetBind(binder, &binding.SimpleBindItem[response.InfosData[I]]{
 			Path:          domainPath + "/query",
 			ResponseFunc:  response.SendInfosResponse[I],
 			RequestParams: simple.QueryQueryParams,
 			Objects:       []domain.Object{simple.ValueObject},
-			ServiceFunc:   Query(tableName, queryOptions.queryCallbacks, queryOptions.queryConditionFieldCallback),
+			ServiceFunc:   Query(tableName, queryOptions.callbacks, queryOptions.conditionFieldCallback),
 		})
 	}
 }
@@ -128,114 +128,114 @@ type QueryOption[I any] func(options *QueryOptions[I])
 
 type CreateOptions struct {
 	// 关闭创建
-	disableCreate bool
+	disable bool
 
 	// 创建是否使用事务
-	createNeedTx bool
+	needTx bool
 
 	// 创建回调
-	createCallbacks *CreateCallbacks
+	callbacks *CreateCallbacks
 
 	// 创建中间件
-	createMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 type DeleteOptions struct {
 	// 关闭删除
-	disableDelete bool
+	disable bool
 
 	// 删除是否使用事务
-	deleteNeedTx bool
+	needTx bool
 
 	// 删除回调
-	deleteCallbacks *DeleteCallbacks
+	callbacks *DeleteCallbacks
 
 	// 删除中间件
-	deleteMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 type QueryOptions[I any] struct {
 	// 关闭查询
-	disableQuery bool
+	disable bool
 
 	// 查询条件构造回调
-	queryConditionFieldCallback ConditionFieldCallback
+	conditionFieldCallback ConditionFieldCallback
 
 	// 查询回调
-	queryCallbacks *QueryCallbacks[I]
+	callbacks *QueryCallbacks[I]
 
 	// 查询中间件
-	queryMiddlewares []api.Handler
+	middlewares []api.Handler
 }
 
 func WithDisableCreate() CreateOption {
 	return func(options *CreateOptions) {
-		options.disableCreate = true
+		options.disable = true
 	}
 }
 
 func WithCreateTx() CreateOption {
 	return func(options *CreateOptions) {
-		options.createNeedTx = true
+		options.needTx = true
 	}
 }
 
 func WithCreateCallbacks(callbacks *CreateCallbacks) CreateOption {
 	return func(options *CreateOptions) {
-		options.createCallbacks = callbacks
+		options.callbacks = callbacks
 	}
 }
 
 func WithCreateMiddlewares(middlewares []api.Handler) CreateOption {
 	return func(options *CreateOptions) {
-		options.createMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }
 
 func WithDisableDelete() DeleteOption {
 	return func(options *DeleteOptions) {
-		options.disableDelete = true
+		options.disable = true
 	}
 }
 
 func WithDeleteTx() DeleteOption {
 	return func(options *DeleteOptions) {
-		options.deleteNeedTx = true
+		options.needTx = true
 	}
 }
 
 func WithDeleteCallbacks(callbacks *DeleteCallbacks) DeleteOption {
 	return func(options *DeleteOptions) {
-		options.deleteCallbacks = callbacks
+		options.callbacks = callbacks
 	}
 }
 
 func WithDeleteMiddlewares(middlewares []api.Handler) DeleteOption {
 	return func(options *DeleteOptions) {
-		options.deleteMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }
 
 func WithDisableQuery[I any]() QueryOption[I] {
 	return func(options *QueryOptions[I]) {
-		options.disableQuery = true
+		options.disable = true
 	}
 }
 
 func WithQueryConditionFieldCallback[I any](callback ConditionFieldCallback) QueryOption[I] {
 	return func(options *QueryOptions[I]) {
-		options.queryConditionFieldCallback = callback
+		options.conditionFieldCallback = callback
 	}
 }
 
 func WithQueryCallbacks[I any](callbacks *QueryCallbacks[I]) QueryOption[I] {
 	return func(options *QueryOptions[I]) {
-		options.queryCallbacks = callbacks
+		options.callbacks = callbacks
 	}
 }
 
 func WithQueryMiddlewares[I any](middlewares []api.Handler) QueryOption[I] {
 	return func(options *QueryOptions[I]) {
-		options.queryMiddlewares = middlewares
+		options.middlewares = middlewares
 	}
 }

+ 13 - 0
framework/core/api/context.go

@@ -69,6 +69,19 @@ func (c *Context) ReadBody() ([]byte, error) {
 	return body, nil
 }
 
+func (c *Context) ReplaceBody(body []byte) error {
+	if c.Request.Body != nil {
+		err := c.Request.Body.Close()
+		if err != nil {
+			return err
+		}
+	}
+
+	c.Request.Body = io.NopCloser(bytes.NewBuffer(body))
+
+	return nil
+}
+
 func (c *Context) GetAllQueryParams() map[string]string {
 	queryParams := make(map[string]string, 0)