From 106e563f2ec83a5d82bd053bfe31ca8318569630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=85=E6=88=BF?= Date: Thu, 15 Jan 2026 15:13:16 +0800 Subject: [PATCH] fix: save draft schedule with negative IDs from auto-arrange - Handle negative groupId by creating new schedule groups - Extract projectId from code format C{competitionId}-P{projectId} - Save project type, participant count, and team count - Query participants by participant_id instead of primary key - Create new participant records if not exists Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com> --- .../impl/MartialScheduleServiceImpl.java | 85 ++++++++++++++++++- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springblade/modules/martial/service/impl/MartialScheduleServiceImpl.java b/src/main/java/org/springblade/modules/martial/service/impl/MartialScheduleServiceImpl.java index a4f5306..26de138 100644 --- a/src/main/java/org/springblade/modules/martial/service/impl/MartialScheduleServiceImpl.java +++ b/src/main/java/org/springblade/modules/martial/service/impl/MartialScheduleServiceImpl.java @@ -409,16 +409,75 @@ public class MartialScheduleServiceImpl extends ServiceImpl() + .eq("competition_id", dto.getCompetitionId()) + .eq("project_id", projectId) + .eq("is_deleted", 0) + .last("LIMIT 1") + ); + } + + // Determine project type from DTO + Integer projectType = null; + if ("集体".equals(groupDTO.getType())) { + projectType = 2; + } else if ("单人".equals(groupDTO.getType())) { + projectType = 1; + } + + // Calculate participant/team counts + int participantCount = groupDTO.getParticipants() != null ? groupDTO.getParticipants().size() : 0; + + if (existingGroup != null) { + realGroupId = existingGroup.getId(); + existingGroup.setGroupName(groupDTO.getTitle()); + existingGroup.setProjectType(projectType); + existingGroup.setTotalParticipants(participantCount); + existingGroup.setTotalTeams(participantCount); + existingGroup.setCategory(groupDTO.getCode()); + scheduleGroupMapper.updateById(existingGroup); + } else { + MartialScheduleGroup newGroup = new MartialScheduleGroup(); + newGroup.setCompetitionId(Long.valueOf(dto.getCompetitionId())); + newGroup.setProjectId(projectId); + newGroup.setGroupName(groupDTO.getTitle()); + newGroup.setProjectType(projectType); + newGroup.setTotalParticipants(participantCount); + newGroup.setTotalTeams(participantCount); + newGroup.setCategory(groupDTO.getCode()); + scheduleGroupMapper.insert(newGroup); + realGroupId = newGroup.getId(); + } + } + MartialScheduleDetail detail = scheduleDetailMapper.selectOne( new QueryWrapper() - .eq("schedule_group_id", groupDTO.getId()) + .eq("schedule_group_id", realGroupId) .eq("is_deleted", 0) .last("LIMIT 1") ); if (detail == null) { detail = new MartialScheduleDetail(); - detail.setScheduleGroupId(groupDTO.getId()); + detail.setScheduleGroupId(realGroupId); detail.setCompetitionId(dto.getCompetitionId()); } @@ -460,7 +519,7 @@ public class MartialScheduleServiceImpl extends ServiceImpl() + .eq("participant_id", participantDTO.getId()) + .eq("schedule_group_id", realGroupId) + .eq("is_deleted", 0) + .last("LIMIT 1") + ); if (participant != null) { participant.setCheckInStatus(participantDTO.getStatus()); participant.setPerformanceOrder(participantDTO.getSortOrder()); participant.setScheduleStatus("draft"); scheduleParticipantMapper.updateById(participant); + } else { + // Create new participant record if not exists + MartialScheduleParticipant newParticipant = new MartialScheduleParticipant(); + newParticipant.setScheduleGroupId(realGroupId); + newParticipant.setScheduleDetailId(detail.getId()); // Set schedule_detail_id + newParticipant.setParticipantId(Long.valueOf(participantDTO.getId())); + newParticipant.setOrganization(participantDTO.getSchoolUnit()); + newParticipant.setCheckInStatus(participantDTO.getStatus()); + newParticipant.setPerformanceOrder(participantDTO.getSortOrder()); + newParticipant.setScheduleStatus("draft"); + scheduleParticipantMapper.insert(newParticipant); } } }