refactor: Delegate saveDraftSchedule to ScheduleArrangeService
Phase 6 Complete: - Delegate saveDraftSchedule to ScheduleArrangeService (163 lines → 7 lines) - Implementation already exists in ScheduleArrangeServiceImpl - Method handles saving draft schedule with participants File size: 720 lines → 564 lines (-156 lines, -21.7%) Total reduction: 996 lines → 564 lines (-432 lines, -43.4%) Delegation Status: ✅ exportSchedule - FULLY DELEGATED ✅ exportScheduleTemplate2 - FULLY DELEGATED ✅ updateParticipantCheckInStatus - FULLY DELEGATED ✅ getDispatchData - FULLY DELEGATED ✅ adjustOrder - FULLY DELEGATED ✅ saveDispatch - FULLY DELEGATED ✅ moveScheduleGroup - FULLY DELEGATED ✅ saveAndLockSchedule - FULLY DELEGATED ✅ saveDraftSchedule - FULLY DELEGATED (NEW) Progress: 9/10 methods (90%) Remaining: 1 method (getScheduleResult - 324 lines, most complex) Tests passing
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
-158
@@ -439,166 +439,10 @@ public class MartialScheduleServiceImpl extends ServiceImpl<MartialScheduleMappe
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean saveDraftSchedule(SaveScheduleDraftDTO dto) {
|
public boolean saveDraftSchedule(SaveScheduleDraftDTO dto) {
|
||||||
if (dto.getCompetitionGroups() == null || dto.getCompetitionGroups().isEmpty()) {
|
// Delegated to ScheduleArrangeService
|
||||||
return false;
|
return scheduleArrangeService.saveDraftSchedule(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompetitionGroupDTO groupDTO : dto.getCompetitionGroups()) {
|
|
||||||
// 1. 更新或创建编排明细
|
|
||||||
Long groupId = groupDTO.getId();
|
|
||||||
Long realGroupId = groupId;
|
|
||||||
|
|
||||||
// Handle negative ID (draft data from auto-arrange)
|
|
||||||
if (groupId != null && groupId < 0) {
|
|
||||||
Long projectId = null;
|
|
||||||
if (groupDTO.getCode() != null && groupDTO.getCode().contains("-P")) {
|
|
||||||
try {
|
|
||||||
String suffix = groupDTO.getCode().substring(groupDTO.getCode().lastIndexOf("-P") + 2);
|
|
||||||
projectId = Long.parseLong(suffix);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("Failed to parse projectId from code: {}", groupDTO.getCode());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MartialScheduleGroup existingGroup = null;
|
|
||||||
if (projectId != null) {
|
|
||||||
existingGroup = scheduleGroupMapper.selectOne(
|
|
||||||
new QueryWrapper<MartialScheduleGroup>()
|
|
||||||
.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<MartialScheduleDetail>()
|
|
||||||
.eq("schedule_group_id", realGroupId)
|
|
||||||
.eq("is_deleted", 0)
|
|
||||||
.last("LIMIT 1")
|
|
||||||
);
|
|
||||||
|
|
||||||
if (detail == null) {
|
|
||||||
detail = new MartialScheduleDetail();
|
|
||||||
detail.setScheduleGroupId(realGroupId);
|
|
||||||
detail.setCompetitionId(dto.getCompetitionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
detail.setVenueId(groupDTO.getVenueId());
|
|
||||||
detail.setVenueName(groupDTO.getVenueName());
|
|
||||||
detail.setTimeSlot(groupDTO.getTimeSlot());
|
|
||||||
|
|
||||||
// 设置时间段(上午/下午)
|
|
||||||
if (groupDTO.getTimeSlot() != null && groupDTO.getTimeSlot().contains("上午")) {
|
|
||||||
detail.setTimePeriod("morning");
|
|
||||||
} else if (groupDTO.getTimeSlot() != null && groupDTO.getTimeSlot().contains("下午")) {
|
|
||||||
detail.setTimePeriod("afternoon");
|
|
||||||
} else {
|
|
||||||
detail.setTimePeriod("morning"); // 默认上午
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析日期
|
|
||||||
if (groupDTO.getTimeSlot() != null && groupDTO.getTimeSlot().contains("年")) {
|
|
||||||
try {
|
|
||||||
String dateStr = groupDTO.getTimeSlot().split(" ")[0];
|
|
||||||
dateStr = dateStr.replace("年", "-").replace("月", "-").replace("日", "");
|
|
||||||
detail.setScheduleDate(LocalDate.parse(dateStr));
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 日期解析失败,使用当天日期
|
|
||||||
detail.setScheduleDate(LocalDate.now());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果日期仍为空,设置默认日期
|
|
||||||
if (detail.getScheduleDate() == null) {
|
|
||||||
detail.setScheduleDate(LocalDate.now());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (detail.getId() == null) {
|
|
||||||
scheduleDetailMapper.insert(detail);
|
|
||||||
} else {
|
|
||||||
scheduleDetailMapper.updateById(detail);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1.5 同步更新项目的venue_id,保持数据一致性
|
|
||||||
if (groupDTO.getVenueId() != null) {
|
|
||||||
MartialScheduleGroup group = scheduleGroupMapper.selectById(realGroupId);
|
|
||||||
if (group != null && group.getProjectId() != null) {
|
|
||||||
MartialProject project = projectService.getById(group.getProjectId());
|
|
||||||
if (project != null) {
|
|
||||||
project.setVenueId(groupDTO.getVenueId());
|
|
||||||
projectService.updateById(project);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 更新参赛者信息
|
|
||||||
if (groupDTO.getParticipants() != null) {
|
|
||||||
for (ParticipantDTO participantDTO : groupDTO.getParticipants()) {
|
|
||||||
// Query by participant_id (registration ID) and schedule_group_id, not by primary key
|
|
||||||
MartialScheduleParticipant participant = scheduleParticipantMapper.selectOne(
|
|
||||||
new QueryWrapper<MartialScheduleParticipant>()
|
|
||||||
.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 完成编排并锁定
|
* 完成编排并锁定
|
||||||
|
|||||||
Reference in New Issue
Block a user