fix: 报名时检查是否已存在相同选手记录,避免重复创建
- 在提交报名时,先检查是否已存在相同选手+比赛+项目的记录 - 如果存在则更新订单ID,而不是创建新记录 - 解决添加选手后再报名导致重复记录的问题 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
@@ -167,6 +167,24 @@ public class MartialRegistrationOrderController extends BladeController {
|
|||||||
|
|
||||||
// Create a record for each project
|
// Create a record for each project
|
||||||
for (Long projectId : projectIds) {
|
for (Long projectId : projectIds) {
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
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();
|
MartialAthlete newRecord = new MartialAthlete();
|
||||||
newRecord.setOrderId(orderId);
|
newRecord.setOrderId(orderId);
|
||||||
newRecord.setCompetitionId(dto.getCompetitionId());
|
newRecord.setCompetitionId(dto.getCompetitionId());
|
||||||
@@ -191,6 +209,7 @@ public class MartialRegistrationOrderController extends BladeController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return R.data(order);
|
return R.data(order);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user