diff --git a/src/main/java/org/springblade/modules/martial/controller/MartialRegistrationOrderController.java b/src/main/java/org/springblade/modules/martial/controller/MartialRegistrationOrderController.java index d6a914e..772b2f6 100644 --- a/src/main/java/org/springblade/modules/martial/controller/MartialRegistrationOrderController.java +++ b/src/main/java/org/springblade/modules/martial/controller/MartialRegistrationOrderController.java @@ -167,27 +167,46 @@ public class MartialRegistrationOrderController extends BladeController { // Create a record for each project for (Long projectId : projectIds) { - MartialAthlete newRecord = new MartialAthlete(); - newRecord.setOrderId(orderId); - newRecord.setCompetitionId(dto.getCompetitionId()); - newRecord.setProjectId(projectId); - newRecord.setPlayerName(existingAthlete.getPlayerName()); - newRecord.setGender(existingAthlete.getGender()); - newRecord.setIdCard(existingAthlete.getIdCard()); - newRecord.setIdCardType(existingAthlete.getIdCardType()); - newRecord.setContactPhone(existingAthlete.getContactPhone()); - newRecord.setOrganization(existingAthlete.getOrganization()); - newRecord.setTeamName(existingAthlete.getTeamName()); - newRecord.setRegistrationStatus(1); - newRecord.setCompetitionStatus(0); - newRecord.setCreateUser(AuthUtil.getUserId()); - newRecord.setCreateTime(new java.util.Date()); - newRecord.setTenantId("000000"); - newRecord.setIsDeleted(0); - newRecord.setStatus(1); + // Check if record already exists for this athlete + competition + project + LambdaQueryWrapper checkWrapper = new LambdaQueryWrapper<>(); + checkWrapper.eq(MartialAthlete::getCompetitionId, dto.getCompetitionId()) + .eq(MartialAthlete::getProjectId, projectId) + .eq(MartialAthlete::getIdCard, existingAthlete.getIdCard()) + .eq(MartialAthlete::getIsDeleted, 0); + MartialAthlete existingRecord = athleteService.getOne(checkWrapper, false); - athleteService.save(newRecord); - log.info("创建选手参赛记录: playerName={}, projectId={}", existingAthlete.getPlayerName(), projectId); + if (existingRecord != null) { + // Update existing record with order info + existingRecord.setOrderId(orderId); + existingRecord.setRegistrationStatus(1); + existingRecord.setUpdateUser(AuthUtil.getUserId()); + existingRecord.setUpdateTime(new java.util.Date()); + athleteService.updateById(existingRecord); + log.info("更新已存在的选手参赛记录: playerName={}, projectId={}", existingAthlete.getPlayerName(), projectId); + } else { + // Create new record + MartialAthlete newRecord = new MartialAthlete(); + newRecord.setOrderId(orderId); + newRecord.setCompetitionId(dto.getCompetitionId()); + newRecord.setProjectId(projectId); + newRecord.setPlayerName(existingAthlete.getPlayerName()); + newRecord.setGender(existingAthlete.getGender()); + newRecord.setIdCard(existingAthlete.getIdCard()); + newRecord.setIdCardType(existingAthlete.getIdCardType()); + newRecord.setContactPhone(existingAthlete.getContactPhone()); + newRecord.setOrganization(existingAthlete.getOrganization()); + newRecord.setTeamName(existingAthlete.getTeamName()); + newRecord.setRegistrationStatus(1); + newRecord.setCompetitionStatus(0); + newRecord.setCreateUser(AuthUtil.getUserId()); + newRecord.setCreateTime(new java.util.Date()); + newRecord.setTenantId("000000"); + newRecord.setIsDeleted(0); + newRecord.setStatus(1); + + athleteService.save(newRecord); + log.info("创建选手参赛记录: playerName={}, projectId={}", existingAthlete.getPlayerName(), projectId); + } } } }