裁判长修改分数功能优化
1. 限制修改范围为原始分数±0.050 2. 修改记录改为更新而非新增(避免重复记录) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -285,7 +285,13 @@ public class MartialScoreServiceImpl extends ServiceImpl<MartialScoreMapper, Mar
|
||||
// 注意:这里假设修改记录存储在选手的 totalScore 和一个额外的字段中
|
||||
// 由于 MartialAthlete 实体没有 originalScore 字段,我们查找修改过的评分记录
|
||||
MartialScore modifiedScore = scores.stream()
|
||||
.filter(s -> s.getOriginalScore() != null && s.getModifyReason() != null)
|
||||
.filter(s -> s.getOriginalScore() != null)
|
||||
.sorted((a, b) -> {
|
||||
if (a.getModifyTime() == null && b.getModifyTime() == null) return 0;
|
||||
if (a.getModifyTime() == null) return 1;
|
||||
if (b.getModifyTime() == null) return -1;
|
||||
return b.getModifyTime().compareTo(a.getModifyTime());
|
||||
})
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
@@ -326,42 +332,67 @@ public class MartialScoreServiceImpl extends ServiceImpl<MartialScoreMapper, Mar
|
||||
throw new ServiceException("选手不存在");
|
||||
}
|
||||
|
||||
// 2. 验证分数范围
|
||||
// 2. 验证分数基本范围
|
||||
if (!validateScore(dto.getModifiedScore())) {
|
||||
throw new ServiceException("修改后的分数必须在5.000-10.000之间");
|
||||
}
|
||||
|
||||
// 3. 保存原始总分(如果是第一次修改)
|
||||
// 3. 保存原始总分(用于记录和范围验证)
|
||||
BigDecimal originalTotalScore = athlete.getTotalScore();
|
||||
|
||||
// 4. 更新选手总分
|
||||
// 4. 验证修改范围(±0.050)
|
||||
if (originalTotalScore != null) {
|
||||
BigDecimal minAllowed = originalTotalScore.subtract(new BigDecimal("0.050"));
|
||||
BigDecimal maxAllowed = originalTotalScore.add(new BigDecimal("0.050"));
|
||||
if (dto.getModifiedScore().compareTo(minAllowed) < 0 || dto.getModifiedScore().compareTo(maxAllowed) > 0) {
|
||||
throw new ServiceException("修改分数只能在原始分数±0.050范围内");
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 更新选手总分
|
||||
athlete.setTotalScore(dto.getModifiedScore());
|
||||
boolean athleteUpdated = athleteService.updateById(athlete);
|
||||
|
||||
// 5. 记录修改日志(可以新增一条特殊的评分记录,或更新现有记录)
|
||||
// 这里选择创建一条新的修改记录
|
||||
MartialScore modificationRecord = new MartialScore();
|
||||
modificationRecord.setCompetitionId(athlete.getCompetitionId());
|
||||
modificationRecord.setAthleteId(athlete.getId());
|
||||
modificationRecord.setProjectId(athlete.getProjectId());
|
||||
modificationRecord.setJudgeId(dto.getModifierId());
|
||||
modificationRecord.setScore(dto.getModifiedScore());
|
||||
modificationRecord.setOriginalScore(originalTotalScore);
|
||||
modificationRecord.setModifyReason(dto.getNote());
|
||||
modificationRecord.setModifyTime(LocalDateTime.now());
|
||||
modificationRecord.setScoreTime(LocalDateTime.now());
|
||||
// 6. 查找是否已存在裁判长的修改记录(通过判断judge_name包含"裁判长修改")
|
||||
LambdaQueryWrapper<MartialScore> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(MartialScore::getAthleteId, dto.getAthleteId())
|
||||
.like(MartialScore::getJudgeName, "裁判长修改");
|
||||
MartialScore existingRecord = this.getOne(queryWrapper);
|
||||
|
||||
// 查询修改者信息
|
||||
MartialJudge modifier = judgeService.getById(dto.getModifierId());
|
||||
if (modifier != null) {
|
||||
modificationRecord.setJudgeName(modifier.getName() + "(裁判长修改)");
|
||||
boolean recordSaved;
|
||||
if (existingRecord != null) {
|
||||
// 7a. 更新现有的裁判长修改记录
|
||||
existingRecord.setScore(dto.getModifiedScore());
|
||||
existingRecord.setOriginalScore(originalTotalScore);
|
||||
existingRecord.setModifyReason(dto.getNote());
|
||||
existingRecord.setModifyTime(LocalDateTime.now());
|
||||
recordSaved = this.updateById(existingRecord);
|
||||
log.info("裁判长更新评分记录 - 选手ID:{}, 姓名:{}, 原始总分:{}, 修改后总分:{}, 修改原因:{}",
|
||||
athlete.getId(), athlete.getPlayerName(), originalTotalScore, dto.getModifiedScore(), dto.getNote());
|
||||
} else {
|
||||
// 7b. 创建新的裁判长修改记录
|
||||
MartialScore modificationRecord = new MartialScore();
|
||||
modificationRecord.setCompetitionId(athlete.getCompetitionId());
|
||||
modificationRecord.setAthleteId(athlete.getId());
|
||||
modificationRecord.setProjectId(athlete.getProjectId());
|
||||
modificationRecord.setJudgeId(dto.getModifierId());
|
||||
modificationRecord.setScore(dto.getModifiedScore());
|
||||
modificationRecord.setOriginalScore(originalTotalScore);
|
||||
modificationRecord.setModifyReason(dto.getNote());
|
||||
modificationRecord.setModifyTime(LocalDateTime.now());
|
||||
modificationRecord.setScoreTime(LocalDateTime.now());
|
||||
|
||||
// 查询修改者信息
|
||||
MartialJudge modifier = judgeService.getById(dto.getModifierId());
|
||||
if (modifier != null) {
|
||||
modificationRecord.setJudgeName(modifier.getName() + "(裁判长修改)");
|
||||
}
|
||||
|
||||
recordSaved = this.save(modificationRecord);
|
||||
log.info("裁判长新增评分记录 - 选手ID:{}, 姓名:{}, 原始总分:{}, 修改后总分:{}, 修改原因:{}",
|
||||
athlete.getId(), athlete.getPlayerName(), originalTotalScore, dto.getModifiedScore(), dto.getNote());
|
||||
}
|
||||
|
||||
boolean recordSaved = this.save(modificationRecord);
|
||||
|
||||
log.info("裁判长修改评分 - 选手ID:{}, 姓名:{}, 原始总分:{}, 修改后总分:{}, 修改原因:{}",
|
||||
athlete.getId(), athlete.getPlayerName(), originalTotalScore, dto.getModifiedScore(), dto.getNote());
|
||||
|
||||
return athleteUpdated && recordSaved;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user