幸运24-统计-个人统计-处理分页下标越界

This commit is contained in:
2025-08-13 10:50:31 +08:00
parent 619abef37c
commit 177d53a13f

View File

@@ -199,10 +199,27 @@ public class Lucky24RecordAdminService {
comparator = comparator.reversed();
}
list.sort(comparator);
int startIndex = (pageNo -1) * pageSize;
int endIndex = Math.min(startIndex + pageSize, list.size());
List<Lucky24PersonalStat> subList = list.subList(startIndex, endIndex);
int startIndex = (pageNo -1) * pageSize;
// 确保startIndex不会超过列表大小
if (startIndex > list.size()) {
startIndex = list.size();
}
int endIndex = Math.min(startIndex + pageSize, list.size());
// 确保endIndex不小于startIndex
if (endIndex < startIndex) {
endIndex = startIndex;
}
// 如果列表为空或起始索引超出范围,则创建空的子列表
List<Lucky24PersonalStat> subList = (list.isEmpty() || startIndex >= list.size())
? Collections.emptyList()
: list.subList(startIndex, endIndex);
if (CollectionUtils.isEmpty(subList)){
return new Lucky24PersonalStatVo(totalInput, totalOutput, totalProductionRatio, new PageResult<>(page));
}
List<Long> uidList = subList.stream().map(Lucky24PersonalStat::getUid).collect(Collectors.toList());
Map<Long, Users> usersMap = usersService.getUsersMapByUids(uidList);
Map<Long, String> userRechargeLevelMap = userRechargeLevelService.mapLevelByUid(uidList);