From aa34251ae485dc1fa1fd8cd92764f77980ac579d Mon Sep 17 00:00:00 2001 From: luogw <3132758203@qq.com> Date: Tue, 14 Jul 2026 15:44:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=BB=E5=8A=A1=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E5=88=A4=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/strategy/ClassicTaskConfigStrategy.java | 12 +++++++----- .../strategy/GenerativeTaskConfigStrategy.java | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) 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("考试任务名称过长");