yjp 1 rok temu
rodzic
commit
bc10a6e7e7

+ 3 - 0
convenient/data_containers/sql_executor.yaml

@@ -9,6 +9,9 @@ spec:
       - name: sql
         type: text
         comment: sql语句
+      - name: executor_id
+        type: varchar(32)
+        comment: 执行人ID
       - name: executor_name
         type: varchar(256)
         comment: 执行人姓名

+ 5 - 0
convenient/domain/sql_executor/api.go

@@ -47,6 +47,7 @@ func (simple *Simple) bind(binder *binding.Binder) {
 
 				sqlExecuteLog := &SqlExecuteLog{
 					Sql:          jsonBody.Sql,
+					ExecutorID:   jsonBody.ExecutorID,
 					ExecutorName: jsonBody.ExecutorName,
 				}
 
@@ -96,6 +97,10 @@ func (simple *Simple) bind(binder *binding.Binder) {
 				conditions.Like(ColumnSql, "%"+queryParams.Sql+"%")
 			}
 
+			if strutils.IsStringNotEmpty(queryParams.ExecutorID) {
+				conditions.Like(ColumnExecutorID, queryParams.ExecutorID)
+			}
+
 			if strutils.IsStringNotEmpty(queryParams.ExecutorName) {
 				conditions.Like(ColumnExecutorName, "%"+queryParams.ExecutorName+"%")
 			}

+ 22 - 2
convenient/domain/sql_executor/entity.go

@@ -9,17 +9,20 @@ import (
 
 const (
 	ColumnSql          = "sql"
+	ColumnExecutorID   = "executor_id"
 	ColumnExecutorName = "executor_name"
 	ColumnExecutedTime = "executed_time"
 )
 
 const (
-	fieldExecutorNameLen = 256
+	fieldExecutorIDLen      = 32
+	fieldExecutorNameMaxLen = 256
 )
 
 type SqlExecuteLog struct {
 	value_object.Base
 	Sql          string    `sqlmapping:"column:sql;" sqlresult:"column:sql;"`
+	ExecutorID   string    `sqlmapping:"column:executor_id;" sqlresult:"column:executor_id;"`
 	ExecutorName string    `sqlmapping:"column:executor_name;" sqlresult:"column:executor_name;"`
 	ExecutedTime time.Time `sqlmapping:"column:executed_time;" sqlresult:"column:executed_time;"`
 }
@@ -38,6 +41,11 @@ func (e *SqlExecuteLog) ForCreate() error {
 		return err
 	}
 
+	err = e.checkFieldExecutorID()
+	if err != nil {
+		return err
+	}
+
 	err = e.checkFieldExecutorName()
 	if err != nil {
 		return err
@@ -56,12 +64,24 @@ func (e *SqlExecuteLog) checkFieldSql() error {
 	return nil
 }
 
+func (e *SqlExecuteLog) checkFieldExecutorID() error {
+	if strutils.IsStringEmpty(e.ExecutorID) {
+		return fserr.New(e.DomainCNName() + "执行人ID为空")
+	}
+
+	if len(e.ExecutorID) != fieldExecutorIDLen {
+		return fserr.New(e.DomainCNName() + "执行人ID长度不正确")
+	}
+
+	return nil
+}
+
 func (e *SqlExecuteLog) checkFieldExecutorName() error {
 	if strutils.IsStringEmpty(e.ExecutorName) {
 		return fserr.New(e.DomainCNName() + "执行人姓名为空")
 	}
 
-	if len(e.ExecutorName) > fieldExecutorNameLen {
+	if len(e.ExecutorName) > fieldExecutorNameMaxLen {
 		return fserr.New(e.DomainCNName() + "执行人姓名超出限定长度")
 	}
 

+ 1 - 0
convenient/domain/sql_executor/info.go

@@ -2,6 +2,7 @@ package sql_executor
 
 type SqlExecuteLogInfo struct {
 	Sql          string `json:"sql" sqlresult:"sql"`
+	ExecutorID   string `json:"executorId" sqlresult:"executor_id"`
 	ExecutorName string `json:"executorName" sqlresult:"executor_name"`
 	ExecutedTime string `json:"executedTime" sqlresult:"executed_time"`
 }

+ 2 - 0
convenient/domain/sql_executor/request_params.go

@@ -4,12 +4,14 @@ import "git.sxidc.com/go-framework/baize/framework/binding/request"
 
 type ExecuteSqlJsonBody struct {
 	Sql          string `json:"sql" binding:"required"`
+	ExecutorID   string `json:"executorId" binding:"required"`
 	ExecutorName string `json:"executorName" binding:"required"`
 }
 
 type QuerySqlExecuteLogQueryParams struct {
 	request.BaseQueryParams
 	Sql              string `form:"sql"`
+	ExecutorID       string `form:"executorId"`
 	ExecutorName     string `form:"executorName"`
 	StartExecuteTime string `form:"startExecuteTime"`
 	EndExecuteTime   string `form:"endExecuteTime"`

+ 58 - 14
convenient/domain_gateway/sql_executor.go

@@ -1,22 +1,66 @@
 package domain_gateway
 
 import (
-	"git.sxidc.com/go-framework/baize/convenient/gwtools"
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
+	"git.sxidc.com/service-supports/fserr"
+	"net/http"
 )
 
 func sqlExecutorGatewayApi(baseUrl string, builder *gateway.Builder) {
-	gwtools.PostPassThrough(builder, &gwtools.SimplePassThroughParams{
-		RelativePath: "/sql/execute",
-		Request: &gateway.PostRequest{
-			Url: baseUrl + "/sql/execute",
-		},
-	})
-
-	gwtools.GetPassThrough(builder, &gwtools.SimplePassThroughParams{
-		RelativePath: "/sql/execute/log",
-		Request: &gateway.GetRequest{
-			Url: baseUrl + "/sql/execute/log",
-		},
-	})
+	builder.
+		Url(http.MethodPost, "/sql/execute").
+		Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
+			bodyMap, err := gateway.AddJsonBodyTenantIDAndUserID(c, "", "executorId")
+			if err != nil {
+				return nil, err
+			}
+
+			userInfo := c.GetUserInfo()
+			if userInfo == nil {
+				bodyMap["executorName"] = "guest"
+			} else {
+				bodyMap["executorName"] = userInfo.GetName()
+			}
+
+			serviceNameValue, ok := bodyMap["serviceName"]
+			if !ok {
+				return nil, fserr.New("没有传递服务名")
+			}
+
+			serviceName, ok := serviceNameValue.(string)
+			if !ok {
+				return nil, fserr.New("服务名不是string类型")
+			}
+
+			delete(bodyMap, "serviceName")
+
+			return &gateway.PostRequest{
+				Url:  baseUrl + "/" + serviceName + "/sql/execute",
+				Body: bodyMap,
+			}, nil
+		}, nil).
+		Build()
+
+	builder.
+		Url(http.MethodPost, "/sql/execute").
+		Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
+			queryPrams, err := gateway.AddQueryParamsTenantIDAndUserID(c, "", "executorId")
+			if err != nil {
+				return nil, err
+			}
+
+			serviceName, ok := queryPrams["serviceName"]
+			if !ok {
+				return nil, fserr.New("没有传递服务名")
+			}
+
+			delete(queryPrams, "serviceName")
+
+			return &gateway.GetRequest{
+				Url:         baseUrl + "/" + serviceName + "/sql/execute/log",
+				QueryParams: queryPrams,
+			}, nil
+		}, nil).
+		Build()
 }

+ 0 - 120
convenient/gwtools/common.go

@@ -1,120 +0,0 @@
-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/service-supports/fserr"
-)
-
-type TenantInfo interface {
-	GetID() string
-}
-
-type UserInfo interface {
-	GetID() string
-}
-
-type GetTenantInfoFunc func(c *api.Context) (TenantInfo, error)
-type GetUserInfoFunc func(c *api.Context) (UserInfo, error)
-
-func AddBodyTenantIDAndUserID(tenantIDFieldName string, userIDFieldName string,
-	getTenantIDFunc GetTenantInfoFunc, getUserIDFunc GetUserInfoFunc) 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 GetTenantInfoFunc, getUserIDFunc GetUserInfoFunc) 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 {
-				tenantInfo, err := getTenantIDFunc(c)
-				if err != nil {
-					return nil, err
-				}
-
-				queryParams[tenantIDFieldName] = tenantInfo.GetID()
-			}
-		}
-
-		if getUserIDFunc != nil {
-			_, ok := queryParams[userIDFieldName]
-			if !ok {
-				userInfo, err := getUserIDFunc(c)
-				if err != nil {
-					return nil, err
-				}
-
-				queryParams[userIDFieldName] = userInfo.GetID()
-			}
-		}
-
-		return queryParams, nil
-	}
-}

+ 55 - 73
convenient/gwtools/crud.go

@@ -69,11 +69,17 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
 	if !createOptions.disable {
 		builder.
 			Url(http.MethodPost, domainPath+"/create").
-			Post(&gateway.PostRequest{
-				Url: params.ServiceVersionedUrl + domainPath + "/create",
-				Body: AddBodyTenantIDAndUserID("tenantId", "createUserId",
-					params.createOptions.getTenantIDFunc, params.createOptions.getUserIDFunc),
-			}, createOptions.callback).
+			Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
+				newBody, err := gateway.AddJsonBodyTenantIDAndUserID(c, "tenantId", "createUserId")
+				if err != nil {
+					return nil, err
+				}
+
+				return &gateway.PostRequest{
+					Url:  params.ServiceVersionedUrl + domainPath + "/create",
+					Body: newBody,
+				}, nil
+			}, createOptions.requestResponseCallback).
 			Build(createOptions.middlewares...)
 	}
 
@@ -83,7 +89,7 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
 			Url(http.MethodDelete, domainPath+"/delete").
 			Delete(&gateway.DeleteRequest{
 				Url: params.ServiceVersionedUrl + domainPath + "/delete",
-			}, deleteOptions.callback).
+			}, deleteOptions.requestResponseCallback).
 			Build(deleteOptions.middlewares...)
 	}
 
@@ -91,11 +97,17 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
 	if !updateOptions.disable {
 		builder.
 			Url(http.MethodPut, domainPath+"/update").
-			Put(&gateway.PutRequest{
-				Url: params.ServiceVersionedUrl + domainPath + "/update",
-				Body: AddBodyTenantIDAndUserID("", "updateUserId",
-					nil, params.updateOptions.getUserIDFunc),
-			}, updateOptions.callback).
+			Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
+				newBody, err := gateway.AddJsonBodyTenantIDAndUserID(c, "", "updateUserId")
+				if err != nil {
+					return nil, err
+				}
+
+				return &gateway.PutRequest{
+					Url:  params.ServiceVersionedUrl + domainPath + "/update",
+					Body: newBody,
+				}, nil
+			}, updateOptions.requestResponseCallback).
 			Build(updateOptions.middlewares...)
 	}
 
@@ -103,11 +115,17 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
 	if !queryOptions.disable {
 		builder.
 			Url(http.MethodGet, domainPath+"/query").
-			Get(&gateway.GetRequest{
-				Url: params.ServiceVersionedUrl + domainPath + "/query",
-				QueryParams: AddQueryParamsTenantIDAndUserID("tenantId", "",
-					params.queryOptions.getTenantIDFunc, nil),
-			}, queryOptions.callback).
+			Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
+				newQueryParams, err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
+				if err != nil {
+					return nil, err
+				}
+
+				return &gateway.GetRequest{
+					Url:         params.ServiceVersionedUrl + domainPath + "/query",
+					QueryParams: newQueryParams,
+				}, nil
+			}, updateOptions.requestResponseCallback).
 			Build(queryOptions.middlewares...)
 	}
 
@@ -117,7 +135,7 @@ func (params *CRUDParams) crud(builder *gateway.Builder) {
 			Url(http.MethodGet, domainPath+"/get").
 			Get(&gateway.GetRequest{
 				Url: params.ServiceVersionedUrl + domainPath + "/get",
-			}, getByIDOptions.callback).
+			}, getByIDOptions.requestResponseCallback).
 			Build(getByIDOptions.middlewares...)
 	}
 }
@@ -132,25 +150,19 @@ type CRUDCreateOptions struct {
 	// 关闭创建
 	disable bool
 
-	// 创建回调
-	callback gateway.RequestCallback
+	// 创建请求响应回调
+	requestResponseCallback gateway.RequestResponseCallback
 
 	// 创建中间件
 	middlewares []api.Handler
-
-	// 获取租户ID的接口
-	getTenantIDFunc GetTenantInfoFunc
-
-	// 获取用户ID的接口
-	getUserIDFunc GetUserInfoFunc
 }
 
 type CRUDDeleteOptions struct {
 	// 关闭删除
 	disable bool
 
-	// 删除回调
-	callback gateway.RequestCallback
+	// 删除请求响应回调
+	requestResponseCallback gateway.RequestResponseCallback
 
 	// 删除中间件
 	middlewares []api.Handler
@@ -160,44 +172,38 @@ type CRUDUpdateOptions struct {
 	// 关闭更新
 	disable bool
 
-	// 更新回调
-	callback gateway.RequestCallback
+	// 更新请求响应回调
+	requestResponseCallback gateway.RequestResponseCallback
 
 	// 更新中间件
 	middlewares []api.Handler
-
-	// 获取用户ID的接口
-	getUserIDFunc GetUserInfoFunc
 }
 
 type CRUDQueryOptions struct {
 	// 关闭查询
 	disable bool
 
-	// 查询回调
-	callback gateway.RequestCallback
+	// 查询请求响应回调
+	requestResponseCallback gateway.RequestResponseCallback
 
 	// 查询中间件
 	middlewares []api.Handler
-
-	// 获取租户ID的接口
-	getTenantIDFunc GetTenantInfoFunc
 }
 
 type CRUDGetByIDOptions struct {
 	// 关闭根据ID查询
 	disable bool
 
-	// 根据ID查询回调
-	callback gateway.RequestCallback
+	// 根据ID请求响应回调
+	requestResponseCallback gateway.RequestResponseCallback
 
 	// 根据ID查询中间件
 	middlewares []api.Handler
 }
 
-func WithCRUDCreateCallbacks(callbacks gateway.RequestCallback) CRUDCreateOption {
+func WithCRUDCreateCallbacks(callbacks gateway.RequestResponseCallback) CRUDCreateOption {
 	return func(options *CRUDCreateOptions) {
-		options.callback = callbacks
+		options.requestResponseCallback = callbacks
 	}
 }
 
@@ -207,27 +213,15 @@ func WithCRUDCreateMiddlewares(middlewares []api.Handler) CRUDCreateOption {
 	}
 }
 
-func WithCRUDCreateGetTenantIDFunc(getTenantIDFunc GetTenantInfoFunc) CRUDCreateOption {
-	return func(options *CRUDCreateOptions) {
-		options.getTenantIDFunc = getTenantIDFunc
-	}
-}
-
-func WithCRUDCreateGetUserIDFunc(getUserIDFunc GetUserInfoFunc) CRUDCreateOption {
-	return func(options *CRUDCreateOptions) {
-		options.getUserIDFunc = getUserIDFunc
-	}
-}
-
 func WithCRUDDisableDelete() CRUDDeleteOption {
 	return func(options *CRUDDeleteOptions) {
 		options.disable = true
 	}
 }
 
-func WithCRUDDeleteCallbacks(callbacks gateway.RequestCallback) CRUDDeleteOption {
+func WithCRUDDeleteCallbacks(callbacks gateway.RequestResponseCallback) CRUDDeleteOption {
 	return func(options *CRUDDeleteOptions) {
-		options.callback = callbacks
+		options.requestResponseCallback = callbacks
 	}
 }
 
@@ -243,9 +237,9 @@ func WithCRUDDisableUpdate() CRUDUpdateOption {
 	}
 }
 
-func WithCRUDUpdateCallbacks(callbacks gateway.RequestCallback) CRUDUpdateOption {
+func WithCRUDUpdateCallbacks(callbacks gateway.RequestResponseCallback) CRUDUpdateOption {
 	return func(options *CRUDUpdateOptions) {
-		options.callback = callbacks
+		options.requestResponseCallback = callbacks
 	}
 }
 
@@ -255,21 +249,15 @@ func WithCRUDUpdateMiddlewares(middlewares []api.Handler) CRUDUpdateOption {
 	}
 }
 
-func WithCRUDUpdateGetUserIDFunc(getUserIDFunc GetUserInfoFunc) CRUDUpdateOption {
-	return func(options *CRUDUpdateOptions) {
-		options.getUserIDFunc = getUserIDFunc
-	}
-}
-
 func WithCRUDDisableQuery() CRUDQueryOption {
 	return func(options *CRUDQueryOptions) {
 		options.disable = true
 	}
 }
 
-func WithCRUDQueryCallbacks(callbacks gateway.RequestCallback) CRUDQueryOption {
+func WithCRUDQueryCallbacks(callbacks gateway.RequestResponseCallback) CRUDQueryOption {
 	return func(options *CRUDQueryOptions) {
-		options.callback = callbacks
+		options.requestResponseCallback = callbacks
 	}
 }
 
@@ -279,21 +267,15 @@ func WithCRUDQueryMiddlewares(middlewares []api.Handler) CRUDQueryOption {
 	}
 }
 
-func WithCRUDQueryGetTenantIDFunc(getTenantIDFunc GetTenantInfoFunc) CRUDQueryOption {
-	return func(options *CRUDQueryOptions) {
-		options.getTenantIDFunc = getTenantIDFunc
-	}
-}
-
 func WithCRUDDisableGetByID() CRUDGetByIDOption {
 	return func(options *CRUDGetByIDOptions) {
 		options.disable = true
 	}
 }
 
-func WithCRUDGetByIDCallbacks(callbacks gateway.RequestCallback) CRUDGetByIDOption {
+func WithCRUDGetByIDCallbacks(callbacks gateway.RequestResponseCallback) CRUDGetByIDOption {
 	return func(options *CRUDGetByIDOptions) {
-		options.callback = callbacks
+		options.requestResponseCallback = callbacks
 	}
 }
 

+ 11 - 13
convenient/gwtools/one2many.go

@@ -1,6 +1,7 @@
 package gwtools
 
 import (
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 	"git.sxidc.com/go-tools/utils/template"
 	"github.com/iancoleman/strcase"
@@ -86,10 +87,16 @@ func (params *One2ManyParams) one2many(builder *gateway.Builder) {
 			// 右到左查询,携带左方信息
 			builder.
 				Url(http.MethodGet, rightDomainPath+leftDomainPath+"/queryWith").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/queryWith",
-					QueryParams: AddQueryParamsTenantIDAndUserID("tenantId", "",
-						params.options.rightWithLeftQueryGetTenantIDFunc, nil),
+				Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
+					newQueryParams, err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
+					if err != nil {
+						return nil, err
+					}
+
+					return &gateway.GetRequest{
+						Url:         params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/queryWith",
+						QueryParams: newQueryParams,
+					}, nil
 				}, nil).
 				Build()
 		}
@@ -119,9 +126,6 @@ type One2ManyOptions struct {
 
 	// 关闭右实体带左实体信息查询
 	disableRightWithLeftQuery bool
-
-	// 获取租户ID的接口
-	rightWithLeftQueryGetTenantIDFunc GetTenantInfoFunc
 }
 
 func WithOne2ManyDisableLeft() One2ManyOption {
@@ -165,9 +169,3 @@ func WithOne2ManyDisableRightWithLeftQuery() One2ManyOption {
 		options.disableRightWithLeftQuery = true
 	}
 }
-
-func WithOne2ManyRightWithLeftQueryGetTenantIDFunc(getTenantIDFunc GetTenantInfoFunc) One2OneOption {
-	return func(options *One2OneOptions) {
-		options.rightWithLeftQueryGetTenantIDFunc = getTenantIDFunc
-	}
-}

+ 21 - 26
convenient/gwtools/one2one.go

@@ -1,6 +1,7 @@
 package gwtools
 
 import (
+	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-framework/baize/framework/gateway"
 	"git.sxidc.com/go-tools/utils/template"
 	"github.com/iancoleman/strcase"
@@ -64,10 +65,16 @@ func (params *One2OneParams) one2one(builder *gateway.Builder) {
 			// 左到右查询,携带右方信息
 			builder.
 				Url(http.MethodGet, leftDomainPath+rightDomainPath+"/queryWith").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/queryWith",
-					QueryParams: AddQueryParamsTenantIDAndUserID("tenantId", "",
-						params.options.leftWithRightQueryGetTenantIDFunc, nil),
+				Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
+					newQueryParams, err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
+					if err != nil {
+						return nil, err
+					}
+
+					return &gateway.GetRequest{
+						Url:         params.ServiceVersionedUrl + leftDomainPath + rightDomainPath + "/queryWith",
+						QueryParams: newQueryParams,
+					}, nil
 				}, nil).
 				Build()
 		}
@@ -98,10 +105,16 @@ func (params *One2OneParams) one2one(builder *gateway.Builder) {
 			// 右到左查询,携带左方信息
 			builder.
 				Url(http.MethodGet, rightDomainPath+leftDomainPath+"/queryWith").
-				Get(&gateway.GetRequest{
-					Url: params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/queryWith",
-					QueryParams: AddQueryParamsTenantIDAndUserID("tenantId", "",
-						params.options.rightWithLeftQueryGetTenantIDFunc, nil),
+				Request(func(c *api.Context, historyRequests []gateway.BuilderRequest, resultMap map[string]any) (gateway.BuilderRequest, error) {
+					newQueryParams, err := gateway.AddQueryParamsTenantIDAndUserID(c, "tenantId", "")
+					if err != nil {
+						return nil, err
+					}
+
+					return &gateway.GetRequest{
+						Url:         params.ServiceVersionedUrl + rightDomainPath + leftDomainPath + "/queryWith",
+						QueryParams: newQueryParams,
+					}, nil
 				}, nil).
 				Build()
 		}
@@ -134,12 +147,6 @@ type One2OneOptions struct {
 
 	// 关闭右实体带左实体信息查询
 	disableRightWithLeftQuery bool
-
-	// 获取租户ID的接口
-	leftWithRightQueryGetTenantIDFunc GetTenantInfoFunc
-
-	// 获取租户ID的接口
-	rightWithLeftQueryGetTenantIDFunc GetTenantInfoFunc
 }
 
 func WithOne2OneDisableLeft() One2OneOption {
@@ -189,15 +196,3 @@ func WithOne2OneDisableRightWithLeftQuery() One2OneOption {
 		options.disableRightWithLeftQuery = true
 	}
 }
-
-func WithOne2OneLeftWithRightQueryGetTenantIDFunc(getTenantIDFunc GetTenantInfoFunc) One2OneOption {
-	return func(options *One2OneOptions) {
-		options.leftWithRightQueryGetTenantIDFunc = getTenantIDFunc
-	}
-}
-
-func WithOne2OneRightWithLeftQueryGetTenantIDFunc(getTenantIDFunc GetTenantInfoFunc) One2OneOption {
-	return func(options *One2OneOptions) {
-		options.rightWithLeftQueryGetTenantIDFunc = getTenantIDFunc
-	}
-}

+ 10 - 10
convenient/gwtools/pass_through.go

@@ -67,8 +67,8 @@ func CommonPassThrough(builder *gateway.Builder, params *CommonPassThroughParams
 }
 
 type PassThroughRequestItem struct {
-	Request  gateway.BuilderRequest
-	Callback gateway.RequestCallback
+	Request                 gateway.BuilderRequest
+	RequestResponseCallback gateway.RequestResponseCallback
 }
 
 type SimplePassThroughParams struct {
@@ -133,13 +133,13 @@ func (params *OnePassThroughParams) passThrough(builder *gateway.Builder, middle
 
 	switch req := params.RequestItem.Request.(type) {
 	case *gateway.PostRequest:
-		copyBuilder = copyBuilder.Post(req, params.RequestItem.Callback)
+		copyBuilder = copyBuilder.Post(req, params.RequestItem.RequestResponseCallback)
 	case *gateway.DeleteRequest:
-		copyBuilder = copyBuilder.Delete(req, params.RequestItem.Callback)
+		copyBuilder = copyBuilder.Delete(req, params.RequestItem.RequestResponseCallback)
 	case *gateway.PutRequest:
-		copyBuilder = copyBuilder.Put(req, params.RequestItem.Callback)
+		copyBuilder = copyBuilder.Put(req, params.RequestItem.RequestResponseCallback)
 	case *gateway.GetRequest:
-		copyBuilder = copyBuilder.Get(req, params.RequestItem.Callback)
+		copyBuilder = copyBuilder.Get(req, params.RequestItem.RequestResponseCallback)
 	default:
 		panic("不支持的请求类型")
 	}
@@ -172,13 +172,13 @@ func (params *CommonPassThroughParams) passThrough(builder *gateway.Builder, mid
 	for _, requestItem := range params.RequestItems {
 		switch req := requestItem.Request.(type) {
 		case *gateway.PostRequest:
-			copyBuilder = copyBuilder.Post(req, requestItem.Callback)
+			copyBuilder = copyBuilder.Post(req, requestItem.RequestResponseCallback)
 		case *gateway.DeleteRequest:
-			copyBuilder = copyBuilder.Delete(req, requestItem.Callback)
+			copyBuilder = copyBuilder.Delete(req, requestItem.RequestResponseCallback)
 		case *gateway.PutRequest:
-			copyBuilder = copyBuilder.Put(req, requestItem.Callback)
+			copyBuilder = copyBuilder.Put(req, requestItem.RequestResponseCallback)
 		case *gateway.GetRequest:
-			copyBuilder = copyBuilder.Get(req, requestItem.Callback)
+			copyBuilder = copyBuilder.Get(req, requestItem.RequestResponseCallback)
 		default:
 			panic("不支持的请求类型")
 		}

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

@@ -2,6 +2,7 @@ package api
 
 import (
 	"bytes"
+	"encoding/json"
 	"git.sxidc.com/go-framework/baize/framework/core/infrastructure/logger"
 	"github.com/gin-gonic/gin"
 	"io"
@@ -82,6 +83,24 @@ func (c *Context) ReplaceBody(body []byte) error {
 	return nil
 }
 
+func (c *Context) ReadJsonBody(output any) error {
+	body, err := c.ReadBody()
+	if err != nil {
+		return err
+	}
+
+	return json.Unmarshal(body, output)
+}
+
+func (c *Context) ReplaceJsonBody(body any) error {
+	bodyBytes, err := json.Marshal(body)
+	if err != nil {
+		return err
+	}
+
+	return c.ReplaceBody(bodyBytes)
+}
+
 func (c *Context) GetAllQueryParams() map[string]string {
 	queryParams := make(map[string]string, 0)
 
@@ -101,3 +120,37 @@ func (c *Context) GetAllPathParams() map[string]string {
 
 	return pathParams
 }
+
+const (
+	tenantInfoKey = "context-tenant-info"
+	userInfoKey   = "context-user-info"
+)
+
+type TenantInfo interface {
+	GetID() string
+	GetName() string
+}
+
+type UserInfo interface {
+	GetID() string
+	GetUserName() string
+	GetName() string
+}
+
+func (c *Context) GetTenantInfo() TenantInfo {
+	tenantInfo, exist := c.Get(tenantInfoKey)
+	if !exist {
+		return nil
+	}
+
+	return tenantInfo.(TenantInfo)
+}
+
+func (c *Context) GetUserInfo() UserInfo {
+	userInfo, exist := c.Get(userInfoKey)
+	if !exist {
+		return nil
+	}
+
+	return userInfo.(UserInfo)
+}

+ 88 - 30
framework/gateway/builder.go

@@ -6,9 +6,11 @@ import (
 	"time"
 )
 
-type RequestParamsBindCallback func(c *api.Context)
-type RequestCallback func(c *api.Context, response *http_client.Response, resultMap map[string]any) error
-type GlobalRequestCallback func(c *api.Context, request BuilderRequest, historyRequests []BuilderRequest, resultMap map[string]any) error
+type FormBuilderRequestFunc func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error)
+
+type GlobalRequestResponseCallback func(c *api.Context, request BuilderRequest, historyRequests []BuilderRequest, resultMap map[string]any) error
+type RequestResponseCallback func(c *api.Context, response *http_client.Response, historyRequests []BuilderRequest, resultMap map[string]any) error
+
 type ResponseSuccessCallback func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any)
 type ResponseErrorCallback func(c *api.Context, err error)
 
@@ -36,35 +38,89 @@ func (builder *Builder) Url(httpMethod string, relativePath string) *Builder {
 	return copyBuilder
 }
 
-func (builder *Builder) Post(request *PostRequest, requestCallbackFunc RequestCallback) *Builder {
-	return builder.addRequest(newBuilderRequestItem(request, requestCallbackFunc))
-}
+func (builder *Builder) Post(request *PostRequest, requestCallbackFunc RequestResponseCallback) *Builder {
+	return builder.Request(func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
+		if request.Body == nil {
+			body, err := c.ReadBody()
+			if err != nil {
+				return nil, err
+			}
+
+			request.Body = body
+		}
 
-func (builder *Builder) PostStruct(request *PostRequest, requestCallbackFunc RequestCallback) *Builder {
-	return builder.addRequest(newBuilderRequestItem(request, requestCallbackFunc))
+		return &PostRequest{
+			Url:     request.Url,
+			Headers: request.Headers,
+			Body:    request.Body,
+		}, nil
+	}, requestCallbackFunc)
 }
 
-func (builder *Builder) Delete(request *DeleteRequest, requestCallbackFunc RequestCallback) *Builder {
-	return builder.addRequest(newBuilderRequestItem(request, requestCallbackFunc))
+func (builder *Builder) Delete(request *DeleteRequest, requestCallbackFunc RequestResponseCallback) *Builder {
+	return builder.Request(func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
+		if request.PathParams == nil {
+			request.PathParams = c.GetAllPathParams()
+		}
+
+		if request.QueryParams == nil {
+			request.QueryParams = c.GetAllQueryParams()
+		}
+
+		return &DeleteRequest{
+			Url:         request.Url,
+			Headers:     request.Headers,
+			PathParams:  request.PathParams,
+			QueryParams: request.QueryParams,
+		}, nil
+	}, requestCallbackFunc)
 }
 
-func (builder *Builder) Put(request *PutRequest, requestCallbackFunc RequestCallback) *Builder {
-	return builder.addRequest(newBuilderRequestItem(request, requestCallbackFunc))
+func (builder *Builder) Put(request *PutRequest, requestCallbackFunc RequestResponseCallback) *Builder {
+	return builder.Request(func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
+		if request.Body == nil {
+			body, err := c.ReadBody()
+			if err != nil {
+				return nil, err
+			}
+
+			request.Body = body
+		}
+
+		return &PutRequest{
+			Url:     request.Url,
+			Headers: request.Headers,
+			Body:    request.Body,
+		}, nil
+	}, requestCallbackFunc)
 }
 
-func (builder *Builder) Get(request *GetRequest, requestCallbackFunc RequestCallback) *Builder {
-	return builder.addRequest(newBuilderRequestItem(request, requestCallbackFunc))
+func (builder *Builder) Get(request *GetRequest, requestCallbackFunc RequestResponseCallback) *Builder {
+	return builder.Request(func(c *api.Context, historyRequests []BuilderRequest, resultMap map[string]any) (BuilderRequest, error) {
+		if request.PathParams == nil {
+			request.PathParams = c.GetAllPathParams()
+		}
+
+		if request.QueryParams == nil {
+			request.QueryParams = c.GetAllQueryParams()
+		}
+
+		return &GetRequest{
+			Url:         request.Url,
+			Headers:     request.Headers,
+			PathParams:  request.PathParams,
+			QueryParams: request.QueryParams,
+		}, nil
+	}, requestCallbackFunc)
 }
 
-func (builder *Builder) GlobalRequestParamsBindCallback(requestParamsBindCallback RequestParamsBindCallback) *Builder {
-	copyBuilder := builder.copy()
-	copyBuilder.params.requestParamsBindCallback = requestParamsBindCallback
-	return copyBuilder
+func (builder *Builder) Request(formBuilderRequestFunc FormBuilderRequestFunc, requestCallbackFunc RequestResponseCallback) *Builder {
+	return builder.addRequest(newBuilderRequestItem(formBuilderRequestFunc, requestCallbackFunc))
 }
 
-func (builder *Builder) GlobalRequestCallback(globalRequestCallback GlobalRequestCallback) *Builder {
+func (builder *Builder) GlobalRequestCallback(globalRequestResponseCallback GlobalRequestResponseCallback) *Builder {
 	copyBuilder := builder.copy()
-	copyBuilder.params.globalRequestCallback = globalRequestCallback
+	copyBuilder.params.globalRequestResponseCallback = globalRequestResponseCallback
 	return copyBuilder
 }
 
@@ -84,23 +140,25 @@ func (builder *Builder) Build(middlewares ...api.Handler) {
 	copyBuilder := builder.copy()
 	copyBuilder.router.AddRoute(builder.params.httpMethod, builder.params.relativePath, append(middlewares,
 		func(c *api.Context) {
-			if builder.params.requestParamsBindCallback != nil {
-				builder.params.requestParamsBindCallback(c)
-			}
-
 			httpRequest := builder.httpClient.NewRequest(http_client.WithNewRequestTimeout(time.Duration(builder.httpTimeoutSec) * time.Second))
 			historyRequests := make([]BuilderRequest, 0)
 			resultMap := make(map[string]any)
 
 			for _, requestItem := range builder.params.requestItems {
-				err := requestItem.request.Request(c, httpRequest, historyRequests, resultMap)
+				request, err := requestItem.formBuilderRequestFuc(c, historyRequests, resultMap)
+				if err != nil {
+					builder.params.responseErrorCallback(c, err)
+					return
+				}
+
+				err = request.Request(httpRequest)
 				if err != nil {
 					builder.params.responseErrorCallback(c, err)
 					return
 				}
 
-				if requestItem.requestCallbackFunc != nil {
-					err := requestItem.requestCallbackFunc(c, requestItem.request.Response(), resultMap)
+				if requestItem.requestResponseCallback != nil {
+					err := requestItem.requestResponseCallback(c, request.Response(), historyRequests, resultMap)
 					if err != nil {
 						builder.params.responseErrorCallback(c, err)
 						return
@@ -109,8 +167,8 @@ func (builder *Builder) Build(middlewares ...api.Handler) {
 					continue
 				}
 
-				if builder.params.globalRequestCallback != nil {
-					err := builder.params.globalRequestCallback(c, requestItem.request, historyRequests, resultMap)
+				if builder.params.globalRequestResponseCallback != nil {
+					err := builder.params.globalRequestResponseCallback(c, request, historyRequests, resultMap)
 					if err != nil {
 						builder.params.responseErrorCallback(c, err)
 						return
@@ -119,7 +177,7 @@ func (builder *Builder) Build(middlewares ...api.Handler) {
 					continue
 				}
 
-				historyRequests = append(historyRequests, requestItem.request)
+				historyRequests = append(historyRequests, request)
 			}
 
 			builder.params.responseSuccessCallback(c, historyRequests, resultMap)

+ 16 - 17
framework/gateway/builder_params.go

@@ -8,21 +8,20 @@ import (
 )
 
 type builderParams struct {
-	httpMethod                string
-	relativePath              string
-	requestItems              []*builderRequestItem
-	requestParamsBindCallback RequestParamsBindCallback
-	globalRequestCallback     GlobalRequestCallback
-	responseSuccessCallback   ResponseSuccessCallback
-	responseErrorCallback     ResponseErrorCallback
+	httpMethod                    string
+	relativePath                  string
+	requestItems                  []*builderRequestItem
+	globalRequestResponseCallback GlobalRequestResponseCallback
+	responseSuccessCallback       ResponseSuccessCallback
+	responseErrorCallback         ResponseErrorCallback
 }
 
 func newBuilderParams() *builderParams {
 	return &builderParams{
-		httpMethod:            "",
-		relativePath:          "",
-		requestItems:          make([]*builderRequestItem, 0),
-		globalRequestCallback: nil,
+		httpMethod:                    "",
+		relativePath:                  "",
+		requestItems:                  make([]*builderRequestItem, 0),
+		globalRequestResponseCallback: nil,
 		responseSuccessCallback: func(c *api.Context, historyRequests []BuilderRequest, customResultMap map[string]any) {
 			c.Status(http.StatusOK)
 
@@ -57,11 +56,11 @@ func newBuilderParams() *builderParams {
 
 func (params *builderParams) copy() *builderParams {
 	return &builderParams{
-		httpMethod:              params.httpMethod,
-		relativePath:            params.relativePath,
-		requestItems:            params.requestItems,
-		globalRequestCallback:   params.globalRequestCallback,
-		responseSuccessCallback: params.responseSuccessCallback,
-		responseErrorCallback:   params.responseErrorCallback,
+		httpMethod:                    params.httpMethod,
+		relativePath:                  params.relativePath,
+		requestItems:                  params.requestItems,
+		globalRequestResponseCallback: params.globalRequestResponseCallback,
+		responseSuccessCallback:       params.responseSuccessCallback,
+		responseErrorCallback:         params.responseErrorCallback,
 	}
 }

+ 15 - 158
framework/gateway/builder_request.go

@@ -1,51 +1,21 @@
 package gateway
 
 import (
-	"git.sxidc.com/go-framework/baize/framework/core/api"
 	"git.sxidc.com/go-tools/utils/http_client"
 	"net/http"
 )
 
-type FormUrlFunc func(c *api.Context) (string, error)
-type FormHeadersFunc func(c *api.Context, historyRequests []BuilderRequest, customResultMap map[string]any) (map[string]string, error)
-type FormBodyFunc func(c *api.Context, historyRequests []BuilderRequest, customResultMap map[string]any) (any, error)
-type FormQueryParamsFunc func(c *api.Context, historyRequests []BuilderRequest, customResultMap map[string]any) (map[string]string, error)
-type FormPathParamsFunc func(c *api.Context, historyRequests []BuilderRequest, customResultMap map[string]any) (map[string]string, error)
-
-func DefaultFormHeadersFunc(c *api.Context, _ []BuilderRequest, _ map[string]any) (map[string]string, error) {
-	return c.GetHeaders(), nil
-}
-
-func DefaultFormBodyFunc(c *api.Context, _ []BuilderRequest, _ map[string]any) (any, error) {
-	return c.ReadBody()
-}
-
-func DefaultFormQueryParamsFunc(c *api.Context, _ []BuilderRequest, _ map[string]any) (map[string]string, error) {
-	return c.GetAllQueryParams(), nil
-}
-
-func DefaultFormPathParamsFunc(c *api.Context, _ []BuilderRequest, _ map[string]any) (map[string]string, error) {
-	return c.GetAllPathParams(), nil
-}
-
 type BuilderRequest interface {
 	HttpMethod() string
-	RequestUrl() string
-	Request(c *api.Context, request *http_client.Request, historyRequests []BuilderRequest, customResultMap map[string]any) error
+	Request(request *http_client.Request) error
 	Response() *http_client.Response
 }
 
 type PostRequest struct {
-	// 静态配置
 	Url     string
 	Headers map[string]string
 	Body    any
 
-	// 动态配置
-	DynamicUrl    FormUrlFunc
-	DynamicHeader FormHeadersFunc
-	DynamicBody   FormBodyFunc
-
 	response *http_client.Response
 }
 
@@ -57,27 +27,9 @@ func (req *PostRequest) RequestUrl() string {
 	return req.Url
 }
 
-func (req *PostRequest) Request(c *api.Context, request *http_client.Request, historyRequests []BuilderRequest, customResultMap map[string]any) error {
-	if req.Headers == nil {
-		req.Headers = DefaultFormHeadersFunc
-	}
-
-	if req.Body == nil {
-		req.Body = DefaultFormBodyFunc
-	}
-
-	headers, err := req.Headers(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
-	body, err := req.Body(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
-	response, err := request.Post(req.Url, body,
-		http_client.WithRequestHeaders(headers))
+func (req *PostRequest) Request(request *http_client.Request) error {
+	response, err := request.Post(req.Url, req.Body,
+		http_client.WithRequestHeaders(req.Headers))
 	if err != nil {
 		return err
 	}
@@ -92,18 +44,11 @@ func (req *PostRequest) Response() *http_client.Response {
 }
 
 type DeleteRequest struct {
-	// 静态配置
 	Url         string
 	Headers     map[string]string
 	PathParams  map[string]string
 	QueryParams map[string]string
 
-	// 动态配置
-	DynamicUrl         FormUrlFunc
-	DynamicHeader      FormHeadersFunc
-	DynamicPathParams  FormPathParamsFunc
-	DynamicQueryParams FormQueryParamsFunc
-
 	response *http_client.Response
 }
 
@@ -111,42 +56,11 @@ func (req *DeleteRequest) HttpMethod() string {
 	return http.MethodDelete
 }
 
-func (req *DeleteRequest) RequestUrl() string {
-	return req.Url
-}
-
-func (req *DeleteRequest) Request(c *api.Context, request *http_client.Request, historyRequests []BuilderRequest, customResultMap map[string]any) error {
-	if req.Headers == nil {
-		req.Headers = DefaultFormHeadersFunc
-	}
-
-	if req.QueryParams == nil {
-		req.QueryParams = DefaultFormQueryParamsFunc
-	}
-
-	if req.PathParams == nil {
-		req.PathParams = DefaultFormPathParamsFunc
-	}
-
-	headers, err := req.Headers(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
-	queryParams, err := req.QueryParams(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
-	pathParams, err := req.PathParams(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
+func (req *DeleteRequest) Request(request *http_client.Request) error {
 	response, err := request.Delete(req.Url,
-		http_client.WithRequestHeaders(headers),
-		http_client.WithRequestPathParams(pathParams),
-		http_client.WithRequestQueryParams(queryParams))
+		http_client.WithRequestHeaders(req.Headers),
+		http_client.WithRequestPathParams(req.PathParams),
+		http_client.WithRequestQueryParams(req.QueryParams))
 	if err != nil {
 		return err
 	}
@@ -166,11 +80,6 @@ type PutRequest struct {
 	Headers map[string]string
 	Body    any
 
-	// 动态配置
-	DynamicUrl    FormUrlFunc
-	DynamicHeader FormHeadersFunc
-	DynamicBody   FormBodyFunc
-
 	response *http_client.Response
 }
 
@@ -182,27 +91,9 @@ func (req *PutRequest) RequestUrl() string {
 	return req.Url
 }
 
-func (req *PutRequest) Request(c *api.Context, request *http_client.Request, historyRequests []BuilderRequest, customResultMap map[string]any) error {
-	if req.Headers == nil {
-		req.Headers = DefaultFormHeadersFunc
-	}
-
-	if req.Body == nil {
-		req.Body = DefaultFormBodyFunc
-	}
-
-	headers, err := req.Headers(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
-	body, err := req.Body(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
-	response, err := request.Put(req.Url, body,
-		http_client.WithRequestHeaders(headers))
+func (req *PutRequest) Request(request *http_client.Request) error {
+	response, err := request.Put(req.Url, req.Body,
+		http_client.WithRequestHeaders(req.Headers))
 	if err != nil {
 		return err
 	}
@@ -217,18 +108,11 @@ func (req *PutRequest) Response() *http_client.Response {
 }
 
 type GetRequest struct {
-	// 静态配置
 	Url         string
 	Headers     map[string]string
 	PathParams  map[string]string
 	QueryParams map[string]string
 
-	// 动态配置
-	DynamicUrl         FormUrlFunc
-	DynamicHeader      FormHeadersFunc
-	DynamicPathParams  FormPathParamsFunc
-	DynamicQueryParams FormQueryParamsFunc
-
 	response *http_client.Response
 }
 
@@ -240,38 +124,11 @@ func (req *GetRequest) RequestUrl() string {
 	return req.Url
 }
 
-func (req *GetRequest) Request(c *api.Context, request *http_client.Request, historyRequests []BuilderRequest, customResultMap map[string]any) error {
-	if req.Headers == nil {
-		req.Headers = DefaultFormHeadersFunc
-	}
-
-	if req.QueryParams == nil {
-		req.QueryParams = DefaultFormQueryParamsFunc
-	}
-
-	if req.PathParams == nil {
-		req.PathParams = DefaultFormPathParamsFunc
-	}
-
-	headers, err := req.Headers(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
-	queryParams, err := req.QueryParams(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
-	pathParams, err := req.PathParams(c, historyRequests, customResultMap)
-	if err != nil {
-		return err
-	}
-
+func (req *GetRequest) Request(request *http_client.Request) error {
 	response, err := request.Get(req.Url,
-		http_client.WithRequestHeaders(headers),
-		http_client.WithRequestPathParams(pathParams),
-		http_client.WithRequestQueryParams(queryParams))
+		http_client.WithRequestHeaders(req.Headers),
+		http_client.WithRequestPathParams(req.PathParams),
+		http_client.WithRequestQueryParams(req.QueryParams))
 	if err != nil {
 		return err
 	}

+ 5 - 5
framework/gateway/builder_request_item.go

@@ -1,13 +1,13 @@
 package gateway
 
 type builderRequestItem struct {
-	request             BuilderRequest
-	requestCallbackFunc RequestCallback
+	formBuilderRequestFuc   FormBuilderRequestFunc
+	requestResponseCallback RequestResponseCallback
 }
 
-func newBuilderRequestItem(request BuilderRequest, callbackFunc RequestCallback) *builderRequestItem {
+func newBuilderRequestItem(formBuilderRequestFuc FormBuilderRequestFunc, requestResponseCallback RequestResponseCallback) *builderRequestItem {
 	return &builderRequestItem{
-		request:             request,
-		requestCallbackFunc: callbackFunc,
+		formBuilderRequestFuc:   formBuilderRequestFuc,
+		requestResponseCallback: requestResponseCallback,
 	}
 }

+ 63 - 0
framework/gateway/common.go

@@ -0,0 +1,63 @@
+package gateway
+
+import (
+	"git.sxidc.com/go-framework/baize/framework/core/api"
+	"git.sxidc.com/go-tools/utils/strutils"
+)
+
+func AddJsonBodyTenantIDAndUserID(c *api.Context, tenantIDField string, userIDField string) (map[string]any, error) {
+	bodyMap := make(map[string]any)
+	err := c.ReadJsonBody(&bodyMap)
+	if err != nil {
+		return nil, err
+	}
+
+	_, ok := bodyMap[tenantIDField]
+	if !ok {
+		tenantInfo := c.GetTenantInfo()
+
+		if tenantInfo != nil {
+			bodyMap[tenantIDField] = tenantInfo.GetID()
+		} else {
+			bodyMap[tenantIDField] = "guest-" + strutils.SimpleUUID()[:26]
+		}
+	}
+
+	_, ok = bodyMap[userIDField]
+	if !ok {
+		userInfo := c.GetUserInfo()
+
+		if userInfo != nil {
+			bodyMap[userIDField] = userInfo.GetID()
+		} else {
+			bodyMap[userIDField] = "guest-" + strutils.SimpleUUID()[:26]
+		}
+	}
+
+	err = c.ReplaceJsonBody(bodyMap)
+	if err != nil {
+		return nil, err
+	}
+
+	return bodyMap, nil
+}
+
+func AddQueryParamsTenantIDAndUserID(c *api.Context, tenantIDField string, userIDField string) (map[string]string, error) {
+	queryParams := c.GetAllQueryParams()
+
+	if c.GetTenantInfo() != nil {
+		_, ok := queryParams[tenantIDField]
+		if !ok {
+			queryParams[tenantIDField] = c.GetTenantInfo().GetID()
+		}
+	}
+
+	if c.GetUserInfo() != nil {
+		_, ok := queryParams[userIDField]
+		if !ok {
+			queryParams[userIDField] = c.GetUserInfo().GetID()
+		}
+	}
+
+	return queryParams, nil
+}