From 4585355c881273b331adce17f009cee52339965b Mon Sep 17 00:00:00 2001 From: zhangyuhang <2827528315@qq.com> Date: Sun, 1 Dec 2024 21:31:55 +0800 Subject: [PATCH] [Bug] [dinky-web] Issue with creating a new task with a subdirectory of the same name (#3993) Co-authored-by: yuhang2.zhang --- .../org/dinky/controller/CatalogueController.java | 3 +++ .../dinky/service/catalogue/CatalogueService.java | 7 +++++++ .../catalogue/impl/CatalogueServiceImpl.java | 13 +++++++++++++ .../src/main/java/org/dinky/data/enums/Status.java | 1 + 4 files changed, 24 insertions(+) diff --git a/dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java b/dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java index 2ed07d9aaf..c822e03cfd 100644 --- a/dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java +++ b/dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java @@ -128,6 +128,9 @@ public Result upload(MultipartFile file, @PathVariable Integer id) { dataType = "Catalogue", dataTypeClass = Catalogue.class) public Result saveOrUpdateCatalogue(@RequestBody Catalogue catalogue) { + if (catalogueService.checkNameIsExistByParentId(catalogue)) { + return Result.failed(Status.NAME_IS_EXIST); + } if (catalogueService.saveOrUpdateOrRename(catalogue)) { return Result.succeed(Status.SAVE_SUCCESS); } else { diff --git a/dinky-admin/src/main/java/org/dinky/service/catalogue/CatalogueService.java b/dinky-admin/src/main/java/org/dinky/service/catalogue/CatalogueService.java index 5a9fa7e5bb..57641eb35d 100644 --- a/dinky-admin/src/main/java/org/dinky/service/catalogue/CatalogueService.java +++ b/dinky-admin/src/main/java/org/dinky/service/catalogue/CatalogueService.java @@ -144,6 +144,13 @@ public interface CatalogueService extends ISuperService { */ Boolean saveOrUpdateOrRename(Catalogue catalogue); + /** + * Check if the catalogue name is exist + * @param catalogue catalogue + * @return true if the catalogue name is exist + */ + Boolean checkNameIsExistByParentId(Catalogue catalogue); + /** * Check if the catalogue task name is exist * @param name catalogue task name diff --git a/dinky-admin/src/main/java/org/dinky/service/catalogue/impl/CatalogueServiceImpl.java b/dinky-admin/src/main/java/org/dinky/service/catalogue/impl/CatalogueServiceImpl.java index 392bf968c4..395fc74c71 100644 --- a/dinky-admin/src/main/java/org/dinky/service/catalogue/impl/CatalogueServiceImpl.java +++ b/dinky-admin/src/main/java/org/dinky/service/catalogue/impl/CatalogueServiceImpl.java @@ -582,6 +582,19 @@ public Boolean saveOrUpdateOrRename(Catalogue catalogue) { return saveOrUpdate(catalogue); } + /** + * Check if the catalogue name is exist + * @param catalogue catalogue + * @return true if the catalogue name is exist + */ + @Override + public Boolean checkNameIsExistByParentId(Catalogue catalogue) { + return getBaseMapper() + .exists(new LambdaQueryWrapper() + .eq(Catalogue::getName, catalogue.getName()) + .ne(catalogue.getParentId() != null, Catalogue::getParentId, catalogue.getParentId())); + } + private CatalogueTaskDTO getCatalogueTaskDTO(String name, Integer parentId) { CatalogueTaskDTO catalogueTaskDTO = new CatalogueTaskDTO(); catalogueTaskDTO.setName(UUID.randomUUID().toString().substring(0, 6) + name); diff --git a/dinky-common/src/main/java/org/dinky/data/enums/Status.java b/dinky-common/src/main/java/org/dinky/data/enums/Status.java index 24f516a9a9..efe2711db5 100644 --- a/dinky-common/src/main/java/org/dinky/data/enums/Status.java +++ b/dinky-common/src/main/java/org/dinky/data/enums/Status.java @@ -196,6 +196,7 @@ public enum Status { CATALOGUE_NOT_EXIST(12017, "catalogue.not.exist"), CATALOGUE_IS_EXIST(12018, "catalogue.is.exist"), TASK_NAME_NOT_MATCH_CATALOGUE_NAME(12019, "task.name.not.match.catalogue.name"), + NAME_IS_EXIST(12021, "A task and a directory cannot have the same name under the same parent directory."), /** * alert instance