Browse Source

修改任务名称判重

master
luogw 2 months ago
parent
commit
aa34251ae4
  1. 12
      src/main/java/com/project/task/domain/service/strategy/ClassicTaskConfigStrategy.java
  2. 12
      src/main/java/com/project/task/domain/service/strategy/GenerativeTaskConfigStrategy.java

12
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())) { if (StrUtil.isBlank(dto.getName())) {
throw new BusinessErrorException("考试任务名称不能为空"); throw new BusinessErrorException("考试任务名称不能为空");
} }
if (dto.getId() == null) { LambdaQueryWrapper<TaskEntity> nameWrapper = new LambdaQueryWrapper<TaskEntity>()
long count = taskBaseService.count(new LambdaQueryWrapper<TaskEntity>().eq(TaskEntity::getName, dto.getName())); .eq(TaskEntity::getName, dto.getName());
if (count > 0) { if (dto.getId() != null) {
throw new BusinessErrorException("考试任务名称已存在"); nameWrapper.ne(TaskEntity::getId, dto.getId());
} }
if (taskBaseService.count(nameWrapper) > 0) {
throw new BusinessErrorException("考试任务名称已存在");
} }
if (StrUtil.length(dto.getName()) > 20) { if (StrUtil.length(dto.getName()) > 20) {
throw new BusinessErrorException("考试任务名称过长"); throw new BusinessErrorException("考试任务名称过长");

12
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())) { if (StrUtil.isBlank(dto.getName())) {
throw new BusinessErrorException("考试任务名称不能为空"); throw new BusinessErrorException("考试任务名称不能为空");
} }
if (dto.getId() == null) { LambdaQueryWrapper<TaskEntity> nameWrapper = new LambdaQueryWrapper<TaskEntity>()
long count = taskBaseService.count(new LambdaQueryWrapper<TaskEntity>().eq(TaskEntity::getName, dto.getName())); .eq(TaskEntity::getName, dto.getName());
if (count > 0) { if (dto.getId() != null) {
throw new BusinessErrorException("考试任务名称已存在"); nameWrapper.ne(TaskEntity::getId, dto.getId());
} }
if (taskBaseService.count(nameWrapper) > 0) {
throw new BusinessErrorException("考试任务名称已存在");
} }
if (StrUtil.length(dto.getName()) > 20) { if (StrUtil.length(dto.getName()) > 20) {
throw new BusinessErrorException("考试任务名称过长"); throw new BusinessErrorException("考试任务名称过长");

Loading…
Cancel
Save