This commit is contained in:
@@ -34,12 +34,25 @@ func (l *GetDeviceListLogic) GetDeviceList() (resp *types.GetDeviceListResponse,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
list, count, err := l.svcCtx.UserModel.QueryDeviceListByUserIds(l.ctx, scopeUserIds)
|
list, count, err := l.svcCtx.UserModel.QueryDeviceListByUserIds(l.ctx, scopeUserIds)
|
||||||
userRespList := make([]types.UserDevice, 0)
|
if err != nil {
|
||||||
tool.DeepCopy(&userRespList, list)
|
return nil, err
|
||||||
for i, d := range list {
|
}
|
||||||
if i < len(userRespList) {
|
// FIX: 逐条复制并设置 DeviceNo,避免 DeepCopy 批量复制后 len(userRespList) 与 list 不一致
|
||||||
userRespList[i].DeviceNo = tool.DeviceIdToHash(d.Id)
|
// 导致 if i < len(userRespList) 条件失效、只有第一条设备号被正确赋值的 bug。
|
||||||
}
|
// 原始代码(保留以供对照):
|
||||||
|
// userRespList := make([]types.UserDevice, 0)
|
||||||
|
// tool.DeepCopy(&userRespList, list)
|
||||||
|
// for i, d := range list {
|
||||||
|
// if i < len(userRespList) {
|
||||||
|
// userRespList[i].DeviceNo = tool.DeviceIdToHash(d.Id)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
userRespList := make([]types.UserDevice, 0, len(list))
|
||||||
|
for _, d := range list {
|
||||||
|
var item types.UserDevice
|
||||||
|
tool.DeepCopy(&item, d)
|
||||||
|
item.DeviceNo = tool.DeviceIdToHash(d.Id)
|
||||||
|
userRespList = append(userRespList, item)
|
||||||
}
|
}
|
||||||
resp = &types.GetDeviceListResponse{
|
resp = &types.GetDeviceListResponse{
|
||||||
Total: count,
|
Total: count,
|
||||||
|
|||||||
Reference in New Issue
Block a user