fix: 报名时检查是否已存在相同选手记录,避免重复创建

- 在提交报名时,先检查是否已存在相同选手+比赛+项目的记录
- 如果存在则更新订单ID,而不是创建新记录
- 解决添加选手后再报名导致重复记录的问题

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
2026-01-06 16:24:23 +08:00
parent 550802a029
commit eefe7167ee

View File

@@ -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<MartialAthlete> 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);
}
}
}
}