diff --git a/src/main/java/com/project/task/domain/service/strategy/ClassicTaskConfigStrategy.java b/src/main/java/com/project/task/domain/service/strategy/ClassicTaskConfigStrategy.java index 570d506..2469a86 100644 --- a/src/main/java/com/project/task/domain/service/strategy/ClassicTaskConfigStrategy.java +++ b/src/main/java/com/project/task/domain/service/strategy/ClassicTaskConfigStrategy.java @@ -54,11 +54,13 @@ public class ClassicTaskConfigStrategy implements TaskConfigStrategy { if (StrUtil.isBlank(dto.getName())) { throw new BusinessErrorException("考试任务名称不能为空"); } - if (dto.getId() == null) { - long count = taskBaseService.count(new LambdaQueryWrapper().eq(TaskEntity::getName, dto.getName())); - if (count > 0) { - throw new BusinessErrorException("考试任务名称已存在"); - } + LambdaQueryWrapper nameWrapper = new LambdaQueryWrapper() + .eq(TaskEntity::getName, dto.getName()); + if (dto.getId() != null) { + nameWrapper.ne(TaskEntity::getId, dto.getId()); + } + if (taskBaseService.count(nameWrapper) > 0) { + throw new BusinessErrorException("考试任务名称已存在"); } if (StrUtil.length(dto.getName()) > 20) { throw new BusinessErrorException("考试任务名称过长"); diff --git a/src/main/java/com/project/task/domain/service/strategy/GenerativeTaskConfigStrategy.java b/src/main/java/com/project/task/domain/service/strategy/GenerativeTaskConfigStrategy.java index a09012f..4ad5437 100644 --- a/src/main/java/com/project/task/domain/service/strategy/GenerativeTaskConfigStrategy.java +++ b/src/main/java/com/project/task/domain/service/strategy/GenerativeTaskConfigStrategy.java @@ -48,11 +48,13 @@ public class GenerativeTaskConfigStrategy implements TaskConfigStrategy { if (StrUtil.isBlank(dto.getName())) { throw new BusinessErrorException("考试任务名称不能为空"); } - if (dto.getId() == null) { - long count = taskBaseService.count(new LambdaQueryWrapper().eq(TaskEntity::getName, dto.getName())); - if (count > 0) { - throw new BusinessErrorException("考试任务名称已存在"); - } + LambdaQueryWrapper nameWrapper = new LambdaQueryWrapper() + .eq(TaskEntity::getName, dto.getName()); + if (dto.getId() != null) { + nameWrapper.ne(TaskEntity::getId, dto.getId()); + } + if (taskBaseService.count(nameWrapper) > 0) { + throw new BusinessErrorException("考试任务名称已存在"); } if (StrUtil.length(dto.getName()) > 20) { throw new BusinessErrorException("考试任务名称过长");