package gateway import ( "git.sxidc.com/go-tools/utils/strutils" ) func AddJsonBodyTenantIDAndUserInfo(requestBuilder *RequestBuilder, tenantIDParamsName string, userIDParamsName string, operatorUserNameParamsName string) error { jsonBody, err := requestBuilder.c.GetJsonBody() if err != nil { return err } if strutils.IsStringNotEmpty(tenantIDParamsName) { tenantID := jsonBody.Get(tenantIDParamsName) if tenantID == nil { tenantInfo := requestBuilder.c.GetTenantInfo() if tenantInfo != nil { jsonBody.Set(tenantIDParamsName, tenantInfo.GetID()) } else { jsonBody.Set(tenantIDParamsName, "guest-"+strutils.SimpleUUID()[:26]) } } } if strutils.IsStringNotEmpty(userIDParamsName) { userID := jsonBody.Get(userIDParamsName) if userID == nil { userInfo := requestBuilder.c.GetUserInfo() if userInfo != nil { jsonBody.Set(userIDParamsName, userInfo.GetID()) } else { jsonBody.Set(userIDParamsName, "guest-"+strutils.SimpleUUID()[:26]) } } } if strutils.IsStringNotEmpty(operatorUserNameParamsName) { operatorUserName := jsonBody.Get(operatorUserNameParamsName) if operatorUserName == nil { userInfo := requestBuilder.c.GetUserInfo() if userInfo != nil { jsonBody.Set(operatorUserNameParamsName, userInfo.GetUserName()) } else { jsonBody.Set(operatorUserNameParamsName, "guest-"+strutils.SimpleUUID()[:26]) } } } return nil } func AddQueryParamsTenantIDAndUserInfo(requestBuilder *RequestBuilder, tenantIDParamsName string, userIDParamsName string, operatorUserNameParamsName string) error { queryParams := requestBuilder.c.GetQueryParams() if requestBuilder.c.GetTenantInfo() != nil && strutils.IsStringNotEmpty(tenantIDParamsName) { tenantID := queryParams.Get(tenantIDParamsName) if strutils.IsStringEmpty(tenantID) { queryParams.Set(tenantIDParamsName, requestBuilder.c.GetTenantInfo().GetID()) } } if requestBuilder.c.GetUserInfo() != nil && strutils.IsStringNotEmpty(userIDParamsName) { userID := queryParams.Get(userIDParamsName) if strutils.IsStringEmpty(userID) { queryParams.Set(userIDParamsName, requestBuilder.c.GetUserInfo().GetID()) } } if requestBuilder.c.GetUserInfo() != nil && strutils.IsStringNotEmpty(operatorUserNameParamsName) { operatorUserName := queryParams.Get(operatorUserNameParamsName) if strutils.IsStringEmpty(operatorUserName) { queryParams.Set(operatorUserNameParamsName, requestBuilder.c.GetUserInfo().GetUserName()) } } return nil }