6
0

feat(big-data): get_user_profile 支持 ip / device_id 筛选透传

前端可按 IP / 设备号查账号,但 SDK 的 GetUserProfileParam / Request / body
结构体缺少 ip、device_id 字段,导致这两个筛选条件被静默丢弃、发不到大数据。
补齐三处结构体字段及 GetBodyReader、CreateGetUserProfileRequest 的透传,
并新增 body 序列化测试锁定该行为。
This commit is contained in:
陈华健 2026-07-03 15:36:20 +08:00
parent d3eef1328e
commit ab87f0b5ee
2 changed files with 48 additions and 0 deletions

View File

@ -25,6 +25,8 @@ type GetUserProfileParam struct {
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"` // 区间 [开始, 结束]
@ -52,6 +54,8 @@ type GetUserProfileRequest struct {
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"`
@ -81,6 +85,8 @@ type getUserProfileBody struct {
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"`
@ -108,6 +114,8 @@ func (request *GetUserProfileRequest) GetBodyReader() io.Reader {
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),
@ -166,6 +174,8 @@ func CreateGetUserProfileRequest(token string, param GetUserProfileParam) *GetUs
TradeOrderId: param.TradeOrderId,
GameSign: param.GameSign,
GameId: param.GameId,
DeviceId: param.DeviceId,
IP: param.IP,
RegisterDate: param.RegisterDate,
LastLoginDate: param.LastLoginDate,
LastPayDate: param.LastPayDate,

View File

@ -0,0 +1,38 @@
package big_data
import (
"encoding/json"
"io"
"testing"
)
// TestGetBodyReaderCarriesIPAndDeviceID 验证 ip / device_id 能被序列化进发往大数据的请求体。
// 这两个字段此前在 SDK 里缺失,导致前端传的 IP/设备号被静默丢弃。
func TestGetBodyReaderCarriesIPAndDeviceID(t *testing.T) {
req := CreateGetUserProfileRequest("token-x", GetUserProfileParam{
IP: []string{"59.51.36.195"},
DeviceId: []string{"dev-abc", "dev-def"},
Page: 1,
PageSize: 50,
})
raw, err := io.ReadAll(req.GetBodyReader())
if err != nil {
t.Fatalf("读取 body 失败: %v", err)
}
var body struct {
IP []string `json:"ip"`
DeviceId []string `json:"device_id"`
}
if err := json.Unmarshal(raw, &body); err != nil {
t.Fatalf("反序列化 body 失败: %v, 原始=%s", err, raw)
}
if len(body.IP) != 1 || body.IP[0] != "59.51.36.195" {
t.Errorf("ip 未正确透传, 期望 [59.51.36.195], 实际 %v, 原始=%s", body.IP, raw)
}
if len(body.DeviceId) != 2 || body.DeviceId[0] != "dev-abc" || body.DeviceId[1] != "dev-def" {
t.Errorf("device_id 未正确透传, 期望 [dev-abc dev-def], 实际 %v, 原始=%s", body.DeviceId, raw)
}
}