This commit is contained in:
@@ -34,12 +34,25 @@ func (l *GetDeviceListLogic) GetDeviceList() (resp *types.GetDeviceListResponse,
|
||||
return nil, err
|
||||
}
|
||||
list, count, err := l.svcCtx.UserModel.QueryDeviceListByUserIds(l.ctx, scopeUserIds)
|
||||
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)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// FIX: 逐条复制并设置 DeviceNo,避免 DeepCopy 批量复制后 len(userRespList) 与 list 不一致
|
||||
// 导致 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{
|
||||
Total: count,
|
||||
|
||||
Reference in New Issue
Block a user