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.apiContext.GetJsonBody() if err != nil { return err } if strutils.IsStringNotEmpty(tenantIDParamsName) { tenantID := jsonBody.Get(tenantIDParamsName) if tenantID == nil { tenantInfo := requestBuilder.c.apiContext.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.apiContext.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.apiContext.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.apiContext.GetQueryParams() if requestBuilder.c.apiContext.GetTenantInfo() != nil && strutils.IsStringNotEmpty(tenantIDParamsName) { tenantID := queryParams.Get(tenantIDParamsName) if strutils.IsStringEmpty(tenantID) { queryParams.Set(tenantIDParamsName, requestBuilder.c.apiContext.GetTenantInfo().GetID()) } } if requestBuilder.c.apiContext.GetUserInfo() != nil && strutils.IsStringNotEmpty(userIDParamsName) { userID := queryParams.Get(userIDParamsName) if strutils.IsStringEmpty(userID) { queryParams.Set(userIDParamsName, requestBuilder.c.apiContext.GetUserInfo().GetID()) } } if requestBuilder.c.apiContext.GetUserInfo() != nil && strutils.IsStringNotEmpty(operatorUserNameParamsName) { operatorUserName := queryParams.Get(operatorUserNameParamsName) if strutils.IsStringEmpty(operatorUserName) { queryParams.Set(operatorUserNameParamsName, requestBuilder.c.apiContext.GetUserInfo().GetUserName()) } } return nil }