| | |
| | | List<ActivityResponse> content = page.getContent().stream() |
| | | .map(activity -> { |
| | | ActivityResponse response = new ActivityResponse(activity); |
| | | // 设置参赛人数(审核通过的报名数量) |
| | | Long playerCountLong = activityPlayerRepository.countByActivityId(activity.getId()); |
| | | int playerCount = playerCountLong != null ? playerCountLong.intValue() : 0; |
| | | // 设置参赛人数(只统计第一阶段的审核通过学员人数) |
| | | int playerCount = 0; |
| | | Activity firstStage = activityRepository.findFirstStageByActivityId(activity.getId()); |
| | | if (firstStage != null) { |
| | | // 如果有第一阶段,统计第一阶段的审核通过人数 |
| | | Long playerCountLong = activityPlayerRepository.countByStageIdAndState(firstStage.getId(), 1); |
| | | playerCount = playerCountLong != null ? playerCountLong.intValue() : 0; |
| | | } else { |
| | | // 如果没有阶段,统计活动本身的审核通过人数 |
| | | Long playerCountLong = activityPlayerRepository.countByActivityIdAndState(activity.getId(), 1); |
| | | playerCount = playerCountLong != null ? playerCountLong.intValue() : 0; |
| | | } |
| | | response.setPlayerCount(playerCount); |
| | | return response; |
| | | }) |
| | |
| | | // 获取所有状态为1的活动 |
| | | List<Activity> allActivities = activityRepository.findByStateOrderByPidAscNameAsc(1); |
| | | |
| | | // 过滤:只保留比赛阶段(pid>0) |
| | | // 过滤:只保留主比赛(pid=0) |
| | | List<Activity> filteredActivities = allActivities.stream() |
| | | .filter(activity -> activity.getPid() > 0) |
| | | .filter(activity -> activity.getPid() == 0) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 转换为ActivityResponse,包含父比赛信息 |
| | | // 转换为ActivityResponse |
| | | List<ActivityResponse> result = filteredActivities.stream() |
| | | .map(activity -> { |
| | | ActivityResponse response = new ActivityResponse(activity); |
| | | // 设置参赛人数(审核通过的报名数量) |
| | | // 设置参赛人数(所有阶段的报名数量总和) |
| | | Long playerCountLong = activityPlayerRepository.countByActivityId(activity.getId()); |
| | | int playerCount = playerCountLong != null ? playerCountLong.intValue() : 0; |
| | | response.setPlayerCount(playerCount); |
| | | |
| | | // 设置父比赛信息 |
| | | Optional<Activity> parentOpt = activityRepository.findById(activity.getPid()); |
| | | if (parentOpt.isPresent()) { |
| | | Activity parent = parentOpt.get(); |
| | | response.setParent(new ActivityResponse(parent)); |
| | | } |
| | | |
| | | return response; |
| | | }) |
| | | .sorted((a, b) -> { |
| | | // 先按父比赛名称排序,再按阶段名称排序 |
| | | if (a.getParent() != null && b.getParent() != null) { |
| | | int parentCompare = a.getParent().getName().compareTo(b.getParent().getName()); |
| | | if (parentCompare != 0) { |
| | | return parentCompare; |
| | | } |
| | | } |
| | | return a.getName().compareTo(b.getName()); |
| | | }) |
| | | .sorted((a, b) -> a.getName().compareTo(b.getName())) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return result; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取所有比赛阶段(用于评审页面下拉选择) |
| | | * 返回所有状态为1且pid>0的比赛阶段 |
| | | */ |
| | | public List<ActivityResponse> findAllStagesForSelection() { |
| | | // 获取所有状态为1的活动 |
| | | List<Activity> allActivities = activityRepository.findByStateOrderByPidAscNameAsc(1); |
| | | |
| | | // 分离主比赛和阶段 |
| | | Map<Long, Activity> parentActivitiesMap = allActivities.stream() |
| | | .filter(activity -> activity.getPid() == 0) |
| | | .collect(Collectors.toMap(Activity::getId, activity -> activity)); |
| | | |
| | | // 过滤:只保留比赛阶段(pid>0) |
| | | List<Activity> filteredStages = allActivities.stream() |
| | | .filter(activity -> activity.getPid() > 0) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 转换为ActivityResponse |
| | | List<ActivityResponse> result = filteredStages.stream() |
| | | .map(activity -> { |
| | | ActivityResponse response = new ActivityResponse(activity); |
| | | // 设置参赛人数(审核通过的报名数量) |
| | | Long playerCountLong = activityPlayerRepository.countByActivityId(activity.getId()); |
| | | int playerCount = playerCountLong != null ? playerCountLong.intValue() : 0; |
| | | response.setPlayerCount(playerCount); |
| | | |
| | | // 手动设置parent信息 |
| | | Activity parentActivity = parentActivitiesMap.get(activity.getPid()); |
| | | if (parentActivity != null) { |
| | | ActivityResponse parentResponse = new ActivityResponse(parentActivity); |
| | | response.setParent(parentResponse); |
| | | } |
| | | |
| | | return response; |
| | | }) |
| | | .sorted((a, b) -> { |
| | | // 先按父比赛ID排序,再按阶段名称排序 |
| | | int pidCompare = Long.compare(a.getPid(), b.getPid()); |
| | | if (pidCompare != 0) return pidCompare; |
| | | return a.getName().compareTo(b.getName()); |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 统计比赛数量 |
| | | */ |
| | | public long countActiveActivities() { |