fix: QueryUserInfo 设备列表改为家庭范围查询,修复 email 用户 user_devices 为空的问题
Some checks failed
Build docker and publish / build (20.15.1) (push) Failing after 7m43s

This commit is contained in:
shanshanzhong 2026-03-31 17:07:09 -07:00
parent 06e4698888
commit 2362b67634

View File

@ -45,10 +45,26 @@ func (l *QueryUserInfoLogic) QueryUserInfo() (resp *types.User, err error) {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidAccess), "Invalid Access")
}
tool.DeepCopy(resp, u)
for i, d := range u.UserDevices {
if i < len(resp.UserDevices) {
resp.UserDevices[i].DeviceNo = tool.DeviceIdToHash(d.Id)
// 用家庭范围查设备,而不是只看当前用户自己的 UserDevices
scopeHelper := newFamilyScopeHelper(l.ctx, l.svcCtx)
scopeUserIds, scopeErr := scopeHelper.resolveScopedUserIds(u.Id)
if scopeErr != nil {
l.Errorw("resolve scoped user ids failed", logger.Field("user_id", u.Id), logger.Field("error", scopeErr.Error()))
scopeUserIds = []int64{u.Id}
}
deviceList, _, deviceErr := l.svcCtx.UserModel.QueryDeviceListByUserIds(l.ctx, scopeUserIds)
if deviceErr != nil {
l.Errorw("query device list failed", logger.Field("user_id", u.Id), logger.Field("error", deviceErr.Error()))
} else {
userDevices := make([]types.UserDevice, 0, len(deviceList))
tool.DeepCopy(&userDevices, deviceList)
for i, d := range deviceList {
if i < len(userDevices) {
userDevices[i].DeviceNo = tool.DeviceIdToHash(d.Id)
}
}
resp.UserDevices = userDevices
}
// refer_code 为空时自动生成
if resp.ReferCode == "" {