diff --git a/src/main/java/org/springblade/modules/martial/controller/MartialMiniController.java b/src/main/java/org/springblade/modules/martial/controller/MartialMiniController.java index d4ada8c..9d88e76 100644 --- a/src/main/java/org/springblade/modules/martial/controller/MartialMiniController.java +++ b/src/main/java/org/springblade/modules/martial/controller/MartialMiniController.java @@ -34,6 +34,8 @@ import org.springblade.modules.martial.pojo.entity.MartialResult; import org.springblade.core.redis.cache.BladeRedis; import org.springblade.modules.martial.mapper.MartialScheduleStatusMapper; import org.springblade.modules.martial.mapper.MartialScheduleGroupMapper; +import org.springblade.modules.martial.mapper.MartialScheduleParticipantMapper; +import org.springblade.modules.martial.mapper.MartialScheduleDetailMapper; import org.springframework.web.bind.annotation.*; import java.math.BigDecimal; @@ -76,6 +78,8 @@ public class MartialMiniController extends BladeController { private final IMartialRegistrationOrderService registrationOrderService; private final MartialScheduleStatusMapper scheduleStatusMapper; private final MartialScheduleGroupMapper scheduleGroupMapper; + private final MartialScheduleParticipantMapper scheduleParticipantMapper; + private final MartialScheduleDetailMapper scheduleDetailMapper; // Redis缓存key前缀 private static final String MINI_LOGIN_CACHE_PREFIX = "mini:login:"; @@ -244,23 +248,23 @@ public class MartialMiniController extends BladeController { @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size ) { - // 1. 构建选手查询条件 - LambdaQueryWrapper athleteQuery = new LambdaQueryWrapper<>(); - athleteQuery.eq(MartialAthlete::getIsDeleted, 0); - - // 按比赛ID过滤(重要:确保只显示当前比赛的选手) - if (competitionId != null) { - athleteQuery.eq(MartialAthlete::getCompetitionId, competitionId); + // 1. 优先从编排表查询选手(按出场顺序) + List athletes = getAthletesFromSchedule(competitionId, projectId, venueId); + + // 如果编排表没有数据,回退到原始选手表查询 + if (athletes.isEmpty()) { + LambdaQueryWrapper athleteQuery = new LambdaQueryWrapper<>(); + athleteQuery.eq(MartialAthlete::getIsDeleted, 0); + if (competitionId != null) { + athleteQuery.eq(MartialAthlete::getCompetitionId, competitionId); + } + if (projectId != null) { + athleteQuery.eq(MartialAthlete::getProjectId, projectId); + } + athleteQuery.orderByAsc(MartialAthlete::getOrderNum); + athletes = athleteService.list(athleteQuery); } - if (projectId != null) { - athleteQuery.eq(MartialAthlete::getProjectId, projectId); - } - - athleteQuery.orderByAsc(MartialAthlete::getOrderNum); - - List athletes = athleteService.list(athleteQuery); - // 2. 获取该场地所有主裁判的judge_id列表 List chiefJudgeIds = getChiefJudgeIds(venueId); @@ -321,6 +325,81 @@ public class MartialMiniController extends BladeController { return R.data(page); } + /** + * 从编排表查询选手列表(按出场顺序) + */ + private List getAthletesFromSchedule(Long competitionId, Long projectId, Long venueId) { + if (competitionId == null) { + return new ArrayList<>(); + } + + // 查询编排分组 + LambdaQueryWrapper groupQuery = new LambdaQueryWrapper<>(); + groupQuery.eq(MartialScheduleGroup::getCompetitionId, competitionId); + groupQuery.eq(MartialScheduleGroup::getIsDeleted, 0); + if (projectId != null) { + groupQuery.eq(MartialScheduleGroup::getProjectId, projectId); + } + List groups = scheduleGroupMapper.selectList(groupQuery); + + if (groups.isEmpty()) { + return new ArrayList<>(); + } + + List groupIds = groups.stream().map(MartialScheduleGroup::getId).collect(Collectors.toList()); + + // 如果指定了场地,过滤出该场地的分组 + if (venueId != null) { + LambdaQueryWrapper detailQuery = new LambdaQueryWrapper<>(); + detailQuery.in(MartialScheduleDetail::getScheduleGroupId, groupIds); + detailQuery.eq(MartialScheduleDetail::getVenueId, venueId); + detailQuery.eq(MartialScheduleDetail::getIsDeleted, 0); + List details = scheduleDetailMapper.selectList(detailQuery); + groupIds = details.stream().map(MartialScheduleDetail::getScheduleGroupId).collect(Collectors.toList()); + + if (groupIds.isEmpty()) { + return new ArrayList<>(); + } + } + + // 查询编排参赛者(按出场顺序) + LambdaQueryWrapper participantQuery = new LambdaQueryWrapper<>(); + participantQuery.in(MartialScheduleParticipant::getScheduleGroupId, groupIds); + participantQuery.eq(MartialScheduleParticipant::getIsDeleted, 0); + participantQuery.orderByAsc(MartialScheduleParticipant::getPerformanceOrder); + List participants = scheduleParticipantMapper.selectList(participantQuery); + + if (participants.isEmpty()) { + return new ArrayList<>(); + } + + // 获取选手ID列表 + List athleteIds = participants.stream() + .map(MartialScheduleParticipant::getParticipantId) + .filter(Objects::nonNull) + .distinct() + .collect(Collectors.toList()); + + if (athleteIds.isEmpty()) { + return new ArrayList<>(); + } + + // 查询选手详情 + LambdaQueryWrapper athleteQuery = new LambdaQueryWrapper<>(); + athleteQuery.in(MartialAthlete::getId, athleteIds); + athleteQuery.eq(MartialAthlete::getIsDeleted, 0); + List athleteList = athleteService.list(athleteQuery); + + // 按编排顺序排序 + Map athleteMap = athleteList.stream() + .collect(Collectors.toMap(MartialAthlete::getId, a -> a)); + + return participants.stream() + .map(p -> athleteMap.get(p.getParticipantId())) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + /** * 获取场地所有主裁判的judge_id列表 */