| @@ -123,7 +123,7 @@ public class ModelsController extends BaseController { | |||||
| */ | */ | ||||
| @PostMapping | @PostMapping | ||||
| @ApiOperation("添加模型") | @ApiOperation("添加模型") | ||||
| public GenericsAjaxResult<Models> add(@RequestBody Models models) { | |||||
| public GenericsAjaxResult<Models> add(@RequestBody Models models) throws Exception { | |||||
| return genericsSuccess(this.modelsService.insert(models)); | return genericsSuccess(this.modelsService.insert(models)); | ||||
| } | } | ||||
| @@ -2,6 +2,7 @@ package com.ruoyi.platform.domain; | |||||
| import com.fasterxml.jackson.databind.PropertyNamingStrategy; | import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||||
| import com.ruoyi.platform.annotations.CheckDuplicate; | |||||
| import io.swagger.annotations.ApiModel; | import io.swagger.annotations.ApiModel; | ||||
| import io.swagger.annotations.ApiModelProperty; | import io.swagger.annotations.ApiModelProperty; | ||||
| @@ -22,6 +23,7 @@ public class Models implements Serializable { | |||||
| private Integer id; | private Integer id; | ||||
| @ApiModelProperty(value = "模型名称") | @ApiModelProperty(value = "模型名称") | ||||
| @CheckDuplicate | |||||
| private String name; | private String name; | ||||
| @ApiModelProperty(value = "模型描述") | @ApiModelProperty(value = "模型描述") | ||||
| @@ -84,7 +84,8 @@ public interface DatasetVersionDao { | |||||
| List<DatasetVersion> queryByDatasetId(Integer datasetId); | List<DatasetVersion> queryByDatasetId(Integer datasetId); | ||||
| DatasetVersion queryByDatasetVersion(@Param("datasetVersion") DatasetVersion datasetVersion); | |||||
| DatasetVersion | |||||
| queryByDatasetVersion(@Param("datasetVersion") DatasetVersion datasetVersion); | |||||
| List<DatasetVersion> queryAllByDatasetVersion(@Param("datasetId") Integer datasetId, @Param("version") String version); | List<DatasetVersion> queryAllByDatasetVersion(@Param("datasetId") Integer datasetId, @Param("version") String version); | ||||
| @@ -1,10 +1,12 @@ | |||||
| package com.ruoyi.platform.mapper; | package com.ruoyi.platform.mapper; | ||||
| import com.ruoyi.platform.domain.Dataset; | |||||
| import com.ruoyi.platform.domain.Models; | import com.ruoyi.platform.domain.Models; | ||||
| import org.apache.ibatis.annotations.Param; | import org.apache.ibatis.annotations.Param; | ||||
| import org.springframework.data.domain.Pageable; | import org.springframework.data.domain.Pageable; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| /** | /** | ||||
| * (Models)表数据库访问层 | * (Models)表数据库访问层 | ||||
| @@ -22,6 +24,8 @@ public interface ModelsDao { | |||||
| */ | */ | ||||
| Models queryById(Integer id); | Models queryById(Integer id); | ||||
| Models findByName(@Param("name") String name); | |||||
| /** | /** | ||||
| * 查询指定行数据 | * 查询指定行数据 | ||||
| * | * | ||||
| @@ -2,6 +2,7 @@ package com.ruoyi.platform.service; | |||||
| import com.ruoyi.platform.domain.Dataset; | |||||
| import com.ruoyi.platform.domain.Models; | import com.ruoyi.platform.domain.Models; | ||||
| import com.ruoyi.platform.domain.ModelsVersion; | import com.ruoyi.platform.domain.ModelsVersion; | ||||
| import com.ruoyi.platform.vo.ModelsVo; | import com.ruoyi.platform.vo.ModelsVo; | ||||
| @@ -45,7 +46,7 @@ public interface ModelsService { | |||||
| * @param models 实例对象 | * @param models 实例对象 | ||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| Models insert(Models models); | |||||
| Models insert(Models models) throws Exception; | |||||
| /** | /** | ||||
| * 修改数据 | * 修改数据 | ||||
| @@ -81,5 +82,7 @@ public interface ModelsService { | |||||
| String readFileContent(Integer modelsId, String version) throws Exception; | String readFileContent(Integer modelsId, String version) throws Exception; | ||||
| public void checkDeclaredName(Models insert) throws Exception; | |||||
| List<Map<String, String>> exportModels(String path, String uuid) throws Exception; | List<Map<String, String>> exportModels(String path, String uuid) throws Exception; | ||||
| } | } | ||||
| @@ -221,7 +221,7 @@ public class ImageServiceImpl implements ImageService { | |||||
| if (imageVersionInsert == null) { | if (imageVersionInsert == null) { | ||||
| throw new Exception("新增镜像版本失败"); | throw new Exception("新增镜像版本失败"); | ||||
| } | } | ||||
| // 使用CompletableFuture异步执行不同的镜像构建逻辑 | |||||
| // 使用CompletableFuture异步执行不同的镜像构建逻辑,在构建镜像的同时,更新数据库中的镜像版本状态 | |||||
| CompletableFuture.supplyAsync(() -> { | CompletableFuture.supplyAsync(() -> { | ||||
| Map<String, String> resultMap = new HashMap<>(); | Map<String, String> resultMap = new HashMap<>(); | ||||
| try { | try { | ||||
| @@ -281,6 +281,7 @@ public class ImageServiceImpl implements ImageService { | |||||
| String pushCmd = "docker push " + imageUrl; | String pushCmd = "docker push " + imageUrl; | ||||
| String sizeCmd = "docker inspect --format='{{.Size}}' " + imageUrl; | String sizeCmd = "docker inspect --format='{{.Size}}' " + imageUrl; | ||||
| String s = k8sClientUtil.executeCommand(pod, tagCmd); | String s = k8sClientUtil.executeCommand(pod, tagCmd); | ||||
| if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, pushCmd))){ | if (StringUtils.isNotEmpty(k8sClientUtil.executeCommand(pod, pushCmd))){ | ||||
| resultMap.put("url", imageUrl); | resultMap.put("url", imageUrl); | ||||
| //得到镜像文件大小 | //得到镜像文件大小 | ||||
| @@ -1,7 +1,9 @@ | |||||
| package com.ruoyi.platform.service.impl; | package com.ruoyi.platform.service.impl; | ||||
| import com.ruoyi.common.security.utils.SecurityUtils; | import com.ruoyi.common.security.utils.SecurityUtils; | ||||
| import com.ruoyi.platform.annotations.CheckDuplicate; | |||||
| import com.ruoyi.platform.domain.AssetIcon; | import com.ruoyi.platform.domain.AssetIcon; | ||||
| import com.ruoyi.platform.domain.Dataset; | |||||
| import com.ruoyi.platform.domain.Models; | import com.ruoyi.platform.domain.Models; | ||||
| import com.ruoyi.platform.domain.ModelsVersion; | import com.ruoyi.platform.domain.ModelsVersion; | ||||
| import com.ruoyi.platform.mapper.ModelsDao; | import com.ruoyi.platform.mapper.ModelsDao; | ||||
| @@ -34,6 +36,7 @@ import javax.annotation.Resource; | |||||
| import java.io.ByteArrayInputStream; | import java.io.ByteArrayInputStream; | ||||
| import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
| import java.io.InputStream; | import java.io.InputStream; | ||||
| import java.lang.reflect.Field; | |||||
| import java.net.URLEncoder; | import java.net.URLEncoder; | ||||
| import java.util.*; | import java.util.*; | ||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||
| @@ -116,8 +119,9 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| * @return 实例对象 | * @return 实例对象 | ||||
| */ | */ | ||||
| @Override | @Override | ||||
| public Models insert(Models models) { | |||||
| public Models insert(Models models) throws Exception { | |||||
| LoginUser loginUser = SecurityUtils.getLoginUser(); | LoginUser loginUser = SecurityUtils.getLoginUser(); | ||||
| checkDeclaredName(models); | |||||
| models.setCreateBy(loginUser.getUsername()); | models.setCreateBy(loginUser.getUsername()); | ||||
| models.setUpdateBy(loginUser.getUsername()); | models.setUpdateBy(loginUser.getUsername()); | ||||
| models.setUpdateTime(new Date()); | models.setUpdateTime(new Date()); | ||||
| @@ -173,8 +177,9 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){ | if (!(StringUtils.equals(username,"admin") || StringUtils.equals(username,createdBy))){ | ||||
| throw new Exception("无权限删除该模型"); | throw new Exception("无权限删除该模型"); | ||||
| } | } | ||||
| if (modelsVersionService.queryByModelsId(id).size()>0){ | |||||
| throw new Exception("请先删除该镜像下的版本文件"); | |||||
| //判断是否有版本文件 | |||||
| if (!modelsVersionService.queryByModelsId(id).isEmpty()){ | |||||
| throw new Exception("请先删除该模型下的版本文件"); | |||||
| } | } | ||||
| models.setState(0); | models.setState(0); | ||||
| return this.modelsDao.update(models)>0?"删除成功":"删除失败"; | return this.modelsDao.update(models)>0?"删除成功":"删除失败"; | ||||
| @@ -427,6 +432,31 @@ public class ModelsServiceImpl implements ModelsService { | |||||
| } | } | ||||
| @Override | |||||
| public void checkDeclaredName(Models insert) throws Exception { | |||||
| Models existingModel = modelsDao.findByName(insert.getName()); | |||||
| if (existingModel != null) { | |||||
| // Check if the found models 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(existingModel.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 = Models.class.getDeclaredFields(); | |||||
| for (Field field : fields) { | |||||
| 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("重复的模型名称: " + insert.getName() + ". " + annotation.message()); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @Override | @Override | ||||
| public List<Map<String, String>> exportModels(String path, String uuid) throws Exception { | public List<Map<String, String>> exportModels(String path, String uuid) throws Exception { | ||||
| List<Map<String, String>> results = new ArrayList<>(); | List<Map<String, String>> results = new ArrayList<>(); | ||||
| @@ -31,6 +31,7 @@ | |||||
| from dataset | from dataset | ||||
| where name = #{name} and state = 1 limit 1 | where name = #{name} and state = 1 limit 1 | ||||
| </select> | </select> | ||||
| <!--查询指定行数据--> | <!--查询指定行数据--> | ||||
| <select id="queryAllByLimit" resultMap="DatasetMap"> | <select id="queryAllByLimit" resultMap="DatasetMap"> | ||||
| select | select | ||||
| @@ -24,6 +24,14 @@ | |||||
| where id = #{id} and state = 1 | where id = #{id} and state = 1 | ||||
| </select> | </select> | ||||
| <!--查询单个--> | |||||
| <select id="findByName" resultMap="ModelsMap"> | |||||
| select | |||||
| id, name, description,available_range, model_type,model_tag, create_by, create_time, update_by, update_time, state | |||||
| from models | |||||
| where name = #{name} and state = 1 limit 1 | |||||
| </select> | |||||
| <!--查询指定行数据--> | <!--查询指定行数据--> | ||||
| <select id="queryAllByLimit" resultMap="ModelsMap"> | <select id="queryAllByLimit" resultMap="ModelsMap"> | ||||
| select | select | ||||