From 819b8645870af7d6b8288f6c2f0c0c56baaa2fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com> Date: Tue, 19 Mar 2024 16:04:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A2=84=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataset/DatasetVersionController.java | 3 +-- .../model/ModelsVersionController.java | 9 +++----- .../service/impl/DatasetServiceImpl.java | 21 +++++++++++++++---- .../impl/DatasetVersionServiceImpl.java | 2 +- .../managementPlatform/WorkflowDaoMapper.xml | 1 - 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetVersionController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetVersionController.java index 3857c25e..6728f124 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetVersionController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/dataset/DatasetVersionController.java @@ -87,14 +87,13 @@ public class DatasetVersionController { * @param datasetVersions 实体 * @return 新增结果 */ - @PostMapping(("/addDatasetVersions")) + @PostMapping("/addDatasetVersions") @ApiOperation("添加数据集版本") public AjaxResult addDatasetVersions(@RequestBody List datasetVersions) throws Exception { return AjaxResult.success(this.datasetVersionService.addDatasetVersions(datasetVersions)); } - /** * 编辑数据 * diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsVersionController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsVersionController.java index 61b15758..803bf068 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsVersionController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/model/ModelsVersionController.java @@ -67,9 +67,6 @@ public class ModelsVersionController { } - - - /** * 新增数据 * @@ -84,11 +81,11 @@ public class ModelsVersionController { /** * 批量新增模型版本 * - * @param datasetVersions 实体 + * @param modelsVersions 实体 * @return 新增结果 */ - @PostMapping(("/addDatasetVersions")) - @ApiOperation("添加数据集版本") + @PostMapping("/addModelVersions") + @ApiOperation("添加模型版本") public AjaxResult addModelVersions(@RequestBody List modelsVersions) throws Exception { return AjaxResult.success(this.modelsVersionService.addModelVersions(modelsVersions)); } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java index b01ae0b1..edfa83bd 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java @@ -362,15 +362,28 @@ public class DatasetServiceImpl implements DatasetService { public void checkDeclaredName(Dataset insert) throws Exception { - Dataset dataset = datasetDao.findByName(insert.getName()); - if (dataset != null) { + Dataset existingDataset = datasetDao.findByName(insert.getName()); + if (existingDataset != null) { + // Check if the found dataset is not the same as the one being inserted + // This is important if you are using this method for both insert and update operations + // You may need an identifier check here, e.g., if 'insert' has an ID and it's the same as 'existingDataset' + if (insert.getId() != null && insert.getId().equals(existingDataset.getId())) { + // This is the same dataset, no duplicate name issue for update operation + return; + } + + // Now we know there's another dataset with the same name Field[] fields = Dataset.class.getDeclaredFields(); for (Field field : fields) { - if (field.isAnnotationPresent(CheckDuplicate.class)) { + field.setAccessible(true); // Make private fields accessible + + if ("name".equals(field.getName()) && field.isAnnotationPresent(CheckDuplicate.class)) { + // If the field is 'name' and is marked with CheckDuplicate annotation CheckDuplicate annotation = field.getAnnotation(CheckDuplicate.class); - throw new Exception(field.getName()+ annotation.message()); + throw new Exception("重复的数据集名称: " + insert.getName() + ". " + annotation.message()); } } } } + } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetVersionServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetVersionServiceImpl.java index 4d7a81d5..d4109884 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetVersionServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetVersionServiceImpl.java @@ -181,7 +181,7 @@ public class DatasetVersionServiceImpl implements DatasetVersionService { } private void insertPrepare(DatasetVersion datasetVersion) throws Exception { - checkDeclaredVersion(datasetVersion); + //checkDeclaredVersion(datasetVersion); LoginUser loginUser = SecurityUtils.getLoginUser(); datasetVersion.setCreateBy(loginUser.getUsername()); datasetVersion.setUpdateBy(loginUser.getUsername()); diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/WorkflowDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/WorkflowDaoMapper.xml index fe4a1fac..5964c7d8 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/WorkflowDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/WorkflowDaoMapper.xml @@ -171,7 +171,6 @@ state = 1 - and name like "%"#{workflow.name}"%" From 5464b742dc54b62d041fc91bbd005b6f8907d065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A5=BF=E5=A4=A7=E9=94=90?= <1070211640@qq.com> Date: Tue, 19 Mar 2024 16:10:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=9B=86=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E6=96=87=E4=BB=B6=E5=8F=96=E6=B6=88=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/platform/service/impl/DatasetServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java index edfa83bd..8a072593 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/DatasetServiceImpl.java @@ -184,16 +184,16 @@ public class DatasetServiceImpl implements DatasetService { */ @Override - public ResponseEntity downloadDataset(Integer id) { + public ResponseEntity downloadDataset(Integer id) throws Exception { DatasetVersion datasetVersion = this.datasetVersionDao.queryById(id); if (datasetVersion == null) { - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null); + throw new Exception("未找到该版本下数据集"); } // 从数据库中获取存储路径(即MinIO中的对象名称) String objectName = datasetVersion.getUrl(); if(objectName == null || objectName.isEmpty() ){ - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); + throw new Exception("未找到该版本数据集文件"); } try { @@ -210,7 +210,7 @@ public class DatasetServiceImpl implements DatasetService { } catch (Exception e) { e.printStackTrace(); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null); + throw new Exception("下载数据集文件错误"); } }