diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageVersionController.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageVersionController.java index d9e3977f..f8ad69a4 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageVersionController.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/controller/image/ImageVersionController.java @@ -90,7 +90,7 @@ public class ImageVersionController extends BaseController { */ @DeleteMapping("{id}") public GenericsAjaxResult deleteById(@PathVariable("id") Integer id) throws Exception { - return genericsSuccess(this.imageVersionService.removeById(id)); + return this.imageVersionService.removeById(id); } } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageVersionService.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageVersionService.java index 737d5f6e..9fd8e3b4 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageVersionService.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/ImageVersionService.java @@ -1,5 +1,6 @@ package com.ruoyi.platform.service; +import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.platform.domain.ImageVersion; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -62,5 +63,5 @@ public interface ImageVersionService { List queryByImageId(Integer id); - String removeById(Integer id) throws Exception; + GenericsAjaxResult removeById(Integer id) throws Exception; } diff --git a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageVersionServiceImpl.java b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageVersionServiceImpl.java index 1582766d..aa513746 100644 --- a/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageVersionServiceImpl.java +++ b/ruoyi-modules/management-platform/src/main/java/com/ruoyi/platform/service/impl/ImageVersionServiceImpl.java @@ -1,8 +1,8 @@ package com.ruoyi.platform.service.impl; import com.alibaba.fastjson2.JSON; +import com.ruoyi.common.core.web.domain.GenericsAjaxResult; import com.ruoyi.common.security.utils.SecurityUtils; -import com.ruoyi.system.api.constant.Constant; import com.ruoyi.platform.domain.AssetWorkflow; import com.ruoyi.platform.domain.ImageVersion; import com.ruoyi.platform.domain.Ray; @@ -10,6 +10,7 @@ import com.ruoyi.platform.mapper.AssetWorkflowDao; import com.ruoyi.platform.mapper.ImageVersionDao; import com.ruoyi.platform.mapper.RayDao; import com.ruoyi.platform.service.ImageVersionService; +import com.ruoyi.system.api.constant.Constant; import com.ruoyi.system.api.model.LoginUser; import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Page; @@ -68,16 +69,23 @@ public class ImageVersionServiceImpl implements ImageVersionService { } @Override - public String removeById(Integer id) throws Exception { + public GenericsAjaxResult removeById(Integer id) throws Exception { ImageVersion imageVersion = this.imageVersionDao.queryById(id); + ImageVersion query = new ImageVersion(); + query.setImageId(imageVersion.getImageId()); + long count = this.imageVersionDao.count(query); + if (count == 1) { + return GenericsAjaxResult.error("当前镜像只有一个版本,不能删除该版本"); + } + if (imageVersion == null) { - return "该版本下模型文件信息不存在"; + return GenericsAjaxResult.error("该版本下模型文件信息不存在"); } List assetWorkflow = assetWorkflowDao.getAssetWorkflow(Long.valueOf(imageVersion.getImageId()), Constant.Asset_Type_Image, imageVersion.getTagName()); if (assetWorkflow != null && !assetWorkflow.isEmpty()) { String workflows = String.join(",", assetWorkflow.stream().map(AssetWorkflow::getWorkflowName).collect(Collectors.toSet())); - throw new Exception("该镜像版本被流水线:" + workflows + "使用,不能删除,请先删除流水线。"); + return GenericsAjaxResult.error("该镜像版本被流水线:" + workflows + "使用,不能删除,请先删除流水线。"); } HashMap map = new HashMap<>(); @@ -85,7 +93,7 @@ public class ImageVersionServiceImpl implements ImageVersionService { List rayList = rayDao.queryByImageId(JSON.toJSONString(map)); if (rayList != null && !rayList.isEmpty()) { String rays = String.join(",", rayList.stream().map(Ray::getName).collect(Collectors.toSet())); - throw new Exception("该镜像版本被超参数自动寻优:" + rays + "使用,不能删除,请先删除超参数自动寻优。"); + return GenericsAjaxResult.error("该镜像版本被超参数自动寻优:" + rays + "使用,不能删除,请先删除超参数自动寻优。"); } //判断权限,只有admin和创建者本身可以删除该数据集 @@ -93,11 +101,11 @@ public class ImageVersionServiceImpl implements ImageVersionService { String username = loginUser.getUsername(); String createdBy = imageVersion.getCreateBy(); if (!(StringUtils.equals(username, "admin") || StringUtils.equals(username, createdBy))) { - return "无权限删除该版本下模型信息"; + return GenericsAjaxResult.error("无权限删除该版本下模型信息"); } imageVersion.setState(Constant.State_invalid); - return this.imageVersionDao.update(imageVersion) > 0 ? "删除成功" : "删除失败"; + return this.imageVersionDao.update(imageVersion) > 0 ? GenericsAjaxResult.success("删除成功") : GenericsAjaxResult.error("删除失败"); } diff --git a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageVersionDaoMapper.xml b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageVersionDaoMapper.xml index 8f522649..861fdd51 100644 --- a/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageVersionDaoMapper.xml +++ b/ruoyi-modules/management-platform/src/main/resources/mapper/managementPlatform/ImageVersionDaoMapper.xml @@ -118,9 +118,6 @@ and update_time = #{imageVersion.updateTime} - - and state = #{imageVersion.state} -