修复导出赛程表:使用正确的数据源
- 从 martial_schedule_group 表获取编排数据 - 使用与 getScheduleResult 相同的数据源 - 按分组顺序和出场顺序导出 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -60,77 +60,69 @@ public class MartialScheduleServiceImpl extends ServiceImpl<MartialScheduleMappe
|
||||
*/
|
||||
@Override
|
||||
public List<ScheduleExportExcel> exportSchedule(Long competitionId) {
|
||||
// 1. 查询该赛事的所有赛程
|
||||
List<MartialSchedule> schedules = this.list(
|
||||
new QueryWrapper<MartialSchedule>()
|
||||
.eq("competition_id", competitionId)
|
||||
.eq("is_deleted", 0)
|
||||
.orderByAsc("schedule_date", "start_time")
|
||||
);
|
||||
|
||||
List<ScheduleExportExcel> exportList = new ArrayList<>();
|
||||
DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
// 2. 遍历每个赛程
|
||||
for (MartialSchedule schedule : schedules) {
|
||||
// 3. 获取该赛程的所有运动员
|
||||
List<MartialScheduleAthlete> scheduleAthletes = scheduleAthleteService.list(
|
||||
new QueryWrapper<MartialScheduleAthlete>()
|
||||
.eq("schedule_id", schedule.getId())
|
||||
.eq("is_deleted", 0)
|
||||
.orderByAsc("order_num")
|
||||
);
|
||||
// 使用与 getScheduleResult 相同的数据源
|
||||
List<ScheduleGroupDetailVO> details = scheduleGroupMapper.selectScheduleGroupDetails(competitionId);
|
||||
|
||||
// 4. 获取项目和场地信息(一次查询,避免重复)
|
||||
MartialProject project = schedule.getProjectId() != null
|
||||
? projectService.getById(schedule.getProjectId())
|
||||
: null;
|
||||
MartialVenue venue = schedule.getVenueId() != null
|
||||
? venueService.getById(schedule.getVenueId())
|
||||
: null;
|
||||
if (details.isEmpty()) {
|
||||
return exportList;
|
||||
}
|
||||
|
||||
// 5. 如果没有运动员,创建一条基础记录
|
||||
if (scheduleAthletes.isEmpty()) {
|
||||
ScheduleExportExcel excel = new ScheduleExportExcel();
|
||||
excel.setScheduleDate(schedule.getScheduleDate() != null
|
||||
? schedule.getScheduleDate().format(dateFormatter)
|
||||
: "");
|
||||
excel.setTimeSlot(schedule.getTimeSlot());
|
||||
excel.setVenueName(venue != null ? venue.getVenueName() : "");
|
||||
excel.setProjectName(project != null ? project.getProjectName() : "");
|
||||
excel.setCategory(schedule.getGroupTitle());
|
||||
excel.setStatus(schedule.getIsConfirmed() != null && schedule.getIsConfirmed() == 1
|
||||
? "已确认" : "未确认");
|
||||
exportList.add(excel);
|
||||
} else {
|
||||
// 6. 为每个运动员创建导出记录
|
||||
for (MartialScheduleAthlete scheduleAthlete : scheduleAthletes) {
|
||||
MartialAthlete athlete = athleteService.getById(scheduleAthlete.getAthleteId());
|
||||
if (athlete == null) {
|
||||
// 按分组ID分组,然后按 displayOrder 排序
|
||||
Map<Long, List<ScheduleGroupDetailVO>> groupMap = details.stream()
|
||||
.collect(Collectors.groupingBy(ScheduleGroupDetailVO::getGroupId));
|
||||
|
||||
// 获取分组的排序顺序
|
||||
List<Long> sortedGroupIds = details.stream()
|
||||
.collect(Collectors.toMap(
|
||||
ScheduleGroupDetailVO::getGroupId,
|
||||
d -> d.getDisplayOrder() != null ? d.getDisplayOrder() : 999,
|
||||
(a, b) -> a
|
||||
))
|
||||
.entrySet().stream()
|
||||
.sorted(Map.Entry.comparingByValue())
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 按排序顺序遍历分组
|
||||
for (Long groupId : sortedGroupIds) {
|
||||
List<ScheduleGroupDetailVO> groupDetails = groupMap.get(groupId);
|
||||
if (groupDetails == null || groupDetails.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ScheduleGroupDetailVO firstDetail = groupDetails.get(0);
|
||||
|
||||
// 过滤出有参赛者的记录,并按出场顺序排序
|
||||
List<ScheduleGroupDetailVO> participants = groupDetails.stream()
|
||||
.filter(d -> d.getParticipantId() != null)
|
||||
.sorted(Comparator.comparing(d -> d.getPerformanceOrder() != null ? d.getPerformanceOrder() : 999))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (participants.isEmpty()) {
|
||||
// 没有参赛者,创建一条基础记录
|
||||
ScheduleExportExcel excel = new ScheduleExportExcel();
|
||||
excel.setScheduleDate(schedule.getScheduleDate() != null
|
||||
? schedule.getScheduleDate().format(dateFormatter)
|
||||
: "");
|
||||
excel.setTimeSlot(schedule.getTimeSlot());
|
||||
excel.setVenueName(venue != null ? venue.getVenueName() : "");
|
||||
excel.setProjectName(project != null ? project.getProjectName() : "");
|
||||
excel.setCategory(schedule.getGroupTitle());
|
||||
excel.setAthleteName(athlete.getPlayerName());
|
||||
excel.setTeamName(athlete.getTeamName());
|
||||
excel.setSortOrder(scheduleAthlete.getOrderNum());
|
||||
|
||||
// 状态转换
|
||||
if (scheduleAthlete.getIsCompleted() != null && scheduleAthlete.getIsCompleted() == 1) {
|
||||
excel.setStatus("已完赛");
|
||||
} else if (schedule.getIsConfirmed() != null && schedule.getIsConfirmed() == 1) {
|
||||
excel.setStatus("已确认");
|
||||
excel.setScheduleDate("");
|
||||
excel.setTimeSlot(firstDetail.getTimeSlot());
|
||||
excel.setVenueName(firstDetail.getVenueName());
|
||||
excel.setProjectName(firstDetail.getGroupName());
|
||||
excel.setCategory(firstDetail.getCategory());
|
||||
excel.setStatus("completed".equals(firstDetail.getScheduleStatus()) ? "已完成" : "草稿");
|
||||
exportList.add(excel);
|
||||
} else {
|
||||
excel.setStatus("待确认");
|
||||
}
|
||||
|
||||
// 为每个参赛者创建导出记录
|
||||
for (ScheduleGroupDetailVO detail : participants) {
|
||||
ScheduleExportExcel excel = new ScheduleExportExcel();
|
||||
excel.setScheduleDate("");
|
||||
excel.setTimeSlot(detail.getTimeSlot());
|
||||
excel.setVenueName(detail.getVenueName());
|
||||
excel.setProjectName(detail.getGroupName());
|
||||
excel.setCategory(detail.getCategory());
|
||||
excel.setAthleteName(detail.getPlayerName());
|
||||
excel.setTeamName(detail.getOrganization());
|
||||
excel.setSortOrder(detail.getPerformanceOrder());
|
||||
excel.setStatus(detail.getCheckInStatus() != null ? detail.getCheckInStatus() : "未签到");
|
||||
exportList.add(excel);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user