| | |
| | | import com.rongyichuang.activity.repository.ActivityPlayerRatingRepository; |
| | | import com.rongyichuang.common.entity.Media; |
| | | import com.rongyichuang.common.repository.MediaRepository; |
| | | import com.rongyichuang.message.service.MessageService; |
| | | import com.rongyichuang.player.dto.*; |
| | | import com.rongyichuang.player.dto.response.PromotionCompetitionPageResponse; |
| | | import com.rongyichuang.player.entity.ActivityPlayer; |
| | | import com.rongyichuang.player.repository.ActivityPlayerRepository; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | @Autowired |
| | | private MediaRepository mediaRepository; |
| | | |
| | | @Autowired |
| | | private MessageService messageService; |
| | | |
| | | /** |
| | | * 获取比赛晋级列表 |
| | | */ |
| | | public List<PromotionCompetitionResponse> getPromotionCompetitions(String name, Integer page, Integer size) { |
| | | List<PromotionCompetitionResponse> result = new ArrayList<>(); |
| | | public PromotionCompetitionPageResponse getPromotionCompetitions(String name, Integer page, Integer size) { |
| | | List<PromotionCompetitionResponse> allResults = new ArrayList<>(); |
| | | |
| | | // 查询所有有效的主比赛(pid = 0) |
| | | List<Activity> competitions = activityRepository.findByPidAndStateOrderByCreateTimeAsc(0L, 1); |
| | | List<Activity> competitions = activityRepository.findByPidAndStateOrderByCreateTimeDesc(0L, 1); |
| | | |
| | | // 如果有名称过滤条件,进行过滤 |
| | | if (name != null && !name.trim().isEmpty()) { |
| | |
| | | |
| | | // 为每个比赛查询其阶段 |
| | | for (Activity competition : competitions) { |
| | | List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeAsc(competition.getId(), 1); |
| | | List<Activity> stages = activityRepository.findByPidAndStateOrderByCreateTimeDesc(competition.getId(), 1); |
| | | |
| | | for (Activity stage : stages) { |
| | | // 统计当前阶段的参赛人数 |
| | |
| | | Integer currentCount = playerCountLong != null ? playerCountLong.intValue() : 0; |
| | | |
| | | PromotionCompetitionResponse response = new PromotionCompetitionResponse(competition, stage, currentCount); |
| | | result.add(response); |
| | | allResults.add(response); |
| | | } |
| | | } |
| | | |
| | | // 简单分页处理(实际项目中建议使用数据库分页) |
| | | // 计算总数 |
| | | long totalElements = allResults.size(); |
| | | |
| | | // 分页处理 |
| | | List<PromotionCompetitionResponse> pagedResults = allResults; |
| | | if (page != null && size != null && page > 0 && size > 0) { |
| | | int start = (page - 1) * size; |
| | | int end = Math.min(start + size, result.size()); |
| | | if (start < result.size()) { |
| | | result = result.subList(start, end); |
| | | int end = Math.min(start + size, allResults.size()); |
| | | if (start < allResults.size()) { |
| | | pagedResults = allResults.subList(start, end); |
| | | } else { |
| | | result = new ArrayList<>(); |
| | | pagedResults = new ArrayList<>(); |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | // 返回分页响应对象 |
| | | return new PromotionCompetitionPageResponse(pagedResults, totalElements, page, size); |
| | | } |
| | | |
| | | /** |
| | |
| | | return PromotionResult.failure("请选择要晋级的参赛者"); |
| | | } |
| | | |
| | | // 查询目标晋级阶段信息(用户点击的阶段就是要晋级到的阶段) |
| | | Activity targetStage = activityRepository.findById(input.getCompetitionId()).orElse(null); |
| | | // 查询目标晋级阶段信息 |
| | | Activity targetStage = activityRepository.findById(input.getTargetStageId()).orElse(null); |
| | | if (targetStage == null) { |
| | | return PromotionResult.failure("目标晋级阶段不存在"); |
| | | } |
| | |
| | | // 复制媒体文件 |
| | | copyMediaFiles(participant.getId(), savedParticipant.getId()); |
| | | |
| | | // 创建晋级消息 |
| | | messageService.createPromotionMessage( |
| | | savedParticipant.getId(), |
| | | savedParticipant.getPlayerId(), |
| | | savedParticipant.getProjectName() |
| | | ); |
| | | |
| | | promotedCount++; |
| | | } |
| | | } |