6
0
gaore-common-sdk-go/services/big-data/get_user_profile.go
陈华健 3fb4728865 feat(big-data): get_user_profile 支持 ip / device_id 筛选透传
前端可按 IP / 设备号查账号,但 SDK 的 GetUserProfileParam / Request / body
结构体缺少 ip、device_id 字段,导致这两个筛选条件被静默丢弃、发不到大数据。
补齐三处结构体字段及 GetBodyReader、CreateGetUserProfileRequest 的透传。
2026-07-03 16:08:34 +08:00

203 lines
8.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package big_data
import (
"bytes"
"encoding/json"
"io"
"strings"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
)
// GetUserProfileParam 用户筛选/圈选查询参数
// 说明:金额类筛选用 *int64未设置(nil)时不参与筛选;切片为空表示不限定该条件
type GetUserProfileParam struct {
UserName []string `json:"user_name"`
UserName2 []string `json:"user_name2"`
Uid []string `json:"uid"`
RoleId []string `json:"role_id"`
RoleName []string `json:"role_name"`
RoleNameLike string `json:"role_name_like"`
LabelId []int `json:"label_id"`
WeworkTag []string `json:"wework_tag"`
OrderId []string `json:"order_id"`
TradeOrderId []string `json:"trade_order_id"`
GameSign []string `json:"game_sign"`
GameId []string `json:"game_id"`
DeviceId []string `json:"device_id"` // 设备号集合,空表示不限定
IP []string `json:"ip"` // IP 集合,空表示不限定
RegisterDate []string `json:"register_date"` // 区间 [开始, 结束]
LastLoginDate []string `json:"last_login_date"` // 区间 [开始, 结束]
LastPayDate []string `json:"last_pay_date"` // 区间 [开始, 结束]
PayAmtAccMin *float64 `json:"pay_amt_acc_min"`
PayAmtAccMax *float64 `json:"pay_amt_acc_max"`
LastPayAmountMin *float64 `json:"last_pay_amount_min"`
LastPayAmountMax *float64 `json:"last_pay_amount_max"`
Page int `json:"page"`
PageSize int `json:"page_size"`
XDebug string `json:"x_debug"` // 测试环境调试头,正式调用可留空
}
// GetUserProfileRequest 用户筛选/圈选查询请求
type GetUserProfileRequest struct {
*requests.JsonRequest
UserName []string `position:"Json" field:"user_name"`
UserName2 []string `position:"Json" field:"user_name2"`
Uid []string `position:"Json" field:"uid"`
RoleId []string `position:"Json" field:"role_id"`
RoleName []string `position:"Json" field:"role_name"`
RoleNameLike string `position:"Json" field:"role_name_like"`
LabelId []int `position:"Json" field:"label_id"`
WeworkTag []string `position:"Json" field:"wework_tag"`
OrderId []string `position:"Json" field:"order_id"`
TradeOrderId []string `position:"Json" field:"trade_order_id"`
GameSign []string `position:"Json" field:"game_sign"`
GameId []string `position:"Json" field:"game_id"`
DeviceId []string `position:"Json" field:"device_id"`
IP []string `position:"Json" field:"ip"`
RegisterDate []string `position:"Json" field:"register_date"`
LastLoginDate []string `position:"Json" field:"last_login_date"`
LastPayDate []string `position:"Json" field:"last_pay_date"`
PayAmtAccMin *float64 `position:"Json" field:"pay_amt_acc_min"`
PayAmtAccMax *float64 `position:"Json" field:"pay_amt_acc_max"`
LastPayAmountMin *float64 `position:"Json" field:"last_pay_amount_min"`
LastPayAmountMax *float64 `position:"Json" field:"last_pay_amount_max"`
Page int `position:"Json" field:"page"`
PageSize int `position:"Json" field:"page_size"`
Authorization string `position:"Header" field:"Authorization"`
XDebug string `position:"Header" field:"x-debug"`
}
// getUserProfileBody 自定义请求体序列化结构,绕开 core 的反射序列化(JsonParams)
// - 金额字段 *float64 + omitempty未设置(nil)时该字段不出现在 JSON 中,避免 0 被 DMS 当成真实筛选条件;
// - 切片字段统一为非 nil 空数组 []:避免 nil 被序列化成 null 触发 DMS 类型校验失败。
type getUserProfileBody struct {
UserName []string `json:"user_name"`
UserName2 []string `json:"user_name2"`
Uid []string `json:"uid"`
RoleId []string `json:"role_id"`
RoleName []string `json:"role_name"`
RoleNameLike string `json:"role_name_like,omitempty"`
LabelId []int `json:"label_id"`
WeworkTag []string `json:"wework_tag"`
OrderId []string `json:"order_id"`
TradeOrderId []string `json:"trade_order_id"`
GameSign []string `json:"game_sign"`
GameId []string `json:"game_id"`
DeviceId []string `json:"device_id"`
IP []string `json:"ip"`
RegisterDate []string `json:"register_date"`
LastLoginDate []string `json:"last_login_date"`
LastPayDate []string `json:"last_pay_date"`
PayAmtAccMin *float64 `json:"pay_amt_acc_min,omitempty"`
PayAmtAccMax *float64 `json:"pay_amt_acc_max,omitempty"`
LastPayAmountMin *float64 `json:"last_pay_amount_min,omitempty"`
LastPayAmountMax *float64 `json:"last_pay_amount_max,omitempty"`
Page int `json:"page"`
PageSize int `json:"page_size"`
}
// GetBodyReader 覆盖 JsonRequest 默认实现,使用自定义结构序列化 body。
// 鉴权头(Authorization / x-debug)仍由 core 的 InitParam 按 Header 字段设置,不受影响。
func (request *GetUserProfileRequest) GetBodyReader() io.Reader {
body := getUserProfileBody{
UserName: emptyStrSlice(request.UserName),
UserName2: emptyStrSlice(request.UserName2),
Uid: emptyStrSlice(request.Uid),
RoleId: emptyStrSlice(request.RoleId),
RoleName: emptyStrSlice(request.RoleName),
RoleNameLike: request.RoleNameLike,
LabelId: emptyIntSlice(request.LabelId),
WeworkTag: emptyStrSlice(request.WeworkTag),
OrderId: emptyStrSlice(request.OrderId),
TradeOrderId: emptyStrSlice(request.TradeOrderId),
GameSign: emptyStrSlice(request.GameSign),
GameId: emptyStrSlice(request.GameId),
DeviceId: emptyStrSlice(request.DeviceId),
IP: emptyStrSlice(request.IP),
RegisterDate: emptyStrSlice(request.RegisterDate),
LastLoginDate: emptyStrSlice(request.LastLoginDate),
LastPayDate: emptyStrSlice(request.LastPayDate),
PayAmtAccMin: request.PayAmtAccMin,
PayAmtAccMax: request.PayAmtAccMax,
LastPayAmountMin: request.LastPayAmountMin,
LastPayAmountMax: request.LastPayAmountMax,
Page: request.Page,
PageSize: request.PageSize,
}
b, err := json.Marshal(body)
if err != nil {
return strings.NewReader("")
}
return bytes.NewReader(b)
}
// emptyStrSlice 将 nil 切片转成非 nil 空切片,避免序列化成 JSON null
func emptyStrSlice(s []string) []string {
if s == nil {
return []string{}
}
return s
}
// emptyIntSlice 同 emptyStrSlice针对 label_id 等 []int 字段
func emptyIntSlice(s []int) []int {
if s == nil {
return []int{}
}
return s
}
// GetUserProfileResponse 用户筛选/圈选查询响应返回不做处理data 原样透出)
type GetUserProfileResponse struct {
*responses.BaseResponse
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data"`
}
// CreateGetUserProfileRequest 创建用户筛选/圈选查询请求
// token 为 GetToken 返回的 data.token直接放入 Authorization 头
func CreateGetUserProfileRequest(token string, param GetUserProfileParam) *GetUserProfileRequest {
req := &GetUserProfileRequest{
JsonRequest: &requests.JsonRequest{},
UserName: param.UserName,
UserName2: param.UserName2,
Uid: param.Uid,
RoleId: param.RoleId,
RoleName: param.RoleName,
RoleNameLike: param.RoleNameLike,
LabelId: param.LabelId,
WeworkTag: param.WeworkTag,
OrderId: param.OrderId,
TradeOrderId: param.TradeOrderId,
GameSign: param.GameSign,
GameId: param.GameId,
DeviceId: param.DeviceId,
IP: param.IP,
RegisterDate: param.RegisterDate,
LastLoginDate: param.LastLoginDate,
LastPayDate: param.LastPayDate,
PayAmtAccMin: param.PayAmtAccMin,
PayAmtAccMax: param.PayAmtAccMax,
LastPayAmountMin: param.LastPayAmountMin,
LastPayAmountMax: param.LastPayAmountMax,
Page: param.Page,
PageSize: param.PageSize,
Authorization: token,
XDebug: param.XDebug,
}
req.InitWithApiInfo(HOST, VERSION, "/api/internal/v1/get_user_profile")
req.Method = requests.POST
req.Scheme = requests.HTTPS
return req
}
// CreateGetUserProfileResponse 创建用户筛选/圈选查询响应
func CreateGetUserProfileResponse() *GetUserProfileResponse {
return &GetUserProfileResponse{
BaseResponse: &responses.BaseResponse{},
}
}